Headlines
Loading...
C++ PROGRAM  Constructors in multiple inheritance

C++ PROGRAM Constructors in multiple inheritance

 //Constructors in multiple inheritance

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

#include<string.h>

class item

{

 private:

   char title[20];

   float price;

 public:

   item()

   {

    strnset(title,0,20);

    price=0;

   }

   item(char *t,float p)

   {

    strcpy(title,t);

    price=p;

   }

   void getdata()

   {

    cout<<"\nEnter title and price";

    cin>>title>>price;

   }

   void displaydata()

   {

    cout<<endl<<"\n\nTitle and price: ";

    cout<<title<<"\t"<<price;

   }

};

 class sales

 {

  private:

   float salesfig[3];

  public:

   sales()

   {

    for(int i=0;i<3;i++)

     salesfig[i]=0;

   }

  sales(float a,float b,float c)

  {

   salesfig[0]=a;

   salesfig[1]=b;

   salesfig[2]=c;

  }

  void getdata()

  {

   cout<<"\nEnter sales figures for 3 months: ";

   for(int i=0;i<3;i++)

     cin>>salesfig[i];

  }

  void displaydata()

  {

   cout<<endl<<"Sales figures for 3 months: ";

   for(int i=0;i<3;i++)

     cout<<salesfig[i]<<"\t";

  }

 };

 class hwitem:private item,private sales

 {

  private:

   char category[10];

   char oem[10];

  public:

   hwitem():item(),sales()

   {

    strnset(category,0,10);

    strnset(oem,0,10);

   }

   hwitem(float a,float b,float c,char *t,float p,char *cat,char *o):item(t,p),sales(a,b,c)

   {

    strcpy(category,cat);

    strcpy(oem,o);

   }

   void getdata()

   {

    item::getdata();

    cout<<endl<<"Enter category and oem:";

    cin>>category>>oem;

    sales::getdata();

    }

   void displaydata()

   {

    item::displaydata();

    cout<<endl<<"Category and oem: ";

    cout<<category<<"\t"<<oem;

    sales::displaydata();

   }

 };

 void main()

 {

  hwitem h1;

  hwitem h2(50000.00,125000.00,17000.00,"IBM PC/AT",25000,"FG","IBM");

  clrscr();

  h1.displaydata();

  h2.displaydata();

  getch();

 }

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