c++ programs examples

C++ Program to inherit a class SALES from the class CUSTOMER and ITEM with related fields in a Departmental store

c++ programs examples

/* 7. Write a program to inherit a class SALES from the class CUSTOMER and

       ITEM with related fields in a departmental store. */

 #include<iostream.h>

 #include<conio.h>

 #include<string.h>

 class customer

 {

  protected:

   int cus_id;

   char cus_name[20];

   static int no;

  public:

   customer()

   {

    cus_id=0;

    strcpy(cus_name,” “);

    }

   void input()

   {

    cout<<“Enter customer Id=”<<endl;

    cin>>cus_id;

    cout<<“Enter customer Name=”<<endl;

    cin>>cus_name;

    }

   void display()

   {

    cout<<“Customer Id=”<<cus_id<<endl;

    cout<<“Customer Name=”<<cus_name<<endl;

    }

  };

 class item

 {

  protected:

   int item_no;

   float price;

  public:

   item()

   {

    item_no=0;

    price=0;

    }

   void input()

   {

    cout<<“Enter Item No=”<<endl;

    cin>>item_no;

    cout<<“Enter price=”<<endl;

    cin>>price;

    }

   void display()

   {

    cout<<“Item No=”<<item_no<<endl;

    cout<<“Price=”<<price<<endl;

    }

 };

 class sales:protected customer,protected item

 {

  private:

   int no_of_item;

   float total;

  public:

   sales()

   {

    no_of_item=0;

    total=0;

    }

   void input()

   {

    customer::input();

    item::input();

    cout<<“Enter no of item sold=”<<endl;

    cin>>no_of_item;

    total=no_of_item*price;

    clrscr();

    }

   void display()

   {

    cout<<“\n\t*********** Invoice No: “<<++no<<” “<<“***********\n\n”;

    customer::display();

    item::display();

    cout<<“No of item sold=”<<no_of_item<<endl;

    cout<<“Total Amount=”<<total;

    }

};

int customer::no=0;

void main()

{

 clrscr();

 sales *a;

 int vc,i;

 cout<<“Enter no of vouchers to be print”<<endl;

 cin>>vc;

 a=new sales[vc];

 for(i=0;i<vc;i++)

 {

 a->input();

 a++;

 }

 a=a-i;

 for(i=0;i<vc;i++)

 {

 a->display();

 a++;

 }

 getch();

 }

Leave a Reply

Your email address will not be published. Required fields are marked *