int main(int argc, char * argv[]) { //checks to make sure that there are 2 arguments - one for input and output inputCheck(argv); //Get the input file name... char *inputFileName = *(argv + 1); char *outputFileName = *(argv + 2); //Find out how many students are on the input file... int numberOfStudents = getRecordCount(inputFileName); //Create the number of students depending on the record count... Student listOfStudents[numberOfStudents]; createStudents(listOfStudents, numberOfStudents); //Read the data of the input file... FILE *myFile = openFile(inputFileName); //Fill out all the student's info... fillStudentRecord(myFile, listOfStudents, numberOfStudents); //sortStudents using the array of student struct sortStudents(listOfStudents, numberOfStudents); //Calculate each student's GPA and recorded in the structure... getGPA(listOfStudents, numberOfStudents); //Calculate each student's Letter Grade and record in the structure... getGrade(listOfStudents, numberOfStudents); //Create ClassGrade structure pointer... ClassGrade *classGrade; classGrade = (ClassGrade *)malloc((sizeof classGrade) * 20); //Call functions to calculate the scores... getScoreAverage(listOfStudents, classGrade, numberOfStudents); getMinScore(listOfStudents, classGrade, numberOfStudents); getMaxScore(listOfStudents, classGrade, numberOfStudents); //Generate and output file with the student grade information generateOutputFile(outputFileName, inputFileName, listOfStudents, numberOfStudents); //Print out student's info... printAllStudents(listOfStudents, classGrade, numberOfStudents, inputFileName, outputFileName); return 0; }
/* * toString() * * The student object will be put into string representation. Student info will be * ordered ID, name, address, phone number, and GPA. Each piece of information will * be on its own line. GPA will not have a newline following it and the precision * of the GPA will be rounded to two decimal places. For example, * * 123456789 * Ben Thompson * 17 Russell St, Provo, UT 84606 * 555-555-5555 * 3.12 * * Returns a string representation of the student object There is no trailing new line. */ string Student::toString() { stringstream tt; tt << ID << endl << name << endl << address << endl << phone << endl << getGPA(); return tt.str(); }
int main( int argc, char *argv[] ) { struct node* root = NULL; root = createTree(); // points to root node of tree int execute = YES; // while loop control int numInserts = 0; if ( argc != 2 ) { println("No filename provided." ); } else { int numInsertsFromFile = loadFile( root, argv[1] ); numInserts += numInsertsFromFile; } while ( execute ) { char cmd[MAX_COMMAND_SIZE]; int studentId, studentId_a, studentId_b, top; char courseId[7], courseName[8], grade[3]; char filename[MAX_COMMAND_SIZE]; printf("Please enter your action: "); scanf("%s", cmd); if ( strEqual(cmd, "exit") ) { execute = NO; } else if ( strEqual(cmd, "printtree") ) { printTree( root ); } else if ( strEqual(cmd, "print") ) { printNode( root ); } else if ( strEqual(cmd, "find") ) { scanf("%d", &studentId); struct nodeIndex* nodeIndex = search( root, studentId ); if ( nodeIndex->wasFound ) { println("StudentId %d was found in tree.", studentId); } else { println("StudentId %d was not found in tree.", studentId); } } else if ( strEqual(cmd, "ins") ) { // studentId, courseId, courseName, grade scanf("%d %s %s %s", &studentId, courseId, courseName, grade); root = insertData( root, studentId, courseId, courseName, grade); // insert new data if ( studentId > 0 ) numInserts++; } else if ( strEqual(cmd, "load") ) { // filename scanf("%s", filename); int numInsertsFromFile = loadFile( root, filename ); numInserts += numInsertsFromFile; } else if ( strEqual(cmd, "range") ) { // studentId_a, studentId_b scanf("%d %d", &studentId_a, &studentId_b); getInfoInRange( root, studentId_a, studentId_b ); } else if ( strEqual(cmd, "gpa") ) { // gpa <studentId> scanf("%d", &studentId); getGPA( root, studentId ); } else if ( strEqual(cmd, "gpa_range") ) { // gpa_range <studentId_a> <studentId_b> scanf("%d %d", &studentId_a, &studentId_b); getGPAinRange( root, studentId_a, studentId_b ); } else if ( strEqual(cmd, "top") ) { scanf("%d", &top); getTopCourses( root, top, numInserts ); } else if ( strEqual(cmd, "verify") ) { // check all nodes to ensure properties of 2-4 tree println("STUB: verify."); } else if ( strEqual(cmd, "leaves") ) { // check all nodes to ensure properties of 2-4 tree traverseLeaves( root ); } else { println("ERROR\nCommand '%s' not recognized.", cmd); } } // end while freeTree( root ); return 0; }