Expand|Select|Wrap|Line Numbers
- #include <iostream.h>
- #include <stdlib.h>
- class Purchased_item
- {
- private:
- static int itemno;
- int price;
- int quantity;
- public:
- Purchased_item() {
- this -> price = 0;
- this -> quantity = 0;
- }
- int getprice()
- {
- cout<<"Price: ";
- cin>>this -> price;
- return price;
- }
- int getquantity()
- {
- cout<<"Quantity: ";
- cin >>this -> quantity;
- return quantity;
- }
- static int items()
- {
- itemno++;
- return itemno;
- }
- };
- int Purchased_item::itemno = 0;
- class Bill
- {
- private:
- int total_amount;
- Purchased_item items[5];
- public:
- Bill()
- {
- this -> total_amount = 0;
- }
- void calculate()
- {
- for(int i=0; i<5; i++)
- {
- cout<<"\nEnter price and purchased quantity of item "<< items[i].items() <<endl;
- total_amount += items[i].getprice() * items[i].getquantity();
- }
- }
- void display()
- {
- cout<<"\nTotal amount to be paid is : "<<total_amount<<endl;
- }
- };
- void main()
- {
- Bill b;
- b.calculate();
- b.display();
- return 0;
- }