Server IP : 172.16.15.8 / Your IP : 3.14.251.103 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/cchansen/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// File Name: assignment3.cpp // // Author: Caitlin Hansen // Instructor: Dr. Wang // Class: cs 212 // Due Date: Feb. 16, 2009 // Compile: g++ assignment3.cpp // Run: ./assign3.out // // Goal: The program reads a student's info and outputs each student's average, // the class average, and the average age of the group of students. // #include <iostream> #include <iomanip> using namespace std; struct Student { string name; int age; int test1, test2, final; float avg; }; int main() { Student z; getline(cin, z.name); // read a whole name char dummy; int size = 0; int total_age = 0; float sum = 0; float ageavg; float classavg; while(cin) { cin >> z.age >> z.test1 >> z.test2 >> z.final; z.avg = (z.test1 + z.test2 + z.final)/3.0; sum += z.avg; total_age += z.age; // Debug cout << "Student's info: " << z.name << endl; cout << "Student's age: "<< z.age << endl; cout << "Student's scores: " << z.test1 << "\t" << z.test2 << "\t"; cout << z.final << endl; cout << "Student's average: " << z.avg << endl; cout << endl; size ++; cin.get (dummy); // consume '\n' getline(cin, z.name); } classavg = static_cast<float>(sum) / size; ageavg = static_cast<float>(total_age) / size; cout << setprecision(1); cout << "There are " << size << " students." << endl; cout << "The class average is: " << classavg << endl; cout << "There average age is: " << ageavg << endl; cout << "\n\nDone.\n\n"; return 0; }