Answer to Question #322438 in C++ for Harsh

Question #322438

There is an Admission class that assigns the admission id and registration number to the Student. The student’s general information i.e. name, email, and contact number is initialized through another class. The student's result is controlled by another class that returns the student's cgpa based on his/her score in all tgpa’s.


Create 5 objects of students, input and display their name, registration number, section, cgpa using any possible type of Inheritance.



1
Expert's answer
2022-04-07T07:30:14-0400
#include <iostream>
#include <string>

using namespace std;

class Admission
{
	int admID;
	int regNum;
public:
	Admission(int _admID=0, int _regNum=0)
	:admID(_admID), regNum(_regNum){}


	void DisplayAdm()
	{
		cout << "\nThe admission id is " << admID
			<< "\nThe registration number is " << regNum;
	}
};

class Result
{
	float cgpa;
public:
	Result(float _cgpa=0):cgpa(_cgpa){}
	void CountCGPA()
	{
		float tmp;
		float sum=0;
		int count = 0;
		cout << "\nPlease, enter all your cgpa (0 - stop entering):";
		do
		{
			cin >> tmp;
			if (tmp > 0)
			{
				count++;
				sum += tmp;
			}
		} while (tmp > 0);
		cgpa = sum / count;
	}
	void DisplayRes()
	{
		cout << "The student's result is " << cgpa;
	}
};

class Student:public Admission,public Result
{
	string name;
	string email;
	int contNum;
public:
	Student(string _name="", string _email="", int _contNum=0,
		int _admID = 0, int _regNum = 0)
	:Admission(_admID,_regNum), Result(),name(_name), email(_email), contNum(_contNum){}
	void Display()
	{
		cout << "\nName is " << name
			<< "\nEmail is " << email
			<< "\nContact number is " << contNum;
	}
};

int main()
{
	Student arr[5] = { Student("Jack","jck@mail.com",1,123,789),
					   Student("John","jhn@mail.com",2,234,777),
						Student("Nancy","nan@mail.com",3,345,666),
						Student("Mary","mry@mail.com",4,456,555), 
						Student("Tom","tm@mail.com",5,567,444), };
	for (int i = 0; i < 5; i++)
	{
		arr[i].Display();
		arr[i].DisplayAdm();
		arr[i].CountCGPA();
		arr[i].DisplayRes();
	}
}

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