Server IP : 172.16.15.8 / Your IP : 3.135.184.27 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/drsparks/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
#include <iostream> // for endl, fixed, showpoint #include <iomanip> // for setprecision using namespace std; class Student { private: // data members string name; int test1, test2, final; public: //(interface) fun. members void Set(string n, int t1, int t2, int f) // transformer { name = n; test1 = t1; test2 = t2; final = f; } void Print() const // observer { cout << "Name: " << name << endl; cout << "Test1: " << test1 << ", Test2: " << test2 << ", Final: " << final << endl; cout <<"Average: " << Average() << endl; } // define Average fun_member to return the // avg score float Average() const { return (test1 + test2 + final)/3.0; } }; // client code int main() { // Q: declare a Student object stu1? Student stu1; // Q: set stu1 to: "Joe Smith", 62, 73, 97? string n1; int t1, t2, f; getline(cin, n1); // read a whole name while(cin) { cin >> t1 >> t2 >> f; stu1.Set(n1, t1, t2, f); getline(cin, n1); // read a whole name cin >> t1 >> t2 >> f; stu1.Set(n1, t1, t2, f); } // Q: diosplay info about stu1? cout << fixed << showpoint << setprecision(1); stu1.Print(); cout << "\n\nDone. Bye-Bye.\n\n"; return 0; }