Server IP : 172.16.15.8 / Your IP : 3.15.239.145 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/bafreeman/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// File name: assign3.cpp // Author: Benjamin Freeman // Instructor: Dr. John Wang // Due date: Wed., Feb. 20, 2008 // Compilation: g++ assign3.cpp -o assign2.out // Execution: ./assign3.out // // Goal: This program will allow the user to input students' // information (name, age, test1, test2, and final), and output each // student's average, class average, and the average age of students #include <iostream> #include <iomanip> using namespace std; // define a new type class Student { private: string name; int test1[1]; int test2[1]; int final[1]; int age; public: Student() { name = "xxx xxx"; test1[0]=0; test2[0]=0; final[0]=0; age = 0; } Student(string n, int s1, int s2, int s3, int s4) { name=n; test1[0]=s1; test2[0]=s2; final[0]=s3; age = s4; } void Set(string n, int s1, int s2, int s3, int s4) { name=n; test1[0]=s1; test2[0]=s2; final[0]=s3; age=s4; } float avg() const { float t; t = (test1[0]+test2[0]+final[0])/4.0; return t; } int Age() const { return age; } void Print() const { cout << "Name: " << name << ", 3 scores: " << test1[0] << ", " << test2[0] << ", " << final[0] << endl; cout << "Avg: " << avg() << endl; cout << "Age: " << Age() << endl; } }; int main() { Student me; string n; char dummy; int s1, s2, s3, s4; float total = 0; int size=0; int age_size=0; float age_avg; float class_avg; int age_total = 0; cout << fixed << showpoint << setprecision(1); cout << "Insert name, scores and age(Press Ctrl-d to quit): "; getline(cin, n); while(cin) { cin >> s1 >> s2 >> s3 >> s4; me.Set(n, s1, s2, s3, s4); me.Age(); me.Print(); cout << "\n------------------\n\n"; total += me.avg(); size ++; age_total += me.Age(); age_size ++; cin.get(dummy); // drop '\n' cout << "Insert name, scores, and age(Press Ctrl-d to quit): "; getline(cin, n); } cout << "\n\n"; class_avg = total/float(size); age_avg = age_total/float(age_size); cout << "\n*******************\n"; cout << "Class avg: " << class_avg << endl; cout << "Age_avg: " << age_avg << endl; cout << "\n\nDone.\n\n\n"; return 0; }