Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iomanip>
- #include<iostream>
- #include<fstream>
- #include<cstdlib>
- #include<cctype>
- using namespace std;
- const int max_students = 7;
- class Student
- {
- private:
- char studentname[30];
- int projgrade[6];
- int examgrade[2];
- int quizgrade[9];
- int finalgrade;
- double projavg;
- double examavg;
- double quizavg;
- double totalavg;
- char grade[30];
- public:
- Student();
- ~Student();
- void get_student_scores();
- void compute_student_stats();
- void determine_student_grade();
- void display_student_name_gpa_grade();
- double student_average();
- };
- class Course
- {
- private:
- Student student[max_students];
- int highest;
- int lowest;
- public:
- Course();
- ~Course();
- void get_grades();
- void evaluate_class();
- void determine_index_of_highest_lowest();
- void display_highest();
- void display_lowest();
- void display_stats();
- };
- const double projectweight = 0.25,
- quizweight = 0.10,
- examweight = 0.15,
- finalweight = 0.20;
- int main()
- {
- Course the_course;
- void describe_program();
- describe_program();
- the_course.get_grades();
- the_course.evaluate_class();
- the_course.determine_index_of_highest_lowest();
- the_course.display_stats();
- the_course.display_highest();
- the_course.display_lowest();
- system("PAUSE");
- return 0;
- }
- void describe_program()
- {
- cout<<"This program will prompt for the names of seven students, and for each \n";
- cout<<"student, prompt for the various grades that student has received. \n";
- cout<<"The program will also calculate averages for each grade, as well as \n";
- cout<<"the student with the highest and student with the lowest class average. \n";
- cout<<"All results will be printed to the screen and sent to an external text \n";
- cout<<"file, 'grades.txt'.";
- cout<<endl<<endl;
- }
- ///////////////////////////////////////////////////////////////////////////////
- // "Student" Functions //
- ///////////////////////////////////////////////////////////////////////////////
- Student::Student()
- {
- studentname[30] = '\0';
- projgrade[0] = 0;
- examgrade[0] = 0;
- quizgrade[0] = 0;
- finalgrade = 0;
- projavg = 0;
- examavg = 0;
- quizavg = 0;
- totalavg = 0;
- grade[30] = '\0';
- }
- Student::~Student()
- {
- cout<<"Student object going out of existence!\n";
- system("PAUSE");
- }
- void Student::get_student_scores() //Enter grades for the student
- {
- int i;
- cout<<"Enter the name of the student: ";
- cin.getline(studentname,30);
- cout<<endl<<endl;
- for(i=0; i<7; i++) //Enter project grades
- {
- cout<<"Enter the grade for Project "<<i+1<<":";
- cin>>projgrade[i];
- cout<<endl;
- while(projgrade[i] > 100 || projgrade[i] < 0)
- {
- cout<<"Illegal grade entered!"<<endl;
- cout<<"Enter the grade for Project "<<i+1<<":";
- cin>>projgrade[i];
- cout<<endl;
- };
- }
- cout<<endl;
- for(i=0; i<3; i++) //Enter exam grades
- {
- cout<<"Enter the grade for Exam "<<i+1<<":";
- cin>>examgrade[i];
- cout<<endl;
- while(examgrade[i] > 100 || examgrade[i] < 0)
- {
- cout<<"Illegal grade entered!"<<endl;
- cout<<"Enter the grade for Exam "<<i+1<<":";
- cin>>examgrade[i];
- cout<<endl;
- };
- }
- cout<<endl;
- for(i=0; i<10; i++) //Enter quiz grades
- {
- cout<<"Enter the grade for Quiz "<<i+1<<":";
- cin>>quizgrade[i];
- cout<<endl;
- while(quizgrade[i] > 100 || quizgrade[i] < 0)
- {
- cout<<"Illegal grade entered!"<<endl;
- cout<<"Enter the grade for Quiz "<<i+1<<":";
- cin>>quizgrade[i];
- cout<<endl;
- };
- }
- cout<<endl;
- cout<<"Enter the grade for the Final Exam:";
- cin>>finalgrade;
- while(finalgrade > 100 || finalgrade < 0)
- {
- cout<<"Illegal grade entered!"<<endl;
- cout<<"Enter the grade for Final Exam:";
- cin>>finalgrade;
- cout<<endl;
- };
- cout<<endl<<endl;
- }
- void Student::compute_student_stats() //Calculates averages
- {
- int i, sum;
- double temp;
- //Calculate project average
- sum = 0;
- for(i=0; i<6;i++)
- sum += projgrade[i];
- temp = static_cast<double>(sum)/6;
- projavg = static_cast<int>(temp + 0.5);
- //Calculate exam average
- sum = 0;
- for(i=0;i<3;i++)
- sum += examgrade[i];
- temp = static_cast<double>(sum)/2;
- examavg = static_cast<int>(temp + 0.5);
- //Calculate quiz average
- sum = 0;
- for(i=0;i<10;i++)
- sum += quizgrade[i];
- temp = static_cast<double>(sum)/5;
- quizavg = static_cast<int>(temp + 0.5);
- }
- void Student::determine_student_grade() //Determines total grade and letter grade
- {
- totalavg = projavg * projectweight +
- quizavg * quizweight +
- examavg * examweight +
- finalgrade * finalweight;
- grade[0] = ' ';
- grade[1] = ' ';
- if(totalavg>=93)
- {
- grade[0] = 'A';
- grade[1] = ' ';
- }
- else if(totalavg>=89)
- {
- grade[0] = 'A';
- grade[1] = '-';
- }
- else if(totalavg>=87)
- {
- grade[0] = 'B';
- grade[1] = '+';
- }
- else if(totalavg>=83)
- {
- grade[0] ='B';
- grade[1] = ' ';
- }
- else if(totalavg>=79)
- {
- grade[0] = 'B';
- grade[1] = '-';
- }
- else if(totalavg>=77)
- {
- grade[0] = 'C';
- grade[1] = '+';
- }
- else if(totalavg>=73)
- {
- grade[0] = 'C';
- grade[1] = ' ';
- }
- else if(totalavg>=69)
- {
- grade[0] = 'C';
- grade[1] = '-';
- }
- else if(totalavg>=67)
- {
- grade[0] = 'D';
- grade[1] = '+';
- }
- else if(totalavg>=63)
- {
- grade[0] = 'D';
- grade[1] = ' ';
- }
- else if(totalavg>=57)
- {
- grade[0] = 'D';
- grade[1] = '-';
- }
- else
- {
- grade[0] = 'F';
- grade[1] = ' ';
- }
- }
- void Student::display_student_name_gpa_grade() //Display results to screen and text file
- {
- cout<<"Student name: "<<studentname<<endl;
- cout<<"Semester Average: "<<totalavg<<endl;
- cout<<"Grade: "<<grade[0]<<grade[1]<<endl;
- //Send to text file
- ofstream outs;
- outs.open("grades.txt",ios::app);
- outs<<"Student name: "<<studentname<<endl;
- outs<<"Semester Average: "<<totalavg<<endl;
- outs<<"Grade: "<<grade<<endl;
- outs.close();
- }
- double Student::student_average() //Returns average grade for one student
- {
- return totalavg;
- }
- ///////////////////////////////////////////////////////////////////////////////
- // "Course" Functions //
- ///////////////////////////////////////////////////////////////////////////////
- Course::Course() //Initialize highest grade and lowest grade subscripts
- {
- highest = 0;
- lowest = 0;
- }
- Course::~Course()
- {
- cout<<"Course object going out of existence!\n";
- system("PAUSE");
- }
- void Course::get_grades() //Tells user what student # to enter data for
- {
- int i;
- for(i=0; i<7; i++)
- {
- cout<<"Enter data for student #"<<i+1<<endl;
- student[i].get_student_scores();
- cin.ignore();
- }
- }
- void Course::evaluate_class() //Calculates grades for all students
- {
- int i;
- for(i=0; i<7; i++)
- {
- student[i].compute_student_stats();
- student[i].determine_student_grade();
- }
- }
- void Course::determine_index_of_highest_lowest() //Finds highest and lowest grade in class.
- {
- double max;
- double tempgrade;
- max = 0;
- tempgrade = 0;
- for(int i=0; i<7; i++)
- {
- tempgrade = student[i].student_average();
- if(tempgrade>max)
- {
- highest = i;
- max = tempgrade;
- }
- }
- max = 101;
- tempgrade = 0;
- for(int i=0; i<7; i++)
- {
- tempgrade = student[i].student_average();
- if(tempgrade<max)
- {
- lowest = i;
- max = tempgrade;
- }
- }
- }
- void Course::display_stats() //Displays all student info on screen
- {
- int i;
- for(i=0; i<7; i++)
- student[i].display_student_name_gpa_grade();
- }
- void Course::display_highest() //Displays student with highest grade
- {
- ofstream outs;
- outs.open("grades.txt",ios::app);
- cout<<"\n\nThe highest grade in the class was: \n";
- outs<<"\n\nThe highest grade in the class was: \n";
- outs.close();
- student[highest].display_student_name_gpa_grade();
- }
- void Course::display_lowest() //Displays student with lowest grade
- {
- ofstream outs;
- outs.open("grades.txt",ios::app);
- cout<<"\n\nThe lowest grade in the class was: \n";
- outs<<"\n\nThe lowest grade in the class was: \n";
- outs.close();
- student[lowest].display_student_name_gpa_grade();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement