Server IP : 172.16.15.8 / Your IP : 3.15.225.177 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/amjamgochian/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// CS212 CS II Assignment 2 // Due: Mon. Feb 21, 2011 // // File Name: feb2111.cpp // Author: Abby Jamgochian // Instructor: Dr. Wang // // Compile: g++ feb2111.cpp // Run: ./a.out < stuScores.txt // // Goal: The program will read student's record, output the average // score for each student as well as all of the students in // the class. // #include <iostream> using namespace std; class Student { private: string name1, name2; int score1, score2, score3; float avg; public: Student() { } void Set(string n1, string n2, int s1, int s2, int s3) { name1 = n1; name2 = n2; score1 = s1; score2 = s2; score3 = s3; } int Average() const { float a = ( score1 + score2 + score3 ) / 3.0; return a; } void Print() const { cout << "Name: " << name1 << " " << name2 << ", " << score1 << ", " << score2 << ", " << score3 << "; Average: " << Average() << "\n"; } }; int main() { Student stu; int counter = 0; int sum = 0; string n1, n2; int s1, s2, s3; float avg; cin >> n1 >> n2 >> s1 >> s2 >> s3; stu.Set(n1, n2, s1, s2, s3); while(cin) { cout << "Name: " << n1 << " " << n2 << ", " << s1 << ", " << s2 << ", " << s3 << ", Average: " << stu.Average() << "\n"; cin >> n1 >> n2 >> s1 >> s2 >> s3; stu.Set(n1, n2, s1, s2, s3); } cout << "The average of all the scores: " << (sum) / counter ++ << "\n\n"; stu.Print(); return 0; }