Write a C++ program that will find out the total amountof a customer\'s bill acc
ID: 3618861 • Letter: W
Question
Write a C++ program that will find out the total amountof a customer's bill according to the items he or shehas purchased.
Create two classes:
Purchased_item,
Bill
The Purchased_item should be having the following datamembers
item_num //for itemnumber
note: item_num //should be static. This data memberwill be used to display the item number whose information iscurrently required from the user
price //for per unit price
quantity //for quantity purchased
class Bill should have two data members
total_amount //for the total amount of bill that is to be paid
items[5] //an array of purchased_item; should be 5 in size
class Bill should also have a member function that isused to calculate the total amount and assign it to the data member, total_amount
Your program should take input of the price and quantity of 5items and display the total amount after calculation.
OUTPUT
Your output should be similar to the following
enter price and purchased quantity of item 1
price:20
Quantity:5
enter price and purchased quantity of item 2
price:10
Quantity:2
enter price and purchased quantity of item 3
price:15
Quantity:1
enter price and purchased quantity of item 4
price:30
Quantity:2
enter price and purchased quantity of item 5
price:10
Quantity:2
Total amount to be paid is 215
Explanation / Answer
#include<iostream.h>
#include<conio.h>
class purchased_item
{
static int item_num;
int price;
public:
int quantity;
purchaed_item() //Default constructor
{
price=0;
quantity=0;
}
int get_data()
{
item_num++;
cout<<" Enter the Price and purchased quantity for item"<<item_num;
cout<<" price :";
cin>>price;
cout<<" quantity :";
cin>>quantity;
return price;
}
int get_quantity()
{
return quantity;
}
~purchased_item() //Destructor
{
}
};
int purchased_item::item_num=0;
class bill
{
int total_amount;
purchased_item items[5];
public:
void calculate_total_amount()
{
int sum=0;
for(int i=0;i<5;i++)
sum=sum+(items[i].get_data()*items[i].get_quantity()); //I have multiply the price with the number of items .
total_amount=sum;
}
void show()
{
cout<<" Total amount :"<<total_amount;
}
};
void main()
{
bill b;
b.calculate_total_amount();
b.show();
getche();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.