Create a base class Student(Roll_No, Name) which derives two classes Academic_Marks(Mark1, Mark2, Mark3) and Extra_Activities_Marks(Marks). Class Result(Total_Marks, Grade) inherits both Academic_Marks and Extra_Activities_Marks classes. (Use Virtual Base Class) Write a C++ menu driven program to perform the following functions: i. Build a master table ii. Calculate Total_marks and grade

//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;

#include<conio.h>
#include<iostream.h>
class stu
{
   public:
   int rno;
   char name[10]; //name=student name , rno= roll no
   void accept()
   {
      cout<<"Enter Roll no: ";
      cin>>rno;
      cout<<"\nEnter student name: ";
      cin>>name;
   }
};
class ac: public stu // inherit class  ac 
{
   protected:
   int m1,m2,m3; //m1=marks1 , m2=marks2 , m3=marks3 
   public:
   void acc()
   {
      cout<<"Enter marks in 1 subject: ";
      cin>>m1;
      cout<<"Enter marks in 2 subject: ";
      cin>>m2;
      cout<<"Enter marks in 3 subject: ";
      cin>>m3;
   }
};
class ec: public ac // inherit class ec 
{
   protected:
   int m4; //m4=marks4
   public:
   void acce()
   {
    cout<<"Enter extra curricular activities: ";
        cin>>m4;
   }

};
class result: public ec // inherit class result 
{
   public:
   int m;
   void cal()
   {
   m=m1+m2+m3+m4; //calculating marks
   cout<<"Total Marks: "<<m<<endl<<"Grade      : ";
   if(m>75)
       cout<<"A grade"<<endl;
   else if(m>65)
       cout<<"B grade"<<endl;
   else if(m>45)
       cout<<"C grade"<<endl;
   else if(m>35)
       cout<<"pass"<<endl;
   else if(m>0)
       cout<<"Fail"<<endl;
   }
};
void main()
{
int ch;
   result s1; //instance of class result

   cout<<endl;
   do
   {
      cout<<"\n1.build a report"<<endl;
      cout<<"2.calculate marks and grade: "<<endl;
      cout<<"3.Exit: "<<endl;
      cout<<"\nchoose one: ";
  cin>>ch;
  cout<<endl;
   switch(ch)
   {

    case 1:
             s1.accept();
             s1.acc();
             s1.acce();break;
         case 2:
             s1.cal(); break;
   }

   }while(ch!=3);
}

0 Comments