Server IP : 172.16.15.8 / Your IP : 3.140.196.5 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/grpatillo/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
/* File Name: hw2_212.cpp Author: R.P. Patillo Instructor: Dr. Wang Due Date: Feb. 13, 2008 Compilation: g++ hw2_212.cpp -o hw2_212.out Execution: ./hw2_212.out Goal: This program will read students' information (name, age, test1, test2, and final), and output each student's average, class average, and the average age of students. */ #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; float class_size = 0; float class_avg; float class_totalAge = 0; float class_avgAge; cout << "Input the name: (ctrl + d to quit)"; getline(cin, someone.name); while(cin) { cout << "First two tests and the final: "; cin >> someone.test1 >> someone.test2 >> someone.final; cout << "The age: "; cin >> someone.age; class_size ++; someone.avg = (someone.test1 + someone.test2 + someone.final) / 4.0; class_total += someone.avg; class_totalAge += 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 << "Student's avg: " << someone.avg << endl; cin.get(dummy); cout << "\nInput the name: "; getline(cin, someone.name); } class_avg = class_total / float(class_size); cout << "\n\nClass average: " << class_avg << endl; class_avgAge = class_totalAge / float(class_size); cout << "Class average Age: " << class_avgAge; cout << "\nDone.\n"; return 0; }