//p6.cxx //************************************************************************************ //AUTHOR:Aaron Sopfe // //COUSE TITLE: Programming 1 // //COUSE NUMBER: CS116 // //PROF NAME: Moe Bidgoli // //ASSIGMENT NUMBER #6 // //DUE DATE OCT-17-2011 // //POSSIBLE POINTS ? Points // //PURPOSE // // This program uses an input file to collect name, id, and three exam scores // (exam1, exam2, exam3) in to an output file, it checks to make sure the student // ID, and exams are in set define range and will display an error if the value(s) // are not in the range. The program also averages the exam grades and does another // check to make sure the average does not supass 100 or under 0. The final part of // the program will display pass or fail if the average is above or below 70. // This program uses a loop so more then one record can be processed in a single // running of the program. // //********************************************************************************** #include #include #include using namespace std; const float MAXE = 100.00; //max exam score const float MINE = 0.00; //min exam score const int MAXID = 9999; //max studId const int MINID = 1111; //min studId const float EXMIN = 70.00; //min passing exam float sumexam; //sums of exams float perPass; // percent passed with avgerage of 70 or more float perFail; // percent failed wtih averge less then 70 int main() { ofstream outFile; ifstream inFile; outFile.open("out.data"); inFile.open("in.data"); outFile.setf(ios::fixed); outFile.precision(2); string studName, pass, fail, inv, work; // inv = invalid work = either pass, fail, or inv int studId; //student id float exam1, exam2, exam3, avg, mavg; //mavg == class mean avg, avg = average int invRd = 0; //invalid record int validRd = 0; //Valid record int noPass = 0; //number of passing int noFail = 0; //Number of failing //float perpass; //percent pass //float perfail; //percent fail pass = "PASSED"; fail = "FAILED"; inv = "~ INVALID DATA ~"; outFile << "~~ < Student Exam Report > ~~" << endl; outFile << "Student ID:" << setw(11) << "Name" << setw(11) << "Exam 1" << setw(11) << "Exam 2" << setw(11) << "Exam 3" << setw(11) << "Average" << setw(20) << "Passed/Failed" << endl; outFile << "-----------" << setw(11) << "----" << setw(11) << "------" << setw(11) << "------" << setw(11) << "------" << setw(11) << "-------" << setw(20) << "-------------" << endl; inFile >> studName >> studId >> exam1 >> exam2 >> exam3; while(inFile) { avg = ( exam1 + exam2 + exam3 )/3; if( avg >= MINE && avg <= MAXE && exam1 >= MINE && exam1 <= MAXE && exam2 >= MINE && exam2 <= MAXE && exam3 >= MINE && exam3 <= MAXE && studId >= MINID && studId <= MAXID ) //then { sumexam = sumexam + avg; validRd = validRd + 1; outFile << studId << setw(11) << studName << setw(11) << exam1 << setw(11) << exam2 << setw(11) << exam3 << setw(11); if( avg >= EXMIN && avg <= MAXE) //then { noPass = noPass + 1; outFile << avg << setw(20) <> studName >> studId >> exam1 >> exam2 >> exam3; } if (validRd != 0) //then { perPass = (noPass / validRd) * 100; perFail = (noFail / validRd) * 100; mavg = (sumexam / validRd); outFile << endl <<"Mean AVG of exams = " << mavg << endl << endl; outFile << "Invalid data: " << invRd << endl; outFile << "Valid data: " << validRd << endl << endl; outFile << "% Passed " << perPass << endl; outFile << "% Failed " << perFail << endl; outFile << "*< end >*" << endl; } else { outFile << "Error: Can not divide by zero" << endl; } inFile.close(); outFile.close(); return 0; } //in.data Lewis,Rose 1111 75.00 80 70 Weber,Mark 7821 70 69 69 Runer,Jon 9102 88 88.00 91 Sooner,Ali 8888 -1 0 100