Complete/Modify the code given in quiz3.cpp to calculate the avg and the std deviation of the...

90.2K

Verified Solution

Question

Programming

Complete/Modify the code given in quiz3.cpp to calculate the avgand the std deviation of the array a and write the output once tomyquiz3outf.txt, and another time to a file to myquiz3outc.txt.(You must write one function for the mean(avg) and one function forthe std.

side note: ***for the string ifilename, the folder name that thefils are under is \"bte320\" and the \"numbers.txt\" that it isreferencing is pasted below***

CODE:

#include
#include
#include
#include //new g++ is stricter - it rquires it forexit

using namespace std;


int max(int a[],int dsize){
  
if (dsize>0){
int max=a[0];
for(int i=0;iif(a[i]>max){
max = a[i];
}
}
return max;
}
return -9999999;
}
int min(int a[],int dsize){
  
if (dsize>0){
int min=a[0];
for(int i=0;iif(a[i]min = a[i];
}
}
return min;
}
return -9999999;
}

void printArray(int array[],int dsize){
for(int i=0;icout << array[i];
if(icout << \" \";
}
cout << endl;
}
void fillArray(int array[],int &dsize, ifstream&fin){
  
int i=0;
while(!fin.eof()){
fin >> array[i];
i++;
}
dsize =i;
  
}

int main(){
ifstream fin;
ofstream fout;
stringifilename=\"/home/ec2-user/environment/bte320/numbers.txt\";
  
int const asize=100;
int a[asize];
int dsize=0;
  
fin.open(ifilename.c_str()); //make sure you use the c_str the newg++ uses it
if(!fin){ cout<< \"Error opening inputfile\"<fillArray(a,dsize,fin);
printArray(a,dsize);
cout <<\"Min Value:\" << min(a,dsize) <cout <<\"Max Value:\" << max(a,dsize) <  
return 0;
}

ARRAY FILE (numbers.txt):

559870332844778756312278

Answer & Explanation Solved by verified expert
4.1 Ratings (474 Votes)
Look at my code and in case of indentation issues check    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students