c++ programming

Write a c++ program to implement method overriding

#include<iostream> using namespace std;  class base { public: void virtual show() { cout<<“baseclass”; } }; class derived:public base { public: void show() { cout<<“derived class”; } }; int main() { base *b; derived d; b=&d; b->show(); return(0); } Output: Derived class

Write a c++ program to implement virtual inheritence

#include<iostream> using namespace std;      class student      {       protected:       int roll_no;       public:       void get_no(int x);       void put_no();      };      void student::get_no(int x)      {       roll_no=x;      } void student::put_no()      {       cout<<“the roll is\n”<<roll_no<<“\n”;      }      class test:public virtual student      {       protected:       float marks1,marks2;       public: void get_marks(float a,float b); void put_marks(); …

Write a c++ program to implement virtual inheritence Read More »

Write a c++ program to implement multilevel inheritance

#include<iostream> using namespace std;  class student  {   protected:   int rollno;   public:   void get_number(int n);   void show_number (); };  void student::get_number(int n)  {   rollno=n;  }  void student::show_number()  {         cout<<“\n the roll number \n”<<rollno;  } class test:public student { protected:           float sub1;         …

Write a c++ program to implement multilevel inheritance Read More »

Write a c++ program to implement single inheritance

#include<iostream> using namespace std; class B { int a; public: int b;         void get_ab(); int get_a(); void show_a(void); }; class D:private B { int c; public: void mul(void); void display(void); }; void B:: get_ab() { cout<<“Enter the value of a\n”; cin>>a; cout<<“Enter the value of b\n”;               cin>>b; } int  B::get_a() {  return a; void B::show_a(void) …

Write a c++ program to implement single inheritance Read More »