#include<iostream>#include<fstream>using namespace std;/********************************************************* @Author: XXXXXXXXXXXX ** @version: 2 ** @Date: 02/10/2007 ** *Important Note: Gradebook file must be in correct ** *format to work for this program** **********************************************************/ifstream inFile; //Used for reading in Previous Gradebook files.ofstream outFile;//Used to create a Text file to store Gradebook information.int hSize = 0; // Number of Homework Gradesint pSize = 0; // Number of Program Gradesint eSize = 0; // Number of Exam Grades, must be less than or equal to two.int fSize = 0; // Tells whether the Final grade has been given or not.int *hArray; // int *pArray; // Arrays for storing grades while in program.int *eArray; //int Final; // The Final Grade.//+++++++++++++++++++Global Variables++++++++++++++++++++++++++++++void readInGrades(){//Method to read grades from the Gradebook text file into the arrays. inFile>> hSize; inFile>> pSize; inFile>> eSize; inFile>> fSize; hArray = new int[hSize]; pArray = new int[pSize]; eArray = new int[eSize]; for( int x = 0; x < hSize; x++) { inFile>>hArray[x]; } for( int x = 0; x < pSize; x++) { inFile>>pArray[x]; } for( int x = 0; x < eSize; x++) { inFile>>eArray[x]; }}//FIX THISvoid writeOutGrades(){//Method used to save Gradebook information into a text file. outFile<<hSize<<endl; outFile<<pSize<<endl; outFile<<eSize<<endl; outFile<<fSize<<endl; for(int x = 0; x < hSize; x++){ outFile<<hArray[x]<<endl; } for(int x = 0; x < pSize; x++){ outFile<<pArray[x]<<endl; } for(int x = 0; x < eSize; x++){ outFile<<eArray[x]<<endl; } if( fSize = 1){ outFile<<Final<<endl;}}double Average(int array[], int array_size){//Method that will find the Average of any given Array. int sum = 0; for(int x = 0; x < array_size; x++) { sum += array[x]; } double average = sum/array_size;return average;}//FIX THISvoid inputGrade( int *array, int newElement, int array_length){//Adds a new Element to the array, extending the index by one. int temp[ array_length + 1]; for(int x = 0; x< array_length; x++) { temp[x] = array[x]; } temp[array_length] = newElement; array = new int[ array_length +1]; for(int x = 0; x < array_length; x++) { array[x]= temp[x]; }}void displayChoices(){//Method to Display all Choice options. cout<<"1. Enter a homework/quiz grade."<<endl; cout<<"2. Enter a program grade."<<endl; cout<<"3. Enter an exam grade."<<endl; cout<<"4. Enter the final exam grade."<<endl; cout<<"5. Show the grade report."<<endl; cout<<"6. Exit."<<endl<<endl;}void printGradeReport(){//Method Helper for Option 5.cout<<" Homeworks\\Quizes (10\%):" /*<< Average(hArray, hSize)*/ <<endl;cout<<" Programs (35\%):" /*<< Average(pArray, pSize)*/ <<endl;cout<<" Exams (30\%):" /*<< Average(eArray, eSize)*/ <<endl;cout<<" Final (25\%):" /*<< Final*/ <<endl<<endl;cout<<" Overall:" <<endl;}int selection(){//Method which repeats while you choose to not exit the program.displayChoices();char choice;cin>> choice; //Reads in User's choice. switch(choice) { int grade; case '1': cout<<"Homework grade: "<<endl; cin>>grade; inputGrade(hArray, grade, hSize); hSize++; return 1; break; case '2': cout<<"Program grade: "<<endl; cin>>grade; inputGrade(pArray, grade, pSize); pSize++; return 2; break; case '3': if(eSize < 2) { cout<<"Exam Grade: "<<endl; cin>>grade; inputGrade(eArray,grade,eSize); eSize++; } else { cout<<"All Exam grades have been entered."<<endl; } return 3; break; case '4': if(fSize < 1) { cout<<"Final Grade: "<<endl; cin>> Final; } else { cout<<"Final has already been entered."<<endl; } return 4; break; case '5': printGradeReport(); return 5; break; case '6': cout<<"Exiting the program..."<<endl; writeOutGrades(); return 6; break; default: cout<<"Invalid Input. Please try again."<<endl; return 0; }}///////////////////////////////Functions/////////////////////////////////int main(int argc, char *argv[]){//Main Method which Drives program. if (argc < 2) {// If number of arguments is less than two, prompt with correct usage. cout<< "Usage: "<< argv[0]<< " <gradebook file>"<<endl; return 0; } cout<< "Opening: "<< argv[1] <<endl; inFile.open( argv[1] ); if(!inFile) {// If gradebook file does not exist, create it with the given argument definition. cout<< argv[1] << " does not exist, creating new file to write gradebook to."<<endl; outFile.open( argv[1] ); cout<< argv[1] << " created."<<endl; } if(inFile){ readInGrades(); } inFile.close(); outFile.open(argv[1]); while(selection() != 6); outFile.close(); return 0;}