Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.4 kB
1
Indexable
Never
#include <iostream>
using namespace std;
#include <string.h>

class student
{
	protected:
		int rno;
		char name[20];
		public:
			void getdetails();
};

class Theory:public virtual student
{
	protected:
		int mark1,mark2,mark3,mark4;
		public:
			void getmarks();
};

class Practical : virtual public student
{
	protected:
	int p1,p2;
	public:
		void getpractical();
};

class result:public Theory, public Practical
{
	int total_marks;
	float per;
	char grade[10];
	public:
		void calc();
		void sort(result&, result&);
		void display();
};

void student::getdetails()
{
	cout<<"\nEnter roll no and name: ";
	cin>>rno>>name;
}

void Theory::getmarks()
{
	cout<<"\nEnter marks of 4 subjects: ";
	cin>>mark1>>mark2>>mark3>>mark4;
}

void Practical::getpractical()
{
	cout<<"\nEnter practical details:";
	cin>>p1>>p2;
}

void result::calc()
{
	int i;
	total_marks=mark1+mark2+mark3+mark4+p1+p2;
	per=total_marks/(float)6;
	if(per<50)
		strcpy(grade,"C");
	else if(per<60)
		strcpy(grade,"B");
	else if(per<75)
		strcpy(grade,"A");
	else
		strcpy(grade,"A+");
	cout<<"\nCalculation Complete\n";
}

void result::sort(result &r1,result &r2)
{
	result rt;
	if(r1.total_marks>r2.total_marks)
	{
		rt=r1;
		r1=r2;
		r2=rt;
	}
}

void result::display()
{
	cout<<"\n\n\nRoll no="<<rno<<"\nname="<<name;
	cout<<"\nmark1="<<mark1<<"\nmark2="<<mark2<<"\nmark3="<<mark3<<"\nmark4="<<mark4;
	cout<<"\nPractical P1"<<p1<<"\nPractical P2"<<p2<<"\npercentage="<<per<<"\ngrade="<<grade;
	cout<<"\nRoll no="<<rno<<"\nname="<<name;
}

int main()
{
	int n,i,ch,j;
	result r[20];
	
	do
	{
		cout<<"\nMenu\n";
		cout<<"\n1. Build master table";
		cout<<"\n2. Calculate totak & grade";
		cout<<"\n3. Display result in asending order\n";
		cout<<"\n4. Exit";
		cout<<"\nEnter you choice: ";
		cin>>ch;
		switch(ch)
		{
			case 1:
				cout<<"How many student?:";
				cin>>n;
				for(i=0;i<n;i++)
				{
					cout<<"Enter student details:\n";
					r[i].getdetails();
					r[i].getmarks();
					r[i].getpractical();
				}
				break;
			case 2:
				for(i=0;i<n;i++)
					r[i].calc();
					
				break;
			case 3:
				for(i=0;i<n;i++)
				{
					for(j=i+1;j<n;j++)
						r[i].sort(r[i],r[j]);
					r[i].display();
				}
					
				break;
			case 4:
				exit(0);
		}
	}while(ch<=3);
	
	return 0;
}