PLEASE WRITE IT IN C++ Thank you
Assignment:
Write a program that reads a text file containing a set of test scores. Each line in the file contains ten scores of a specific student. For example, the first line has the scores for the first student, the second line has the scores for the second student, and so forth. Average the scores of each student and save them in a vector of final scores. So, if there are 10 students, the vector should have 10 final scores. Sort the final scores to calculate the class median. Print the final scores sorted from least to greatest, the class average and the class median.
Detailed set of requirements:
Lab Guidelines:2. Write a comment above each function header explaining what the function does and the purpose of each variable. Example:
/******************************************************************
This function adds the amount passed as parameter to the balance
in the account and returns whether the operation was successful.
*******************************************************************/
bool deposit (double amount)
{
...
}
3. Comment variables that are not self explanatories.
For example, a variable named interestRate doesn't need an explanation if you are using it to store interest rate, but if you have a variable named x, you need to explain what you use it for.
4. General guidelines:
Comments are supposed to add meaning to your code. The following are examples of comments that do NOT have any purpose in a program and must be avoided:
// variable declarations
int x; // integer variable
voidprintReport(); // function prototype
input.txt -
70 79 72 78 71 73 68 74 75 70
78 89 96 91 94 95 92 88 95 92
83 81 93 85 84 79 78 90 88 79
93 100 86 99 98 97 96 95 94 92
72 60 82 64 65 63 62 61 67 64
80 92 100 81 82 83 84 85 86 87
92 91 74 76 77 78 81 83 80 88
67 60 65 68 72 74 76 77 78 73
93 99 91 93 94 96 95 97 98 74
82 81 89 75 77 79 81 83 85 78
sample output:
Final scores: 66 71 73 81 82 84 86 91 93 95
This is the avrg grade in the class: 82.2
This is the median grade in the class: 83
#include <fstream>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
// FUNCTION TO SORT ELEMENTS OF VECTOR
bool tf(int i, int j){
return (i<j);
}
//FUNCTION TO COMPUTE AVERAGE OF VECTOR
double average_fx(std::vector<double> fscores) {
double summ = 0, avg;
for(int s=0;s<fscores.size();s++){
summ = summ+fscores[s];
}
avg = summ/fscores.size();
return avg;
}
//FUNCTION TO COMPUTE MEDIAN OF VECTOR
double median_fx(std::vector<double> fscores) {
double mdn = 0;
int L=fscores.size();
if((L%2) ==0){
mdn = 0.5*(fscores[L/2 - 1]+fscores[L/2]);
}else{
mdn = fscores[L/2];
}
return mdn;
}
//FUNCTION TO PRINT RESULTS
void printResults(std::vector<double> fscores,double avgg,
double mdnn){
std::cout << " Sorted Vector: " << std::endl;
for (int g=0;g<fscores.size();g++){
std::cout << fscores[g] << std::endl;
}
// TO USE RAGE BASED for LOOP
/*
for (int g: fscores){
std::cout << fscores[g] << std::endl;
}
*/
std::cout << " Average: " <<
avgg<<std::endl;
std::cout << " Median: " <<
mdnn<<std::endl;
}
int main() {
//PROMPTING USER TO ENTER FILE NAME AND TRYING OPENNING FILE FROM
DEFAULT PATH
std::ifstream in_file;
std::string filename,custom_paths;
std::cout<<"Enter FileName.txt ";
std::cin>>filename;
in_file.open(filename.c_str());
//HANDLING FAILURE TO OPEN FILE
while(in_file.fail())
{
in_file.clear();
std::cout<<"no such file exists in default path, please try
to in-put correct name: ";
std::cin>>filename;
in_file.open(filename.c_str());
if(in_file.fail()){
std::cout<<"no such file exists, enter custom paths including
the filename.txt. Use double back-slashes: ";
std::cin>>custom_paths;
in_file.open(custom_paths.c_str());
}
}
std::vector<double> scores;
std::vector<double> final_scores;
double num = 0.0;
while (in_file >> num) {
scores.push_back(num);
}
int m=0;
int n=10;
int nn = n-1;
//COMPUTING AVERAGE OF EACH STUDENT
std::cout << " Vector (Final Scores): " <<
std::endl;
for(int j = 0; j < scores.size()-nn; j=j+nn){
double sm = 0;
for (int i = j+m; i < j+n+m; ++i) {
sm = sm+scores[i];
}
final_scores.push_back(sm/n);
std::cout << final_scores[m] << std::endl;
m=m+1;
}
//SORTING VECTOR
std::sort(final_scores.begin(),final_scores.end(),tf);
//CALLING FUNCTIONS, COMPUTING AND DISPLAYING RESULTS
double average = average_fx(final_scores);
double median = median_fx(final_scores);
printResults(final_scores,average, median);
//CLOSING FILE
in_file.close();
return 0;
}

please give thumbs up
PLEASE WRITE IT IN C++ Thank you Assignment: Write a program that reads a text file...