Headlines
Loading...
C++ PROGRAM  for hybrid inheritance(without using virtual function)

C++ PROGRAM for hybrid inheritance(without using virtual function)

 /* Program for hybrid inheritance(without using virtual function) */


#include<iostream.h>

#include<conio.h>

#include<string.h>

class publication

{

  private:

char title[15];

float price;

 public:

void getdata()

{

cout<<"\nEnter title:";

cin>>title;

cout<<"\nEnter price:";

cin>>price;

}

void putdata()

{

cout<<"\ntitle:"<<title;

cout<<"\nPrice:"<<price;

}

};

class book : public publication

{

private:

int pages;

public:

void getdata()

{

publication::getdata();

cout<<"\nEnter number of pages:";

cin>>pages;

}

void putdata()

{

publication::putdata();

cout<<"\npages:"<<pages;

}

};

class sales

{

private:

enum{months=3};

float salesarr[months];

public:

void getdata();

void putdata();

};

void sales::getdata()

{

cout<<"\nEnter sales for 3 months\n";

for(int j=0;j<months;j++)

{

cout<<"     Month"<<j+1<<":";

cin>>salesarr[j];

 }

}

void sales::putdata()

{

for(int j=0;j<months;j++)

{

cout<<"\nSales for Month"<<j+1<<":";

cout<<salesarr[j];

 }

}

class tape:public book,public sales

{

private:

char author[50];

public:

void getdata()

{

    book::getdata();

   // publication::getdata();

    cout<<"\nEnter author name:";

    cin>>author;

    sales::getdata();

}

void putdata()

{

book::putdata();

       // publication::putdata();

cout<<"\n Author name:"<<author;

sales::putdata();

}

};

void main()

{

clrscr();

tape t;

t.getdata();

t.putdata();

cout<<endl;

getch();

}


/*Output*/


/* Enter title:JAVA


Enter price:250


Enter number of pages:300


Enter author name:SAM


Enter sales for 3 months

     Month1:30

     Month2:60

     Month3:80


title:MasteringC++

Price:250

pages:300

 Author name:SAM

Sales for Month1:30

Sales for Month2:60

Sales for Month3:80 */




*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***