Server IP : 172.16.15.8 / Your IP : 18.116.81.255 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/bsjackson/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// CS212 CS II Assignment 2 // // Due: Monday Feb. 28, 2011 // // File: hw2.cpp // Author: Brittany Jackson // Instructor: Dr. Wang // // Compile: g++ hw2.cpp // Run: ./a.out < stuScores.txt // // Goal: Use the new class type and read the scores // from hw1.cpp, out the average score for each // student as well as all students in the class #include <iostream> using namespace std; class Student { string first, last; int test1, test2, test3; float avg; public: Student() { } void Set(string f, string l, int t1, int t2, int t3) { first = f; last = l; test1 = t1; test2 = t2; test3 = t3; } float Avg() const { float a = (test1 + test2 + test3)/3.0; return a; } void Print() const { cout << "Name: " << first << " " << last << ", Avg: " << Avg() << "\n"; } }; int main() { int counter = 0; float total_avg = 0; float sum_avg = 0; Student stu; string s1, s2; int t1, t2, t3; cin >> s1 >> s2 >> t1 >> t2 >> t3; while (cin) { stu.Set(s1, s2, t1, t2, t3); stu.Print(); //output student info counter++; sum_avg += stu.Avg(); cin >> s1 >> s2 >> t1 >> t2 >> t3; } total_avg = sum_avg / counter; cout << "Total Average: " << total_avg <<endl; return 0; }