Wednesday, 1 April 2015

U5P7

Create a class student that stores roll_no,name. Create a class test that stores marks obtained in five subjects. Class result derived from student and test contains the total marks and percentage obtained in test. Input and display information of a student.

 #include<iostream.h>  
 #include<conio.h>  
 class student  
 {  
      public:  
      char name[10];  
      int roll;  
      void get_basic()  
      {  
           cout<<"Enter name of the Student : ";  
           cin>>name;  
           cout<<"Enter Roll Number of "<<name<<" : ";  
           cin>>roll;  
      }  
 };  
   
 class test  
 {  
      public:  
      int marks[5];  
      void get_marks()  
      {  
           cout<<"\nEnter marks of 5 Subjects(Out of 100): "<<endl;  
           for(int i=0;i<5;i++)  
           {  
                cout<<"Marks of Subject "<<i+1<<" : ";  
                cin>>marks[i];  
           }  
      }  
   
 };  
   
 class result : public student, public test  
 {  
      float total;  
      public:  
      float get_total()  
      {  
           for(int i=0;i<5;i++)  
           {  
                total = total + marks[i];  
           }  
           return total;  
      }  
      float get_perc()  
      {  
           return total/5;  
      }  
   
   
 };  
   
 void main()  
 {  
      clrscr();  
      result obj1;  
      obj1.get_basic();  
      obj1.get_marks();  
      cout<<"\n=========================";  
      cout<<"\nRoll No  : "<<obj1.roll;  
      cout<<"\nName    : "<<obj1.name;  
      cout<<"\nTotal   : "<<obj1.get_total()<<"/500";  
      cout<<"\nPercentage : "<<obj1.get_perc()<<" %";  
      cout<<"\n=========================";  
      getch();  
 }  

Output :

No comments:

Post a Comment