Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*input text file named guest.dat contains
- a list of guests' name, payment type(Master Card, or Visa or Cash);
- room charge per day and number of days stayed in a hotel. The data is for a specific month
- of the year as shown if Figure 1:
- Aiman Hakeem
- Master Card
- 250.0 7
- Tasmin Munirah
- Visa
- 210.0 10
- Ali Abdul
- Cash
- 150.0 3
- Anis Syifa
- Master Card
- 210.0 7
- Figure 1: The data written in guest.dat file
- The program will read data from the input text file and produce the report as shown
- in figure 2 on the output text file named report.dat.
- GUEST NAME PAYMENT TYPE TOTAL PRICE
- Aisman Hakeem Master Card RM 1575.0
- Tasnim Munirah Visa RM 1785.0
- Ali Abdul Cash RM 450.0
- Anis Syifa Master Card RM 1323.0
- The total monthly collection is : ---> RM 5133.0
- The number of hotel guests is: 4
- The number of Master Card users is: 2
- The number of Visa users is : 1
- Figure 2: The report produced on report.dat file
- The information printed includes guest's name, payment type, and total charge. The formulas are as follows:
- Total charge = room charge * number of days stated
- the discount of the total charge entitled for each guest will be given based on the following table:
- Number of days stayed Discount(%)
- 1 to 4 0
- 5 to 9 10
- more than 9 15
- Write a complete C++ program to calculate and produce the report as shown in Figure 2 above.
- */
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- char name[20];
- char paymentType[20];
- float charge;
- int days;
- int count=0,masterCard=0,visa=0;
- float total=0.0,discount,payment;
- ifstream inf("guest.dat");
- ofstream outf("report.dat");
- if (!inf)
- {
- cout << "Fail to open input file--> guest.dat" << endl;
- exit(1);
- }
- if (!outf)
- {
- cout << "Fail to open output file--> report.dat" << endl;
- exit(1);
- }
- outf << setiosflags(ios::left) << setw(20) << "GUEST NAME"
- << setw(20) << "PAYMENT TYPE"
- << "TOTAL PRICE" << endl;
- while (!inf.eof())
- {
- inf.getline(name,20);
- inf.getline(paymentType,20);
- inf >> charge;
- inf >> days;
- outf << setiosflags(ios::left) << setw(20) << name
- << setw(20) << paymentType;
- if (strcmp(paymentType,"Master Card")==0)
- masterCard+=1;
- else if (strcmp(paymentType,"Visa")==0)
- visa+=1;
- if (days>9)
- discount = 0.15;
- else if (days>=5&&days<=9)
- discount = 0.1;
- else
- discount =0.0;
- payment = (1-discount) * charge * days;
- total+=payment;
- outf << "RM "<< setiosflags(ios::fixed) << setprecision(1) << payment;
- outf << endl;
- count++;
- inf>>ws;
- }
- outf << endl;
- outf << "The number of hotel guests is: " << count << endl;
- outf << "The number of Master Card users is: "<< masterCard << endl;
- outf << "The number of Visa users is : " << visa << endl;
- inf.close();
- outf.close();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement