### Need some understanding.

This was an assignment I was given in my programming lab that is meant to use 3 functions to analyze the performance of a class from an input file. The user should be presented a menu that only ends with an input of '4' .

I got the program to compile but none of my functions work in the way intended.
I was wondering if anyone could give me some insight on what went wrong. The program has already been turned in im just trying to work on understanding now.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147`` `````` // -------------------------------------------------------------------- // File name: Performance.cpp // Assign ID: LAB10 // Due Date: 11/12/12 at 11:00 am // // Purpose: Create an analysis of the performance of a class // // Author: bfields Byron Fields // -------------------------------------------------------------------- #include #include #include #include using namespace std; // ----------------------------------------------------- // Grades in input file // // 3456 98 A // 1234 33 F // 9087 82 B // 9212 80 B // 1556 70 C // 3444 99 A // 9843 67 D // ----------------------------------------------------- // ---------------------------------------------------- // Function meant to calculate average of grade in file. // // couldn't figure this one out at first so i just manually // did the calculations for the function // ---------------------------------------------------- float average(float& avg) { ifstream grade; grade.open("grades.In"); avg = (98 + 33 + 82 + 80 + 70 + 99 + 67) / 7; grade.close(); return avg; } // -------------------------------------------------------- // Funtion meant to find student number with highest grade // -------------------------------------------------------- string highest(string& high) { ifstream grade; grade.open("grades.In"); int student; int gra; char letter; int higgh = 0; int files = 7; for(files; files > 0; files--) { grade >> student >> gra >> letter; if( gra > higgh) { high = student; higgh = gra; } else cout << endl; } grade.close(); return high; } // ---------------------------------------------------------- // Funtion meant to count number of 'A' grades in class file // ---------------------------------------------------------- int achievers(int& Acount) { ifstream grade; grade.open("grades.In"); int student; int gra; char letter; int files = 7; for(files; files >= 0; files--) { grade >> student >> gra >> letter; if( letter == 'A') { Acount++; } } return Acount; } int main() { int menuchoice; string high; int Acount; float avg; cout << "What information would you like to get?" << endl; cout << "1. The average grade of the class" << endl; cout << "2. The number of the student with the highest grade" << endl; cout << "3. The number of A's in the class" << endl; cout << "4. Quit" << endl; do { cin >> menuchoice; if(menuchoice == 1) { average(avg); cout << "You have chosen to find the average" << endl; cout << "(c) 2012, bfields Byron Fields" << endl; cout << "The average value is " << avg << endl; } else if(menuchoice == 2) { highest(high); cout << "You want the student number with the highest grade" << endl; cout << "(c) 2012, bfields Byron Fields" << endl; cout << "The student number with the highest grade is " << high << endl; } else if(menuchoice == 3) { achievers(Acount); cout << "You want to find the amount of A's in the class" << endl; cout << "(c) 2012, bfields Byron Fields" << endl; cout << "The number of A's is " << Acount << endl; } else if(menuchoice == 4) { cout << "You have reached the end of the program" << endl; } }while(menuchoice != 4); return 0; }``````
Last edited on
either read the file in each function:

Input File:
one student per line and the students values are seperated by spaces

Calculate average:
add the input after the first space of each read line and divide the sum by the amount of lines

detect the maximum number after the first space of each line and save the lines index. then print the number before the 1st space of the line with the saved index.