Server IP : 172.16.15.8 / Your IP : 3.149.23.124 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 (0755) : /home/jljustice/cs212/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// File Name: student3.cpp // Author: Jared Justice // Instructor: Dr. Wang // Due Date: Feb. 23, 2009 // Goal: To read a students' info and output each student's // average, class average, and the age of the students. // #include <iostream> #include <iomanip> using namespace std; class Student { string name; int age; int test1, test2, final; public: int Age() const { return age; } float Avg() const { return (test1 + test2 + final)/3.0; } void Print() const { cout << fixed << setprecision(2); cout << "Student Name: " << name << endl; cout << "Student Age: " << Age() << endl; cout << endl; cout << "\tTest scores: "<< endl; cout << "\t-------------" << endl; cout << " Test 1: " << setw(4) << test1 << endl; cout << " Test 2: " << setw(4) <<test2 << endl; cout << " Final: " << setw(5) << final << endl; cout << " Average: " << setw(6) << Avg() << endl; } // transformer void Set(string n, int a, int t1, int t2, int f) { name=n; age=a; test1=t1; test2=t2; final=f;} }; //driver int main() { //declare an Student stu? Student stu; string n; int a, t1, t2, f; int counter = 0; int total_age = 0; float total_grade_avg = 0; float avg_age; float class_avg; char dummy; // read the first item? getline(cin, n); while(cin) //Eof-Ctrl loop { // read the rest cin >> a >> t1 >> t2 >> f; // process here counter ++; stu.Set(n, a, t1, t2, f); total_age += stu.Age(); total_grade_avg += stu.Avg(); // out the stu'd info? stu.Print(); cout << "\n---------------------\n"; cout << endl; // read the next stu's info cin.get(dummy); getline(cin, n); } avg_age = static_cast<float>(total_age) / counter; class_avg = total_grade_avg / counter; cout << "\t Class Info" << endl; cout << "\t------------" << endl; cout << "\tTotal age: " << setw(12) << total_age << endl; cout << "\tClass avg: " << setw(15) << class_avg << endl; cout << "\tAverage age: " << setw(13) << avg_age << endl; cout << "\tNumber of Student's: " << setw(2) << counter << endl; cout << endl; cout << "You are Finished." << endl; return 0; }