Write a program to create a student report using inheritance technique.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class student
{
    protected:
       char name[20];
       int reg;
    public:
       void getdata()
       {
      cout<<"\nType Register No:";
      cin>>reg;
      cout<<"\nType Name:";
      cin>>name;
       }
       void showdata()
       {
      cout<<setprecision(2);
      cout.setf(ios::left,ios::adjustfield);
      cout<<"\nRoll No         :"<<setw(3)<<reg;
      cout<<"\nName            :"<<setw(10)<<name;
       }
};
class marks : public student
{
   protected:
       int m1,m2,m3;
       float perc;
   public:
       void getmarks()
       {
      cout<<"\nMarks in C++ , Maths , DBMS:";
      cin>>m1>>m2>>m3;
      perc=(m1+m2+m3)/300.00*100;
       }
       void showmarks()
       {
      cout<<"\nC++             :"<<setw(5)<<m1;
      cout<<"\nMaths           :"<<setw(5)<<m2;
      cout<<"\nDBMS            :"<<setw(5)<<m3;
      cout<<"\nPercent         :"<<setw(5)<<perc;
       }
};
class result : public marks
{
    private:
       char grade;
    public:
       void display()
       {
      showdata();
      showmarks();
      cout<<"\nGrade           :"<<setw(10)<<getgrade()<<endl;
       }
    char getgrade()
    {
       if(m1<40||m2<40||m3<40)
    grade='F';
      else if(perc>=75)
        grade='A';
          else if(perc>=60)
         grade='B';
           else if(perc>=50)
              grade='C';
               else if(perc>=40)
             grade='D';
             else
             grade='F';
    return grade;
      }
};
void main()
{
   clrscr();
   result std;
   cout<<"\nGrades: A-> 75% and above "<<endl;
   cout<<"                  B->60-74"<<endl;
   cout<<"                  C->50-59"<<endl;
   cout<<"                  D->40-49"<<endl;
   cout<<"                  F->Below 40"<<endl;
   std.getdata();
   std.getmarks();
   std.display();
   getch();
}

No comments:

Post a Comment