Server IP : 172.16.15.8 / Your IP : 3.144.90.236 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/cjabbott/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// File Name: assign2.cpp // Author: Christie Abbott // Instructor: Dr. Wang // Due Date: February 13, 2008 // compiling: g++ assign2.cpp // execution: ./a.out // // Goal: This program will give a students average, the class average, // and the average age. // #include <iostream> #include <iomanip> using namespace std; struct Student { string name; int test1, test2, final; int age; float avg; }; int main() { //1. declare objects Student someone; char dummy; float class_total = 0; int class_age = 0; int class_size = 0; float class_avg; int age_avg; //2. input 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); //discard '\n' //3. compute class_size ++; someone.avg = (someone.test1 + someone.test2 + someone.final) /4.0; class_total += someone.avg; class_age += someone.age; //4. output cout << "Name: " << someone.name << endl; cout << "Three scores: " << someone.test1 << " " << someone.test2 << " " << 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 << "\nClass average: " << class_avg << endl; age_avg = class_age / float(class_size); cout << "\nClass average age: " << age_avg << endl; cout << "\nDone.\n"; return 0; }