Here's a simple C++ program for hotel billing:
#include <iostream>
#include <string>
using namespace std;
class HotelBilling {
private:
string customerName;
int roomNumber;
int numberOfDays;
double roomRate;
double foodBill;
double totalBill;
public:
void inputDetails() {
cout << "Enter customer name: ";
getline(cin, customerName);
cout << "Enter room number: ";
cin >> roomNumber;
cout << "Enter number of days stayed: ";
cin >> numberOfDays;
cout << "Enter room rate per day: ";
cin >> roomRate;
cout << "Enter food bill: ";
cin >> foodBill;
}
void calculateBill() {
totalBill = (roomRate * numberOfDays) + foodBill;
}
void displayBill() {
cout << "\nHotel Bill\n";
cout << "Customer Name: " << customerName << endl;
cout << "Room Number: " << roomNumber << endl;
cout << "Number of Days Stayed: " << numberOfDays << endl;
cout << "Room Rate per Day: " << roomRate << endl;
cout << "Food Bill: " << foodBill << endl;
cout << "Total Bill: " << totalBill << endl;
}
};
int main() {
HotelBilling billing;
billing.inputDetails();
billing.calculateBill();
billing.displayBill();
return 0;
}
```
*Example Output:*
```
Enter customer name: John Doe
Enter room number: 101
Enter number of days stayed: 3
Enter room rate per day: 500
Enter food bill: 200
Hotel Bill
Customer Name: John Doe
Room Number: 101
Number of Days Stayed: 3
Room Rate per Day: 500
Food Bill: 200
Total Bill: 1700
This program defines a `HotelBilling` class with private member variables for customer details, room information, and billing data. The class includes public methods for inputting customer details, calculating the total bill, and displaying the hotel bill.
In the `main()` function, an instance of the `HotelBilling` class is created, and the program prompts the user to input customer details. The program then calculates the total bill and displays the hotel bill with the calculated total.
No comments:
Post a Comment