Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C++ The following table shows the number of customers staying in each room

ID: 3758088 • Letter: U

Question

Using C++

The following table shows the number of customers staying in each room on each of the floors in a hotel. Each floor has 5 rooms, but the number of floors isunknown. Each row represents a floor and the five numbers in each row represent the number of people staying in each of the five rooms.

1 2 4 4 3

2 3 3 1 4

2 2 1 1 3

2 3 2 2 1

Create the text file floors.txt with the numbers as shown in the table. Write a program that will read the file and display the total number of customers staying on each floor. The program output will look somewhat like this:

14 people stay on floor 1

13 people stay on floor 2

… and so on

Explanation / Answer

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream ipFile;
int x, i, floorSum = 0;
ipFile.open("floors.txt",ios::in);
int floorNum = 0;
while(!ipFile.eof())
{
floorNum++;
floorSum = 0;
for(i = 0; i < 5; i++)
{
ipFile>>x;
floorSum += x;
}
cout<<floorSum<<" people stay in floor "<<floorNum<<endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote