Server IP : 172.16.15.8 / Your IP : 18.118.119.129 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/vnlaughlin/../drsparks/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// File Name: student1.cpp // // Class: CS 212 Comp. Prog. II // Author: Dale Sparks // Instructor: Dr. Wang // Date: Feb. 16, 2009 // Compile: g++ student1.cpp -o s1.out // Run: ./jan28.out // // Goal: Write a program to read students' information (name, age, // test1, test2, and final), and output each student's average, // class average, and the average age of students. Total point // for each test is 100. Use struct to define the student type. // Display to the first decimal place. Use EOF-controlled loop. // // #include <iostream> #include <iomanip> using namespace std; struct Student { string name; int test1, test2, final; int age; float avg; }; int main() { // 1. decl. obj. Student someone; char dummy; float class_total = 0; int class_size = 0; float class_avg; float class_totage = 0; float class_avgage = 0; // 2. input getline(cin, someone.name); cout << fixed << setprecision(1); while(cin) { cin >> someone.test1 >> someone.test2 >> someone.final; cin >> someone.age; cin.get(dummy); class_size ++; someone.avg = (someone.test1+someone.test2 +someone.final)/3.0; class_total += someone.avg; class_totage += someone.age; // 4. out 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; getline(cin, someone.name); } class_avgage = class_totage / class_size; cout << "\nClass average age: " << class_avgage; class_avg = class_total / float(class_size); cout << "\nClass average: " << class_avg << endl; cout << "\nDone.\n"; return 0; }