Server IP : 172.16.15.8 / Your IP : 3.135.209.107 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/jmsanchez/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Jason Sanchez // Wed. 20, 1988 // Dr. Wang // Assignment 3 #include <iostream> using namespace std; // define a new type class Student { private: string name; int scores[3]; int age; public: Student() // default constructor { name = "xxx xxx"; age=0; scores[0]=0; scores[1]=0; scores[2]=0; } Student(string n, int a, int test1, int test2, int final) // general construct { name=n; age=a; scores[0]=test1; scores[1]=test2; scores[2]=final; } void Set(string n, int a, int test1, int test2, int final) // transformer { name=n; age=a; scores[0]=test1; scores[1]=test2; scores[2]=final; } float avg() const // observer { float t; t = (scores[0]+scores[1]+scores[2])/4.0; return t; } int Age() { return age; } char Grade() const { if( avg() >= 60 ) return 'P'; else return 'F'; } void Print() const { cout << "Name: " << name << " Age: " << age << ", Test1: " << scores[0] << ", Test2:" << scores[1] << ", Final:" << scores[2] << endl; cout << "Avg: " << avg(); cout << ", Grade: " << Grade(); } }; int main() { Student me; // invoke default string n; char dummy; int a, test1, test2, final; float total = 0; int size=0; float tage = 0; getline(cin, n); while(cin) { cin >> a >> test1 >> test2 >> final; me.Set(n, a, test1, test2, final); me.Print(); cout << "\n---------\n\n"; total += me.avg(); size ++; tage += me.Age(); cin.get(dummy); // drop '\n' getline(cin, n); } cout << "Class average score: " << total/size << endl; cout << "class average age: " << tage/size << endl; cout << "\n\nDone.\n\n\n"; return 0; }