-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoeing.cpp
128 lines (109 loc) · 3.06 KB
/
Boeing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Class: Boeing
*
* This class is an inheritance of the Plane abstract class.
* It implement the functions printSeats and save of its base class.
*
* Designed by: Team 4
*
* List of methods:
* constructor and destructor
* printSeats: display the seat arrangment in the plane
* save: save the seating chart back to the file in the same format
*
*/
#include "Boeing.h"
#include <iostream> // to use cin/cout
#include <fstream> // to work with files
using namespace std;
/******************************************
* CONSTRUCTOR
* load the file to store the seating chart
*****************************************/
Boeing::Boeing(string flightCode, string depart, string arrive, string fileName) :
Plane(94, flightCode, depart, arrive, fileName)
{
type = "Boeing";
businessClassSeats = 24;
seatingFile = fileName;
}
/********************************************
* DESTRUCTOR
* save the seating chart back into the file
*********************************************/
Boeing::~Boeing()
{
save();
}
/****************************************
* function: printSeats (override)
* parameter:
* return: void
* display the seating arrangement
*****************************************/
void Boeing::printSeats()
{
printPlaneInfo();
cout << "Seating chart:\n\n BUSINESS CLASS\n";
// display bussiness seats layout
for (int i = 0; i < businessClassSeats; i++)
{
// display the first 2 whitespaces at the beginning of each row
if (i % 3 == 0)
cout << " " << seatingChart[i];
// display the seat then go to new row
else if ((i + 1) % 3 == 0)
cout << seatingChart[i] << "\n";
else
cout << " " << seatingChart[i] << " ";
}
cout << " ECONOMIC CLASS\n";
// display economic seats layout
for (int i = businessClassSeats; i < capacity; i++)
{
if ((i + 1) % 5 == 0)
cout << seatingChart[i] << " ";
else if ((i + 2) % 5 == 0)
cout << " " << seatingChart[i] << endl;
else
cout << seatingChart[i] << " ";
}
}
/*******************************************
* function: save (override)
* parameter: outputFileName: string
* return: void
* save the seating chart back into the file
********************************************/
void Boeing::save()
{
ofstream outputFile(fileName + ".txt");
if (!outputFile)
{
cout << "Cannot open output file.\n";
return;
}
// display bussiness seats layout
for (int i = 0; i < businessClassSeats; i++)
{
// display the first 2 whitespaces at the beginning of each row
if (i % 3 == 0)
outputFile << " " << seatingChart[i];
// display the seat then go to new row
else if ((i + 1) % 3 == 0)
outputFile << seatingChart[i] << "\n";
else
outputFile << " " << seatingChart[i] << " ";
}
outputFile << endl;
// display economic seats layout
for (int i = businessClassSeats; i < capacity; i++)
{
if ((i + 1) % 5 == 0)
outputFile << seatingChart[i] << " ";
else if ((i + 2) % 5 == 0)
outputFile << " " << seatingChart[i] << endl;
else
outputFile << seatingChart[i] << " ";
}
}