Jaluh is making a room inventory in the Hostel where she is working. They have 16 rooms
labelled as A-P. She is doing this manually that it will consume more time. Make a program
that will automatically be identified if the room is taken or not. An array code.. ANYONE COULD HELP ME THIS GUYS.
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
We'd be happy to help if you had some code to show us, so we could give pointers for it. Solving your homework for you isn't helping.
toneewa 81 Junior Poster in Training
Here is a working program that'll keep track of your rooms A-P. It reads a text file and it saves changes as you make changes as "book" or open.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int menu();
void readrooms();
int status_update();
int choice();
int main()
{
menu();
status_update();
return 0;
}
int choice()
{
int choice = 0;
std::cout << "\n";
std::cout << " Hostel " << std::endl;
std::cout << "*******************" << std::endl;
std::cout << "1) Room Status" << std::endl;
std::cout << "2) Change Room Status" << std::endl;
std::cout << "> ";
std::cin >> choice;
if (choice == 1)
{
readrooms();
}
if (choice == 2)
{
status_update();
}
if (choice != 1 && choice != 2)
{
choice = 0;
menu();
}
return 0;
}
int menu()
{
choice();
return 0;
}
void readrooms() {
std::cout << "\n";
std::cout << "*****************************************************" << std::endl;
std::cout << "* * " << std::endl;
std::cout << "* Room Status * " << std::endl;
std::cout << "* *" << std::endl;
std::cout << "*****************************************************" << std::endl;
cout << " Room " << "\t\t" << "Room #" << "\t\t" << "Flag" << "\t\t" << "Status" << std::endl;
const int quantity = 16;
int ID[quantity]{};
string RoomName[quantity];
int RoomNumber[quantity]{};
int RoomStatus[quantity]{};
int i = 0;
int a = 0;
int t = 0;
string available = "open";
string taken = "booked";
string status = "";
ifstream infile;
infile.open("rooms2.txt");
ofstream replace_room("rooms.txt");
while (i < quantity)
{
while (infile.good())
{
while (infile >> RoomName[i] >> RoomNumber[i] >> RoomStatus[i]) {
if (RoomStatus[i] == 1){
status = taken;
t = t + 1;
}
if (RoomStatus[i] == 0) {
status = available;
a = a + 1;
}
std::cout << RoomName[i] << "\t\t" << RoomNumber[i] << "\t\t" << RoomStatus[i] << "\t\t" << status << endl;
replace_room << RoomName[i] << " " << RoomNumber[i] << " " << RoomStatus[i] << " " << endl;
i++;
}
}
}
std::cout << "" << std::endl;
std::cout << "Rooms Available: " << a << std::endl;
std::cout << "Rooms Booked: " << t << std::endl;
infile.close();
replace_room.close();
menu();
exit(0);
}
int status_update()
{
char room = ' ';
string rooms = " ";
int up = 0;
int low = 0;
std::cout << "\n";
std::cout << " Enter room to change (lowercase): ";
std::cin >> room;
std::cout << "\n";
int r_status = 0;
std::cout << " Status of room: " << (char)toupper(room) << std::endl;
std::cout << " Enter status (1 = booked || 0 = open): ";
std::cin >> r_status;
const int quantity = 16;
int ID[quantity]{};
string RoomName[quantity];
int RoomNumber[quantity]{};
int RoomStatus[quantity]{};
int line = 0;
int acount = 0;
int t = 0;
string available = "open";
string taken = "booked";
string status = "";
ifstream infile;
infile.open("rooms.txt");
ofstream replace_room("rooms2.txt");
while (line < quantity)
{
while (infile.good())
{
while (infile >> RoomName[line] >> RoomNumber[line] >> RoomStatus[line]) {
if(room =='a')
RoomStatus[0] = r_status;
if (room == 'b')
RoomStatus[1] = r_status;
if (room == 'c')
RoomStatus[2] = r_status;
if (room == 'd')
RoomStatus[3] = r_status;
if (room == 'e')
RoomStatus[4] = r_status;
if (room == 'f')
RoomStatus[5] = r_status;
if (room == 'g')
RoomStatus[6] = r_status;
if (room == 'h')
RoomStatus[7] = r_status;
if (room == 'i')
RoomStatus[8] = r_status;
if (room == 'j')
RoomStatus[9] = r_status;
if (room == 'k')
RoomStatus[10] = r_status;
if (room == 'l')
RoomStatus[11] = r_status;
if (room == 'm')
RoomStatus[12] = r_status;
if (room == 'n')
RoomStatus[13] = r_status;
if (room == 'o')
RoomStatus[14] = r_status;
if (room == 'p')
RoomStatus[15] = r_status;
if (RoomStatus[line] == 1) {
status = taken;
t = t + 1;
}
if (RoomStatus[line] == 0) {
status = available;
acount = acount + 1;
}
replace_room << RoomName[line] <<" " << RoomNumber[line] << " " << RoomStatus[line] << std::endl;
line++;
}
}
}
std::cout << "" << std::endl;
infile.close();
replace_room.close();
readrooms(); // save
menu();
return 0;
}
Hostel
*******************
1) Room Status
2) Change Room Status
> 1
*****************************************************
* *
* Room Status *
* *
*****************************************************
Room Room # Flag Status
A 1 0 open
B 2 0 open
C 3 1 booked
D 4 0 open
E 5 1 booked
F 6 0 open
G 7 1 booked
H 8 0 open
I 9 1 booked
J 10 0 open
K 11 1 booked
L 12 0 open
M 13 1 booked
N 14 0 open
O 15 1 booked
P 16 1 booked
Rooms Available: 8
Rooms Booked: 8
Hostel
*******************
1) Room Status
2) Change Room Status
> 2
Enter room to change (lowercase): a
Status of room: A
Enter status (1 = booked || 0 = open): 1
*****************************************************
* *
* Room Status *
* *
*****************************************************
Room Room # Flag Status
A 1 1 booked
B 2 0 open
C 3 1 booked
D 4 0 open
E 5 1 booked
F 6 0 open
G 7 1 booked
H 8 0 open
I 9 1 booked
J 10 0 open
K 11 1 booked
L 12 0 open
M 13 1 booked
N 14 0 open
O 15 1 booked
P 16 1 booked
Rooms Available: 7
Rooms Booked: 9
Hostel
*******************
1) Room Status
2) Change Room Status
>
//rooms.txt
A 1 1
B 2 0
C 3 1
D 4 0
E 5 1
F 6 0
G 7 1
H 8 0
I 9 1
J 10 0
K 11 1
L 12 0
M 13 1
N 14 0
O 15 1
P 16 1
Edited by Dani because: Shouldn't have been deleted
toneewa 81 Junior Poster in Training
This will help you keep track of your rooms A-P, it saves changes to a file and updates as you go, reading from the file.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int menu();
void readrooms();
int status_update();
int choice();
int main()
{
menu();
status_update();
return 0;
}
int choice()
{
int choice = 0;
std::cout << "\n";
std::cout << " Hostel " << std::endl;
std::cout << "*******************" << std::endl;
std::cout << "1) Room Status" << std::endl;
std::cout << "2) Change Room Status" << std::endl;
std::cout << "> ";
std::cin >> choice;
if (choice == 1)
{
readrooms();
}
if (choice == 2)
{
status_update();
}
if (choice != 1 && choice != 2)
{
choice = 0;
menu();
}
return 0;
}
int menu()
{
choice();
return 0;
}
void readrooms() {
std::cout << "\n";
std::cout << "*****************************************************" << std::endl;
std::cout << "* * " << std::endl;
std::cout << "* Room Status * " << std::endl;
std::cout << "* *" << std::endl;
std::cout << "*****************************************************" << std::endl;
cout << " Room " << "\t\t" << "Room #" << "\t\t" << "Flag" << "\t\t" << "Status" << std::endl;
const int quantity = 16;
int ID[quantity]{};
string RoomName[quantity];
int RoomNumber[quantity]{};
int RoomStatus[quantity]{};
int i = 0;
int a = 0;
int t = 0;
string available = "open";
string taken = "booked";
string status = "";
ifstream infile;
infile.open("rooms2.txt");
ofstream replace_room("rooms.txt");
while (i < quantity)
{
while (infile.good())
{
while (infile >> RoomName[i] >> RoomNumber[i] >> RoomStatus[i]) {
if (RoomStatus[i] == 1){
status = taken;
t = t + 1;
}
if (RoomStatus[i] == 0) {
status = available;
a = a + 1;
}
std::cout << RoomName[i] << "\t\t" << RoomNumber[i] << "\t\t" << RoomStatus[i] << "\t\t" << status << endl;
replace_room << RoomName[i] << " " << RoomNumber[i] << " " << RoomStatus[i] << " " << endl;
i++;
}
}
}
std::cout << "" << std::endl;
std::cout << "Rooms Available: " << a << std::endl;
std::cout << "Rooms Booked: " << t << std::endl;
infile.close();
replace_room.close();
menu();
exit(0);
}
int status_update()
{
char room = ' ';
string rooms = " ";
int up = 0;
int low = 0;
std::cout << "\n";
std::cout << " Enter room to change (lowercase): ";
std::cin >> room;
std::cout << "\n";
int r_status = 0;
std::cout << " Status of room: " << (char)toupper(room) << std::endl;
std::cout << " Enter status (1 = booked || 0 = open): ";
std::cin >> r_status;
const int quantity = 16;
int ID[quantity]{};
string RoomName[quantity];
int RoomNumber[quantity]{};
int RoomStatus[quantity]{};
int line = 0;
int acount = 0;
int t = 0;
string available = "open";
string taken = "booked";
string status = "";
ifstream infile;
infile.open("rooms.txt");
ofstream replace_room("rooms2.txt");
while (line < quantity)
{
while (infile.good())
{
while (infile >> RoomName[line] >> RoomNumber[line] >> RoomStatus[line]) {
if(room =='a')
RoomStatus[0] = r_status;
if (room == 'b')
RoomStatus[1] = r_status;
if (room == 'c')
RoomStatus[2] = r_status;
if (room == 'd')
RoomStatus[3] = r_status;
if (room == 'e')
RoomStatus[4] = r_status;
if (room == 'f')
RoomStatus[5] = r_status;
if (room == 'g')
RoomStatus[6] = r_status;
if (room == 'h')
RoomStatus[7] = r_status;
if (room == 'i')
RoomStatus[8] = r_status;
if (room == 'j')
RoomStatus[9] = r_status;
if (room == 'k')
RoomStatus[10] = r_status;
if (room == 'l')
RoomStatus[11] = r_status;
if (room == 'm')
RoomStatus[12] = r_status;
if (room == 'n')
RoomStatus[13] = r_status;
if (room == 'o')
RoomStatus[14] = r_status;
if (room == 'p')
RoomStatus[15] = r_status;
if (RoomStatus[line] == 1) {
status = taken;
t = t + 1;
}
if (RoomStatus[line] == 0) {
status = available;
acount = acount + 1;
}
replace_room << RoomName[line] <<" " << RoomNumber[line] << " " << RoomStatus[line] << std::endl;
line++;
}
}
}
std::cout << "" << std::endl;
infile.close();
replace_room.close();
readrooms(); // save
menu();
return 0;
}
Hostel
*******************
1) Room Status
2) Change Room Status
> 1
*****************************************************
* *
* Room Status *
* *
*****************************************************
Room Room # Flag Status
A 1 1 booked
B 2 0 open
C 3 1 booked
D 4 0 open
E 5 1 booked
F 6 0 open
G 7 1 booked
H 8 0 open
I 9 1 booked
J 10 0 open
K 11 1 booked
L 12 0 open
M 13 1 booked
N 14 0 open
O 15 1 booked
P 16 1 booked
Rooms Available: 7
Rooms Booked: 9
Hostel
*******************
1) Room Status
2) Change Room Status
> 2
Enter room to change (lowercase): b
Status of room: B
Enter status (1 = booked || 0 = open): 1
*****************************************************
* *
* Room Status *
* *
*****************************************************
Room Room # Flag Status
A 1 1 booked
B 2 1 booked
C 3 1 booked
D 4 0 open
E 5 1 booked
F 6 0 open
G 7 1 booked
H 8 0 open
I 9 1 booked
J 10 0 open
K 11 1 booked
L 12 0 open
M 13 1 booked
N 14 0 open
O 15 1 booked
P 16 1 booked
Rooms Available: 6
Rooms Booked: 10
Hostel
*******************
1) Room Status
2) Change Room Status
>
A 1 1
B 2 1
C 3 0
D 4 0
E 5 0
F 6 1
G 7 1
H 8 0
I 9 0
J 10 0
K 11 0
L 12 0
M 13 0
N 14 0
O 15 0
P 16 0
Edited by Dani because: Shouldn't have been deleted
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
You really should learn how to use arrays and maps before posting any more repetitive code (eg 147-178).
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
@Toneewa: please stop answering questions which don't show the OP's own code - DaniWeb is not a free homework solving service. And yes, I know I'd made the same mistake in the past myself, but when this was pointed out to me I stopped doing so.
Also, please pay more attention to the dates of original posts. After more than a month, it is safe to say that the assignment has passed.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.