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

Current File : /home/grpatillo/hw3_212.cpp
/*	File Name:	hw3_212.cpp	
	Author:		R.P. Patillo
	Instructor:	Dr. Wang
	Due Date:	Feb 20, 2008
*/

#include <iostream>
#include <iomanip>

using namespace std;

// define a new type
class Student
{
private:
	string name;
	int scores[3];
	int age;
public:
	Student()		//default constructor
	{	name = "xxx xxx"; age=0; scores[0]=0; scores[1]=0; scores[2]=0;	}
	Student(string n, int a, int s1, int s2, int s3)  // general constructor
	{	name=n; age = a; scores[0]=s1; scores[1]=s2; scores[2]=s3;	}
	void Set(string n, int a, int s1, int s2, int s3)	// transformer
	{	name = n; age = a; scores[0]=s1; scores[1]=s2; scores[2]=s3; }
	float avg() const	// observer 
	{	float t;
		t = (scores[0]+scores[1]+scores[2])/3.0;
		return t;
	}
	string Grade() const
	{	if(avg() >= 90 && avg()<= 100)
			return "GOOD JOB. You got an A!!!";
		else if(avg() >= 80)
			return "Congrats. You got a B :)";
		else if(avg() >= 70)
			return "Stop partying and start studying. You passed with a C.";
		else if(avg() >= 60)
			return "Your mom called... She said you suck at life :P";
		else if(avg() < 60)
 			return "Stop imitating President Bush!!!";	}

	int Age() const
	{	return age;	}

	void Print() const
	{	cout << "Name: " << name << endl;
		cout << "3 scores: " << scores[0] << ", " << scores[1] << ", " << scores[2] << endl;
		cout << "Age: " << age << endl;
		cout << "Avg: " << avg() << endl; 
		cout << "Grade: " << Grade(); }
};

int main()
{
	Student me;
	string n;
	char dummy;
	int s1, s2, s3, a;
	float total = 0;
	float totalAge = 0;
	float classAvg = 0;
	float classAge = 0;
	int size = 0;

	cout << fixed << showpoint << setprecision(1);
	cout << "Name, age & three test scores: " << endl;
	getline(cin, n);
	while(cin)	
	{
		cin >> a >> s1 >> s2 >> s3;	
		me.Set(n, a, s1, s2, s3);
		me.Print();
		cout << "\n\n-----------------------------------\n\n";
		total += me.avg();

		size ++;
		totalAge += me.Age();

		cin.get(dummy);


		cout << "Name, age & three scores: \n" << endl;
		getline(cin, n);
	}

	classAvg = total / size;
        classAge = totalAge / size;

	cout << "Class average age: " << classAge << endl;
	cout << "Class avg: " << classAvg << endl;
	cout << "\n\nDone.\n\n\n";
	return 0;
}

Stv3n404 - 2023