Answer to Question #183041 in C++ for Panjumin

Question #183041

Develop a C++ for the Student Examination Details having student class with data members like roll no, name, marks and grade. Member functions in this class are used for accept / display details of students. Create derived classes such as Engineering, Medical, Sciences etc.. calculate grade based on marks obtained by student. [Note: Use virtual function]


1
Expert's answer
2021-04-19T07:50:13-0400



#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;


class student
{


	public:
	int rollno;
	int marks;
	string name;
	char grade;	
	string subject;
	
	void input()
	{
		 // storing information
		cout<<"Enter Roll No: ";
	    cin>>rollno;
	        
	    cout << "Enter name: ";
	    cin>>name;
	    cout << "Enter marks: ";
	    cin >> marks;
	    cout << endl;
	    
	}
	
	virtual void getGrade()
	{
		if(marks > 90)
		{
			grade = 'A';
		}
		else if(marks > 80 && marks <= 90)
		{
			grade = 'B';
		}
		else if(marks > 70 && marks <= 80)
		{
			grade = 'C';
		}
		else if(marks > 60 && marks <= 70)
		{
			grade = 'D';
		}
		else
		{
			grade = 'E';
		}
	}
	
	void display()
	{
		//diplaying information
		cout << "Roll No: " << rollno << endl;
	    cout << "Name: " << name << endl;
	    cout << "Marks: " << marks << endl;
	    cout << "Grade: "<< grade << endl;
	}
	
	virtual void show1()
	{
		cout << "Branch: Engineering" << endl;
	}
	
	virtual void show2()
	{
		cout << "Branch: Medical" << endl;
	}
	
	virtual void show3()
	{
		cout << "Branch: Commerce" << endl;
	}
	


};


class Engineering : public student
{
	public:
		void show1()
		{
			cout << "Branch: Engineering" << endl;
		}
};


class Medical : public student
{
	public:
		void show2()
		{
			cout << "Branch: Medical" << endl;
		}
	
};




class Commerce : public student
{
	public:
		void show3()
		{
			cout << "Branch: Commerce" << endl;
		}
	
};




int main()
{
	student *s;
	cout<<"Enter which subject students u want to add"<<endl;
	cout<<"1. Engineering"<<endl<<"2. Medical"<<endl<<"3. Commerce"<<endl;
	int option;
	cin>>option;
	
	cout << "Enter number of students: " << endl;
	int n;
	cin>>n;
	
	cout<<endl<<endl;
	switch(option)
	{
		case 1:
			{
			Engineering e[n];
			s = &e[0];
			cout<<"Enter info of Engineering students"<<endl;
			cout<<"---------------------------------------"<<endl;
			for(int i=0; i<n; i++)
			{
				e[i].input();
				e[i].getGrade();
			}
			cout<<endl<<endl;
			cout<<"Display of Student Info"<<endl;
			cout<<"----------------------------"<<endl;
			for(int i=0; i<n; i++)
			{
				s->show1();
				e[i].display();
				cout<<endl<<endl;
			}
			break;
		}
		case 2:
			{
			Medical m[n];
			s = &m[0];
			cout<<"Enter info of medical students"<<endl;
			cout<<"----------------------------------"<<endl;
			for(int i=0; i<n; i++)
			{
				m[i].input();
				m[i].getGrade();
			}
			cout<<endl<<endl;
			cout<<"Display of Student Info"<<endl;
			cout<<"----------------------------"<<endl;
			for(int i=0; i<n; i++)
			{
				s->show2();
				m[i].display();
				cout<<endl<<endl;
			}
			break;
		}
		case 3:
			{
			Commerce c[n];
			s = &c[0];
			cout<<"Enter info Commerce students"<<endl;
			cout<<"---------------------------------"<<endl;
			for(int i=0; i<n; i++)
			{
				c[i].input();
				c[i].getGrade();
			}
			cout<<endl<<endl;
			cout<<"Display of Student Info"<<endl;
			cout<<"----------------------------"<<endl;
			for(int i=0; i<n; i++)
			{
				s->show3();
				c[i].display();
				cout<<endl<<endl;
			}
			break;
		}
				
	}
 
}

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