just do option 2,3,4,5 using 2 dimesional array to edit the file.please don\'t u
ID: 3710173 • Letter: J
Question
just do option 2,3,4,5 using 2 dimesional array to edit the file.please don't use classes.I will give you good rating.Thanks
Explanation / Answer
void reserveSeats(char seatChart[10][4]){
char seat[2];
printf("Enter seat number :");
scanf("%s",seat);
if(seatChart[seat[0]-'0'-1][seat[1]-'A']=='x'){ // check if not reserved
printf("Sorry!The seat is already reserved ");
}else{
seatChart[seat[0]-'0'-1][seat[1]-'A']='x';
printf("The seat has been successfully reserved ");
}
}
void cancelSeats(char seatChart[10][4]){
char seat[2];
printf("Enter seat number :");
scanf("%s",seat);
if(seatChart[seat[0]-'0'-1][seat[1]-'A']!='x'){ // check if reserved
printf("Sorry!The seat is not yet reserved ");
}else{
seatChart[seat[0]-'0'-1][seat[1]-'A']=seat[0];
printf("The seat has been successfully cancelled ");
}
}
void statistics(char seatChart[10][4]){
int i,j;
int numOfSeats;
double percent;
for(i=0;i<10;i++){
for(j=0;j<4;j++){
if(seatChart[i][j]!='x') // count available seats
numOfSeats++;
}
}
printf("Number of available seats are %d ",numOfSeats);
percent=((40-numOfSeats)*1.0/(10*4))*100; // total num of seats - available/total seats *100
printf("Percentage of reserved seats are %0.2f ",percent);
printf("List of available window seats :");
for(i=0;i<10;i++){
for(j=0;j<4;j++){
if((j==0||j==3)&&(seatChart[i][j]!='x'))// check window condition and reserved
printf("%d%c ,",i+1,j+'A');
}
}
printf(" List of available Aisle seats :");
for(i=0;i<10;i++){
for(j=0;j<4;j++){
if((j==1||j==2)&&(seatChart[i][j]!='x')) // check middle condition and reserved
printf("%d%c ,",i+1,j+'A');
}
}
}
void saveToFile(char seatChart[10][4]){
char *filename;
int i,j;
FILE * fp;
printf("Enter filename ");
scanf("%s",filename);
fp = fopen (filename,"w"); // open file in write mode
for(i=0;i<10;i++){
for(j=0;j<4;j++){
fprintf(fp,"%c ",seatChart[i][j]);
}
fprintf(fp," ");//add line space
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.