Advertisement
pranto_95

Untitled

Oct 27th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.70 KB | None | 0 0
  1. //Write a object oriented programming wahere we have a measure the average marks of three subject of a second semester steudent.you have to take four input as your name and three marks of three different subjects,the result will be calculate in four different classes by taking four different marks for esach classs for these three subject.now u wll show the reslt from the second and last derived class only.using inheritance and virtual functon
  2. #include<iostream>
  3. using namespace std;
  4.                                             class Result1{
  5.                                             protected:
  6.                                             float marks1,marks2,marks3;
  7.                                             string name;
  8.                                             public:
  9.                                             void res(){
  10.                                             cout<<"Enter name"<<endl;
  11.                                             cin>>name;
  12.                                             cout<<"Enter marks";
  13.                                             cin>>marks1>>marks2>>marks3;
  14.                                             float avg;
  15.                                             avg=(marks1+marks2+marks3)/3.0;
  16.                                              cout<<"average is :"<<avg<<endl;
  17.                                                 }
  18.                                         };
  19.  
  20.                                             class Result2:public Result1{
  21.                                             protected:
  22.                                             float marks4,marks5,marks6;
  23.  
  24.                                             string name1;
  25.                                             public:
  26.                                                 void res(){
  27.  
  28.                                             cout<<"Enter name";
  29.                                             cin>>name1;
  30.                                             cout<<"Enter numbers";
  31.                                             cin>>marks4>>marks5>>marks6;
  32.                                             float avg;
  33.  
  34.                                             avg=(marks4+marks5+marks6)/3.0;
  35.  
  36.  
  37.                                                 cout<<"average is :"<<avg<<endl;
  38.                                                 }
  39.  
  40.  
  41.  
  42.                                         };
  43.                                         class Result3:public Result1{
  44.                                             protected:
  45.                                             float marks10,marks11,marks12;
  46.                                             float avg;
  47.                                             string name;
  48.                                             public:
  49.                                                virtual void res(){
  50.  
  51.                                             cout<<"Enter name";
  52.                                             cin>>name;
  53.                                             cout<<"Enter numbers";
  54.                                             cin>>marks10>>marks11>>marks12;
  55.                                             float avg;
  56.  
  57.                                             avg=(marks10+marks11+marks12)/3.0;
  58.  
  59.  
  60.                                                cout<<"average is :"<<avg<<endl;
  61.                                         }
  62.  
  63.  
  64.  
  65.                                         };
  66.                                          class Result4:public Result3{
  67.                                             protected:
  68.                                             float marks7,marks8,marks9;
  69.  
  70.                                             string name;
  71.                                             public:
  72.                                                 void res(){
  73.  
  74.                                             cout<<"Enter name";
  75.                                             cin>>name;
  76.                                             cout<<"Enter numbers";
  77.                                             cin>>marks7>>marks8>>marks9;
  78.                                            float avg;
  79.                                             avg=(marks7+marks8+marks9)/3.0;
  80.  
  81.                                             cout<<"average is :"<<avg<<endl;
  82.                                          }
  83.  
  84.  
  85.  
  86.                                         };
  87.                                         int main(){
  88.                                         Result1 *R;
  89.                                         Result2 s;
  90.                                         Result4 t;
  91.                                         R=&s;
  92.                                         R->res();
  93.                                         R=&t;
  94.                                         R->res();
  95.                                         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement