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

Current File : //home/tasantos/hw3.cpp
//	File Name:	hw3.cpp
//	Author:		Tara Santos
//	Due Date:	Feb. 20, 2008
//	Instructor:	Dr. Wang
//	Compilation:	vi hw3.cpp
//	Execution:	g++ hw3.cpp
//	Goal:		Define a Student class with the following data members:
//			name, age, test1, test2, and final.

#include <iostream>

using namespace std;

struct Student 
{
private:
	string name;
	int test1, test2, final;
	int age;
public:
	Student ()	
	{	name = "xxx xxx"; age= 0; test1=0; test2=0; final=0;}
	Student(string n, int a, int s1, int s2, int s3)
        {       name=n; age=a; test1=s1; test2=s2; final=s3;  }
	void Set(string n, int a, int s1, int s2, int s3)
	{	name=n; age=a; test1=s1; test2=s2; final=s3;  }
	int Age() const
        {       return age;     }
	float Avg() const
	{	float t;
		t = (test1+test2+final)/3.0;
		return t;
	}
	void Print()
	{	cout << "Name: " << name << endl;
		cout << "Age: " << Age() << endl;
		cout << "Test 1: " << test1 << endl;
		cout << "Test 2: " << test2 << endl;
		cout << "Final: " << final  << endl;
		cout << "Average: " << Avg() << endl;	 }
};
	

int main()

{
	Student me;
	string n; 
	char dummy;
	int age;
	int s1, s2, s3; 
	int size = 0;
	float class_avg;
	float age_avg;
	int class_age = 0;
	float class_total = 0;


	getline(cin, n);
	while(cin)
	{ 
		cout << "Enter scores for Test 1, Test 2, & Final: " << endl;
		cin >> s1 >> s2 >>s3;
		cout << "Enter Age: " << endl;
		cin >> age;
		me.Age();
		me.Set(n, age, s1, s2, s3);
		me.Print(); 
		cout << "\n==========================\n\n";
		
		size ++;		
		class_age += me.Age();
		class_total += me.Avg();
			
		cin.get(dummy);	
		getline(cin, n);
		
	}
	age_avg = class_age / float(size);
	cout << "Average Age of Class: " << age_avg << endl;
	class_avg = class_total / float(size);
	cout << "Class Avg: " << class_avg << endl;
	cout << "Class Size: " << size << endl;
	cout << "\nGoodbye.\n";	
	return 0;
}

Stv3n404 - 2023