0% found this document useful (0 votes)
12 views2 pages

GP

The document contains a C++ program that defines two classes: Item and User. The Item class allows for input and display of item details, including a price, while the User class calculates the total bill for two items. The main function creates instances of both classes, gathers item data, displays it, and computes the total bill.

Uploaded by

sahilekal204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

GP

The document contains a C++ program that defines two classes: Item and User. The Item class allows for input and display of item details, including a price, while the User class calculates the total bill for two items. The main function creates instances of both classes, gathers item data, displays it, and computes the total bill.

Uploaded by

sahilekal204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

using namespace std;

class Item
{
private:
int Sr_No;
char iname[20];
int price;

public:
void input()
{
cout << "Enter Item Id: ";
cin >> Sr_No;
cout << "Enter Item Name: ";
cin >> iname;
cout << "Enter Item Price: ";
cin >> price;
}

void display()
{
cout << Sr_No << " " << iname << " " << price << endl;
}

int getPrice() // Getter function to access private price variable


{
return price;
}
};

class User
{
private:
int bill;

public:
User() : bill(0) {} // Initialize bill to 0

void getdata(Item& i1, Item& i2)


{
bill = i1.getPrice() + i2.getPrice(); // Sum prices of both items
cout << "Total bill: " << bill << endl;
}
};

int main()
{
Item i1, i2;
User u;

i1.input();
i2.input();

cout << "-------------------------------------" << endl;


cout << "Sr.No" << " " << "Item Name" << " " << "Price" << endl;
cout << "-------------------------------------" << endl;
i1.display();
i2.display();
cout << "-------------------------------------" << endl;

u.getdata(i1, i2); // Passing both items to calculate the total bill

return 0;
}

You might also like