### Subtracting a minimum score out of an average

I have written a c++ program to calculate student grades. I have confirmed my code is correct for a main.cpp, a student.h file , and a student.cpp file but I am missing one element from the main.cpp file: I need to add something that removes the lowest homework score. First, find the minimum homework assignment score (min). Then you add all the homework assignment scores (sum). After you get the sum, you can calculate the average homework scores in the formula
(sum - min)/(n-1) n is the number of homework assignments. And i have to replace lowest exam score by final exam if final exam is higher. How would I do this? The TA has approved my code below so no need to make any changes to it besides these score dropping elements

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139`` ``````#include "Student.h" #include #include #include #include #include #include #include #include #include using namespace std; vector process_line(string line){ vector entries; string built_int = ""; for(int i = 0; i < line.size(); i++){ if (line[i] == ' '){ entries.push_back(stoi(built_int)); built_int = ""; } else { built_int = built_int + line[i]; } } entries.push_back(stoi(built_int)); return entries; } int main(int argc, char *argv[]){ if (argc == 1){ cout << "You did not enter any file names!" << endl; return 0; } ifstream input_file; input_file.clear(); input_file.open("student_data.dat"); if (! input_file.is_open() ){ cout << "The file could not be opened!" << endl; return 0; } int linenum=1; vector names; vector> hw; vector> e; vector f; string line; while(getline(input_file, line)){ if (line=="") linenum=0; switch (linenum){ case 0: linenum++; break; case 1: names.push_back(line); linenum++; break; case 2: hw.push_back(process_line(line)); linenum++; break; case 3: e.push_back(process_line(line)); linenum++; break; case 4: f.push_back(stoi(line)); linenum++; break; } } input_file.close(); for (int i=0; i hw_tot; vector e_tot; int row_sum; for (int i=0; i f_names; vector l_names; for (int i=0;i finalgrades; for (int i=0;i order; for (int i=0; i < l_names.size(); i++){ order.push_back(i); } auto comparator = [&l_names](int a, int b){ return (l_names[a] < l_names[b]); }; sort(order.begin(), order.end(), comparator); int k; for (int i=0;i
- you’ve created a class “Student”.
- You read Student’s data from a file into std::vectors which are not members of Student.
- You need to perform some basic calculation on those data.

For what I can see, there could be a misunderstanding: all the data you’re dealing with were probably supposed to be managed from inside your class Student - otherwise I can’t see the point of writing that class.
Let’s assume the data you need to manage are (for each Student):
a) first and last name;
b) list of homework marks;
c) list of exam score;
d) final exam score.
It seams you’re putting those data into:
a) vector<string> names; --> a std::vector for all Students names
b) vector<vector<int>> hw; --> a std::vector of std::vectors for all Students lists of homework marks
c) vector<vector<int>> e; --> a std::vector of std::vectors for all Students lists of exam scores
d) vector<int> f; --> a std::vector for all Students final exam scores
While it is possible the assignment asks you to use your class more or less this way:
 ``123456789101112`` ``````#ifndef SHIMSHIM96_STUDENT_H #define SHIMSHIM96_STUDENT_H class Student { std::string fname, lname; std::vector hws; std::vector exams; int fscore; double average; }; #endif // SHIMSHIM96_STUDENT_H ``````

Maybe I’m wrong, of course, but I’d read the assignment again to be sure.

 I need to add something that removes the lowest homework score
Once you’ve sorted your std::vector, the lowest homework mark is the first one, i.e. the one at position 0.

I think your "student_data.dat" file is somewhat like:

Ann Anderson
13 666 679
51 34 47
18

Barbara Brown
14 667 681
52 74 16
44

Carl Carter
56 28 45
63 11 26
85

Let’s reduce it to:

Ann
13 666 679

Barbara
14 667 681

Carl
56 28 45

to deal only with homework marks.
An example of code similar to yours could be:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263`` ``````#include #include #include #include #include #include #include std::vector process_line(const std::string& line); double getAverage(std::vector& hws); int getRowSum(const std::vector& hws); int main() { std::ifstream input_file("student_data.dat"); if (! input_file) { std::cout << "The file could not be opened!\n"; return 0; } std::vector names; std::vector> hw; int linenum { 1 }; for(std::string line; std::getline(input_file, line); ++linenum) { if(line.empty()) { linenum = 0; } switch (linenum) { case 0: break; case 1: names.push_back(line); break; case 2: hw.push_back(process_line(line)); break; } } input_file.close(); std::vector averages(names.size()); for(size_t i{}; i process_line(const std::string& line) { std::istringstream iss(line); std::vector entries; for(int i{}; iss >> i; /**/) { entries.push_back(i); } return entries; } double getAverage(std::vector& hws) { std::sort(hws.begin(), hws.end()); return static_cast(getRowSum(hws) - hws.at(0)) / (hws.size() - 1); } int getRowSum(const std::vector& hws) { return std::accumulate(hws.begin(), hws.end(), 0); }``````

Output:
 ```Ann average is 672.5 Barbara average is 674 Carl average is 50.5```