single level inheritance exampleA derived class with one base class is called single level inheritance. Block diagram given below shows the single level inheritance.
#include<iostream.h>#include<conio.h>class student{ private: int enroll;char name[20];char course[20]; public: void input_stud();void display_stud();};void student::input_stud(){cout<<"enter enroll:";cin>>enroll;cout<<"enter name:";cin>>name;cout<<"enter subject:";cin>>course;
}void student::display_stud(){cout<<"enroll is:"<<enroll;cout<<"\nname is:"<<name;cout<<"\ncourse is:"<<course;}class exam:public student{ private: int msub1;int msub2;int msub3; public: void input_exam(); void display_exam();};void exam::input_exam(){cout<<"enter marks of subject1:";cin>>msub1;cout<<"enter marks of subject2:";cin>>msub2;cout<<"enter marks of subject3:";cin>>msub3;}void exam::display_exam(){cout<<"\nmarks in subject1 is:"<<msub1;cout<<"\nmarks in subject2 is:"<<msub2;cout<<"\nmarks in subject3 is:"<<msub3; }void main(){ clrscr();exam e1;e1.input_stud();e1.input_exam();e1.display_stud();e1.display_exam();getch();}
Hybrid InheritanceMultiple inheritanceQuestion answer
C++ Multiple Inheritance
#include<iostream.h>#include<conio.h>class student{ private: int enroll;char name[20];char course[20]; public: void input_stud();void display_stud();};void student::input_stud(){cout<<"enter enroll:";cin>>enroll;cout<<"enter name:";cin>>name;cout<<"enter subject:";cin>>course;
}void student::display_stud(){cout<<"enroll is:"<<enroll;cout<<"\nname is:"<<name;cout<<"\ncourse is:"<<course;}class exam:public student{ private: int msub1;int msub2;int msub3; public: void input_exam(); void display_exam();};void exam::input_exam(){cout<<"enter marks of subject1:";cin>>msub1;cout<<"enter marks of subject2:";cin>>msub2;cout<<"enter marks of subject3:";cin>>msub3;}void exam::display_exam(){cout<<"\nmarks in subject1 is:"<<msub1;cout<<"\nmarks in subject2 is:"<<msub2;cout<<"\nmarks in subject3 is:"<<msub3; }void main(){ clrscr();exam e1;e1.input_stud();e1.input_exam();e1.display_stud();e1.display_exam();getch();}
Hybrid InheritanceMultiple inheritanceQuestion answer
C++ Multiple Inheritance
View more documents from harshaltambe
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | inheritance in c++ with example ppt
View more PowerPoint from cprogrammings
No comments:
Post a Comment