Answer to Question #329776 in C++ for zaira

Question #329776

2. We want to keep track of Students studying in university. To do so create a class Students that has the following instance variables Reg_no, Name, Age, Address, Semester, CGPA and Fee. Where address is the object of address class and fee is same for all students.


The Student Class should have default constructor and augmented constructor. You need to write set() method to assign values to the instance variables and a method which can return grade using CGPA. You are required to create two objects of Student class and then display his Data along with grade.



1
Expert's answer
2022-04-17T11:03:40-0400
#include <iostream>
#include <string>


using namespace std;


class Address
{
	string addr;
public:
	Address(){}
	Address(string _addr):addr(_addr){}
	Address(Address& ad):addr(ad.addr){}
	string GetAddress() { return addr; }
};


class Student
{
	int Reg_no;
	string Name;
	int age;
	Address a;
	string sem;
	float CGPA;
	float fee;
public:
	Student(){}
	Student(int _Reg_no, string _Name, int _age, Address _a, string _sem, float _CGPA, float _fee)
	:Reg_no(_Reg_no), Name(_Name), age(_age), a(_a),sem(_sem), CGPA(_CGPA), fee(_fee){}
	void Set()
	{
		cout << "\nPlease, enter Reg_no: ";
		cin >> Reg_no;
		cout << "Please, enter Name: ";
		cin >> Name;
		cout << "Please, enter an age: ";
		cin >> age;
		string s;
		cout << "Please, enter an address: ";
		cin >> s;
		Address b(s);
		a=b;
		cout << "Please, enter semestr: ";
		cin >> sem;
		cout << "Please, enter CGPA: ";
		cin >> CGPA;
		cout << "Please, enter fee: ";
		cin >> fee;
	}
	float GetGrade() { return CGPA; }
	void Display()
	{
		cout << "\nReg_no of student is " << Reg_no
			<< "\nName of student is " << Name
			<< "\nAge of student is " << age
			<< "\nAddress of student is " << a.GetAddress()
			<< "\nSemestr of student is " << sem
			<< "\nCGPA of student is " << CGPA
			<< "\nFee of student is " << fee;
	}
};


int main()
{
	Address a("35 Street");
	Student x(1234, "Jack", 39, a, "1 semestr", 78, 100);
	cout<<"Grade id "<<x.GetGrade();
	x.Display();
	Student b;
	b.Set();
	b.Display();
	
}









Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS