rendered paste body#include <iostream>
#include <fstream>
using namespace std;
void Initialize (int[], int[]);
void PrintBookings(int [],int [], int);
int FindFlight (int [], int, int);
int main () {
int flightNo[20];
int bookings[20];
int i, type, flightnumb, seats, search;
for (i=0; i<20; i++){
flightNo[i]=0;
bookings[i]=0;
}
Initialize (flightNo, bookings);
PrintBookings (flightNo, bookings, 17);
ifstream File ("/Users/mine/Programming/Assignment 7/transactions.txt", ios::in);
File >> type >> flightnumb >> seats;
while (File) {
search= FindFlight(flightNo, 20, flightnumb);
if (search ==-1){
cout << "Invalid Flight Number" << endl;
} else {
if (type==2){
// cancel a flight
if (seats > bookings [search])
cout << seats << " seats were not cancled from flight "<< flightnumb << " (excess of seats booked)"<< endl;
else {
bookings[search]-=seats;
cout << seats << " seats subtracted from flight " << flightnumb << endl;
}
} else if (type==1){
// add a flight
bookings[flightnumb]+=seats;
cout << seats << " seats added to flight " << flightnumb << endl;
} else cout << "Transaction Type Invalid" << endl;
}
File >> type >> flightnumb >> seats;
}
PrintBookings (flightNo, bookings, 17);
return 0;
}
void Initialize (int flight[], int bookings[]){
int i;
int count=0;
ifstream File ("/Users/mine/Programming/Assignment 7/info.txt", ios::in);
for (i=0; i<=10; i++){
File >> flight[i];
bookings[i]=0;
count++;
}
return;
}
void PrintBookings (int flight [], int bookings [], int count){
int i;
cout.width(10);
cout << "Flight number";
cout.width(15);
cout << "Current Booking" << endl;
for (i=0; i<count; i++){
cout.width(10);
cout << flight[i];
cout.width(13);
cout << bookings[i]<< endl;
}
return;
}
int FindFlight (int flightNo[], int count, int flight){
int i;
for (i=0; i<count; i++) {
if (flightNo[i]==flight)
return i;
}
return -1;
}