• Option 4 (Save Seat Chart to File): The program calls a function that prompts
ID: 3820406 • Letter: #
Question
• Option 4 (Save Seat Chart to File): The program calls a function that prompts users for a file name. Then it saves the chart to that file in the format shown in page 1. • Option 5 (statistics): The program calls a function that displays the following statistics: Number of available seats, percentage of seats that are reserved, list of window seats that are available, list of aisle seats that are available.• Option 6 (Help): the program calls a function that displays a detailed message on how to use the program. The aim of this project is to implement a seat reservation system fora passenger airplane. We assume a small airplane with 10 rows and 4 seats per row. We assume that the seat chart is initially stored in a file "chartIn.txt" in the following format: A B C D 2 ABCD 3 A B C D A B C D 5 A B C D 6 A B C D A B C D A B C D ABCD 10 ABCD The example given above means that seats 1A, 1B, 1C, ID, 2A, 2B, 2C, 2D, 3A, are all available. Note that the number 1, 2, 3 also belong to the file. Below is another example of data store in the file "chartIn.txt": A X C D A B C D 3 A B C D A B C D 5 A X CD 6 A B C D 7 A B C D A B C D 9 ABX D 10 A XX D This second example mentions that the following seats marked with X' are reserved: l B, 5B, 9C, 10B, 10C.Explanation / Answer
// Option 6 depends on other options , for the part done here saveChart expects an array(a[10[5]) filled with current
// values to be sent ot it whereas void showStatistics() just needs a call to be made
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
void saveChart(string arr[10][5]); // This is for saving to file string array containing seat chart is needed
void showStatistics(); // This is for showing statistics
void saveChart(string arr[10][5]){
string fname ;
cout << " Please enter the name of the file for saving " ;
cin >> fname ;
ofstream out;
out.open(fname); //opening an output stream for outFileName
for(int i = 0; i <10; i++)
{for(int j = 0; j <5; j++)
{ out << arr[i][j]; out <<" ";
}
out<<" ";
}//writing ith row and jth column of array in the file
out.close();
}
void showStatistics(){
std::stringstream wss;
std::stringstream ass;
string s[10][5];
ifstream in;
string t;
int numA =0 ; float perR; in.open("chartIn.txt"); //opening an input stream for inFileName
for(int i = 0; i <10; i++)
{for(int j = 0; j <5; j++)
{ in >> s[i][j] ;
}
}
for(int i = 0; i <10; i++)
{for(int j = 1; j <5; j++)
{ t=s[i][j] ; if(t=="X") continue;
numA++;
if(j==1||j==4)
wss<<(i+1)<<t<<" ";
else
ass<<(i+1)<<t<<" ";
}
}
perR = 40 -numA ;
perR = perR/40*100;
std::string ws = wss.str();
std::string as = ass.str();
cout<<"Number Of seats available is "<<numA<<" ";
cout<<"Percentage Of seats reserved is "<<perR<<" ";
cout<<"List of available window seats "<<ws<<" ";
cout<<"List of available aisle seats "<<as<<" ";
//writing ith row and jth column of array in the file
in.close();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.