#include<iostream.h> #include<conio.h> class student { protected: int rno; public: void getno(){cout<<"\n\n Roll no.: ";cin>>rno;} void putno(){cout<<"\n Roll no.:"<<rno;} }; class test : virtual public student { protected : int m1,m2; public: void getmark(){cout<<"Marks of 2 subjects : ";cin>>m1>>m2;} void putmark(){cout<<"\nMarks of 2 subjects : "<<m1<<","<<m2;} }; class sports : virtual public student { protected: int score; public: void getscore(){cout<<" Sports mark : ";cin>>score;} void putscore(){cout<<"\n Sports mark : "<<score;} }; class result:public test,public sports { int total; public: void display(){total=m1+m2+score;putno();putmark();putscore(); cout<<"\n Total Marks : "<<total;} }; void main() { result r[10]; int n,i; clrscr(); cout<<"\n Enter no: of students : "; cin>>n; clrscr(); cout<<"\n\n Enter details of student\n"; for(i=1;i<=n;i++) { cout<<"\n Enter details of student : "<<i; r[i].getno(); r[i].getmark(); r[i].getscore(); } clrscr(); cout<<"\n Details of student\n\n"; for(i=1;i<=n;i++) { cout<<"\n\n---------------------------------------------"; cout<<"\n Details of student : "<<i<<endl; r[i].display(); cout<<"\n\n---------------------------------------------"; } getch(); }
Create a virtual base class student that stores rollno with member functions getno( ) and putno( ). From this derive a class test with data members mark1 and mark2 and member functions getmarks( ) and putmarks( ) and derive another class sports with data member score and member functions getscore( ) and putscore( ). From test and sports classes derive the class result that stores total mark. Write a CPP program to test the classes.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment