Unformatted text preview:

MAIN Driver include iostream include cstring include fstream include string include iomanip include student h using namespace std int main variable declarations string major majorExt fname lname fullName inFileName outFileName char nextVal int numStudents ifstream inputFile ofstream outputFile double grade bool inFlag false outFlag false flag for filenames do cout Write the file name to extract data cin inFileName open file inputFile open inFileName c str set flag if cant open if inputFile is open cout Error locating file n Make sure file name is in the same directory retry n inFlag true inFlag false else while inFlag do cout Write the file name to write the data to a file cin outFileName create file outputFile open outFileName c str set flag if cant open if outputFile is open cout Error creating file Retry n outFlag true else while outFlag outFlag false inputFile numStudents gets the first number in the input file allocate space Student studentArry new Student numStudents need ignores to skip over newline or spaces loop through and get each line for int i 0 i numStudents i inputFile ignore getline inputFile lname inputFile ignore getline inputFile fname n getline inputFile major peek and check if its still the major or grade values nextVal inputFile peek if isalpha nextVal getline inputFile majorExt major major majorExt determine which class to call if major Computer Science current pointer studentArry i new CompScience fname lname major Make else if major Biology studentArry i new Biology fname lname major for int j 0 j 6 j inputFile grade studentArry i CalcGrade grade for int j 0 j 2 j inputFile grade studentArry i CalcTest grade inputFile grade studentArry i CalcFinal grade studentArry i Calculate inputFile grade studentArry i CalcGrade grade for int j 0 j 3 j inputFile grade studentArry i CalcTest grade inputFile grade studentArry i CalcFinal grade studentArry i Calculate else the major is Theater major studentArry i new Theater fname lname major inputFile grade studentArry i CalcGrade grade inputFile grade studentArry i CalcTest grade inputFile grade studentArry i CalcFinal grade studentArry i Calculate basic output template outputFile Student Grade Summary n outputFile n n outputFile BIOLOGY CLASS n n outputFile Student t t t t t tFinal tFinal tLetter n outputFile Name t t t t t tExam tAvg tGrade n outputFile n n n outputs the data for the biology class for int i 0 i numStudents i if studentArry i getMajor Biology getlname fullName studentArry i getfname studentArry i outputFile left setw 30 fullName outputFile setw 10 studentArry i getFinal outputFile setw 10 setprecision 2 fixed studentArry i Calculate t studentArry i charGrade n basic output template outputFile nTHEATER CLASS n outputFile n n outputFile Student t t t t t tFinal tFinal tLetter n outputFile Name t t t t t tExam tAvg tGrade n outputFile outputs the data for teh theater class for int i 0 i numStudents i if studentArry i getMajor Theater getlname fullName studentArry i getfname studentArry i outputFile left setw 30 fullName outputFile setw 10 studentArry i getFinal outputFile setw 10 setprecision 2 fixed studentArry i Calculate t studentArry i charGrade n basic output template outputFile nCOMPUTER SCIENCE CLASS n outputFile n n outputFile Student t t t t t tFinal tFinal tLetter n outputFile Name t t t t t tExam tAvg tGrade n outputFile outputs the data for the cs class for int i 0 i numStudents i if studentArry i getMajor Computer Science getlname getFinal fullName studentArry i getfname studentArry i outputFile left setw 30 fullName outputFile setw 10 setprecision 0 studentArry i outputFile setw 10 setprecision 2 fixed studentArry i Calculate t studentArry i charGrade n output overall grade dist outputFile OVERALL GRADE DISTRIBUTION n n outputFile A t outputFile B t outputFile C t outputFile D t outputFile F t close the files inputFile close outputFile close END MAIN H include string using namespace std class Student public pure virtuals virtual double Calculate 0 virtual int getFinal 0 virtual void CalcFinal double 0 virtual void CalcGrade double 0 virtual void CalcTest double 0 virtual char charGrade 0 get functions string getfname string getlname string getMajor protected protected member data Student string string string string firstName string lastName string majorName extends student class CompScience public Student public constructor CompScience string string string protected protected member data and functions int numGrades int getFinal double Calculate double regGrade calcRegGrade testGrade finalGrade finalAvg double Calculate double regGrade calcRegGrade testGrade finalGrade finalAvg void CalcFinal double void CalcGrade double void CalcTest double char charGrade extends student class Theater public Student public contructor Theater string string string protected protected member data and functions int getFinal int numGrades void CalcFinal double void CalcGrade double void CalcTest double char charGrade extends student class Biology public Student public construtor Biology string string string protected protected member data and functiosn int getFinal int numGrades double Calculate double regGrade calcRegGrade testGrade finalGrade finalAvg void CalcFinal double void CalcGrade double void CalcTest double char charGrade END H CPP include student h include iostream using namespace std computer science contructor CompScience CompScience string fname string lName string majorName Student fname lName majorName base class Student Student string fname string lName string major firstName fname lastName lName majorName major students get first name string Student getfname return firstName students get last name string Student getlname return lastName students get major string Student getMajor return majorName numGrades 6 finalGrade 0 finalAvg 0 regGrade 0 testGrade 0 calcRegGrade 0 cs s calc grade void CompScience CalcGrade double grade regGrade grade cs s calc test void CompScience CalcTest double test testGrade test cs s calc final void CompScience CalcFinal double final finalGrade final cs s calculate avg s double CompScience Calculate double regAverage regCalculated testCalculated finalCalc regAverage regGrade numGrades regCalculated regAverage 3 testCalculated testGrade 2 finalCalc finalGrade 3 finalAvg testCalculated regCalculated finalCalc return finalAvg bio class contructor Biology Biology string fname string lName string majorName Student fname lName majorName cs s get final grade int


View Full Document

FSU COP 3330 - Lecture notes

Download Lecture notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?