Using c++, we need to display table and import a file from our computer also obj
ID: 3600437 • Letter: U
Question
Using c++, we need to display table and import a file from our computer also objective Practice reading from a file . Practice using an array A theater seating chart is implemented as a table of ticket prices, like this 10 10 10 10 10 10 20 30 40 40 10 10 10 20 20 20 30 30 50 50 10 10 10 20 20 20 30 40 50 50 10 10 10 20 20 20 30 50 50 50 10 10 10 20 20 20 30 50 50 50 10 10 10 20 20 20 30 40 50 50 10 10 10 20 20 20 30 30 50 50 10 10 10 10 10 10 20 30 40 40 10 10 10 10 10 10 10 10 10 10 10 20 20 30 20 20 20 30 20 The above seating information is saved in a text file. Your program should load the information from the file into an array Write a program that asks users to pick either a seat or a price. When choosing seat, indicate the row and column for the location; when choosing the price, randomly choose a seat with that price; mark the sold seats by changing the price to 0. Make sure your code will check whether the seat is available (doesn't matter which method you use) Use loop to determine whether continue to order or not. In each time, the seating chart should be displayed for user When user stops ordering, your program should output the number of tickets ordered, and amount orderedExplanation / Answer
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main(){
ifstream fin;
int data[10][10];
int ch,n,amt;
int row,col,pr;
srand(time(NULL));
fin.open("input61.txt");
if (!fin){
cout << "Error opening file ";
return 0;
}
for (int i = 0; i<10; i++){
for (int j = 0; j<10; j++){
fin >> data[i][j];
}
}
n = 0;
amt = 0;
while (1){
for (int i = 0; i<10; i++){
for (int j = 0; j<10; j++){
cout << data[i][j] << " ";
}
cout << " ";
}
cout << endl << endl;
cout << "1.Pick a seat ";
cout << "2.A price ";
cout << "3.quit ";
cout << "Enter your choice:";
cin >> ch;
if (ch == 3)
break;
if (ch == 1){
cout << "Enter row and column:";
cin >> row >> col;
if (data[row-1][col-1] == 0){
cout << "Seat is sold ";
}
else {
n++;
amt = amt + data[row][col];
data[row][col] = 0;
}
}
if (ch == 2){
cout << "Enter price :";
cin >> pr;
row = rand()%10;
col = rand()%10;
while (data[row][col] != pr && data[row][col] != 0){
row = rand()%10;
col = rand()%10;
}
n++;
amt = amt + data[row][col];
data[row][col] = 0;
}
}
cout << "Number of tickets:" << n << endl;
cout << "Amount:" << amt << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.