In: Computer Science
In C++
Complete the following code without the use of auto.
code:
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
void getAverages(vector<float>& v){
cout<<"Enter student marks average"<<endl;
while(true){ // take input until - value
float a;
cin>>a;
if(a<0)
break;
v.push_back(a); // pus data to vector
}
}
void storeAverages(const vector<float>& v, string
filename){
ofstream fout;
string line;
fout.open(filename.c_str());
for(int i=0; i<v.size(); i++)
fout << v[i] << endl; // writing data to file in each
new line
fout.close();
cout<<"file writen"<<endl;
}
void curveAverages(vector<float>& v, float number){
for(int i=0; i<v.size(); i++){
v.at(i)=v[i] + number; // user at and assing the value
}
}
float calculateClassAverage(const vector<float>&
v){
float sum = 0;
for(int i=0; i<v.size(); i++){
sum += v[i]; // calculating average
}
return sum/v.size();
}
int main(){
vector<float> avg;
getAverages(avg); // calling methore
cout<<endl<<"Enter average data in vector is: ";
for(int i=0; i<avg.size(); i++){
cout<<avg[i]<<" ";
}
cout<<endl<<"Enter filename: ";
string filename;
cin>>filename;
storeAverages(avg,filename);// calling methore
cout<<endl<<"Enter average constant curve: ";
int curve;
cin>>curve;
curveAverages(avg,curve);// calling methore
cout<<endl<<"vector after curve: ";
for(int i=0; i<avg.size(); i++){
cout<<avg[i]<<" ";
}
float avge = calculateClassAverage(avg);
cout<<endl<<"Average after cal: ";
cout<<avge<<endl;
}
for any help ask in the
comment !