Server IP : 172.16.15.8 / Your IP : 3.142.133.210 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/tasantos/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Due Date: Feb. 13, 2008 // File Name: hw2.cpp // Author: Tara Santos // Instructor: Dr. John Wang // Compilation: vi hw2.cpp // Execution: g++ hw2.cpp // Goal: Program will read students' information and output // each student's average, class average, and the average // age of students. Total points for each test is 100 and // the final is 200. using struct to define student type. // Display to the first decimal point. #include <iostream> #include <iomanip> using namespace std; struct Student { string name; int test1, test2, final; int age; float avg; }; int main() { Student someone; char dummy; float class_total = 0; int class_size = 0; int class_age = 0; float class_avg; float age_avg; cout << fixed << showpoint << setprecision(1); cout << "Input the name: "; getline(cin, someone.name); while(cin) { cout << "Three exams: "; cin >> someone.test1 >> someone.test2 >> someone.final; cout << "The age: "; cin >> someone.age; cin.get(dummy); class_size ++; class_age ++; someone.avg = (someone.test1 + someone.test2 + someone.final)/4.0; class_total += someone.avg; class_age += someone.age; cout << "Name: " << someone.name << endl; cout << "Test 1: " << someone.test1 << endl; cout << "Test 2: " << someone.test2 << endl; cout << "Final: " << someone.final << endl; cout << "Age: " << someone.age << endl; cout << "Average: " << someone.avg << endl; cout << "Input the name: "; getline(cin, someone.name); } class_avg = class_total / float(class_size); cout << "\n\nClass Average: " << class_avg << endl; age_avg = class_age / float(class_size); cout << "Average Age of Class: " << age_avg << endl; return 0; }