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

Amansic, Joshua John Y. Bscs Machine Problem002: Seat Reservation

The document describes a C++ program that models a seat reservation system using a 2D array. The program allows a user to input a seat number, reserves it by changing its value to 0, and provides feedback on the reservation status or errors. It continuously loops until the user enters 0 to exit. The full program code and specifications are provided.

Uploaded by

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

Amansic, Joshua John Y. Bscs Machine Problem002: Seat Reservation

The document describes a C++ program that models a seat reservation system using a 2D array. The program allows a user to input a seat number, reserves it by changing its value to 0, and provides feedback on the reservation status or errors. It continuously loops until the user enters 0 to exit. The full program code and specifications are provided.

Uploaded by

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

Amansic, Joshua John Y.

BSCS
Machine Problem002: Seat Reservation

Questions:(to be answered within the video)

Write a C++ program with the following specifications:


1. Use two-dimensional array with size 7 columns and 5 rows.
2. Seat numbers are populated during run-time.
3. User is asked to input a seat number.
4. Seat number chosen is replaced by 0.
5. Program displays a remark “Seat successfully reserved” when reservation is done.
6. User is not allowed to reserve a previously reserved seat. Display “Seat is taken” remarks.
7. User is not allowed to enter an invalid seat number. Display an error message.
8. Program continuously loops.

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include "_pause.h"

using namespace std;

int main() {
const int rows = 5, cols = 7;
int seats[rows][cols];
int seatChoice, getRow, getCol;
bool isValidInput;

for(int i = 0, n = 1; i < rows; i++){


for(int x = 0; x < cols; x++, n++){
seats[i][x] = n;
}
}

do{
for(int i = 0; i < rows; i++){
for(int x = 0; x < cols; x++){
cout << seats[i][x] << "\t";
}
cout << "\n";

This study source was downloaded by 100000769552447 from CourseHero.com on 07-19-2022 07:59:29 GMT -05:00

https://www.coursehero.com/file/79621268/AmansicJoshua-John-Y-MachineProblem002docx/
}

do{
cout << "\nDesired seat from above 0 to exit: ";
cin >> seatChoice;
if(seatChoice < 0 || seatChoice > 35){
isValidInput = false;
cout << "\nInvalid Input.!";
}else{
isValidInput = true;
}
}while(!isValidInput);

getRow = (seatChoice - 1) / cols;


getCol = (seatChoice - 1) % cols;
if(seats[getRow][getCol] == 0){
cout << "Seat is taken.\n\n\n";
}else{
seats[getRow][getCol] = 0;
cout << "Seat successfully reserved.\n";
}
cin.get();
}while(seatChoice!=0);
cout << "\n\nExiting...";
cin.get();
cout << "\n";

system ("pause");
return 0;
}

Video Link:
https://drive.google.com/file/d/1cHRxQLkCbGWCKQi0F8bNnwuV9Ig28XM5/vie
w?usp=sharing
https://drive.google.com/file/d/1B0Q3vEe9lsJWKk3t9nP55FiaWh50ycfg/view?
usp=sharing

This study source was downloaded by 100000769552447 from CourseHero.com on 07-19-2022 07:59:29 GMT -05:00

https://www.coursehero.com/file/79621268/AmansicJoshua-John-Y-MachineProblem002docx/
Powered by TCPDF (www.tcpdf.org)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy