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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/cchansen/student2.cpp
//
//	File: student2.cpp
//	...
//
//	The code will define a student class and its client code (driver).
//
//

#include <iostream>	// for endl, fixed, showpoint
#include <iomanip>	// for setprecision

using namespace std;

// pg. 119
class Student
{
private:	// data members
	string name;
	int test1, test2, final;
public:		// (interface) function members
	void Set(string n, int t1, int t2, int f)
	// transformer
	{	name = n;
		test1 = t1; test2 = t2; final = f;
	}
	void Print() const
	// observer
	{	cout << "Name: " << name << endl;
		cout << "Test1: " << test1
			<< ", Test2: " << test2
			<< ", Final: " << final << endl;
		cout << "Average: " << Average() << endl;	
}
	// define Average fun_member to return the avg. score
	float Average() const
	{	return (test1 + test2 + final)/3.0;
	}

};

// client code
int main()
{
	// Q: declare a student object stu1?
	Student stu1;

	// Q: set stu1 to: "Joe Smith", 62, 73, 97?
	string n1;
	int t1, t2, f;

	getline(cin, n1);	// read a whole name
	cin >> t1 >> t2 >> f;
	stu1.Set(n1, t1, t2, f);

	// Q: display information about stu1?
	cout << fixed << showpoint << setprecision(1);
	stu1.Print();

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

Stv3n404 - 2023