-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
151 lines (126 loc) · 3.11 KB
/
main.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include<iostream>
#include<fstream>
#include<windows.h>
#include<sstream>
using namespace std;
class Airline {
private:
string Flight, Des, Dep;
int Seats;
public:
Airline(string flight, string des, string dep, int seats) {
Flight = flight;
Des = des;
Dep = dep;
Seats = seats;
}
string getFlight() {
return Flight;
}
string getDes() {
return Des;
}
string getDep() {
return Dep;
}
int getSeat() {
return Seats;
}
void update(string flight) {
ifstream in("D:/Flight.txt");
ofstream out("D:/Flight Temp.txt");
string line;
while (getline(in, line)) {
int pos = line.find(flight);
if (pos != string::npos) {
int current = Seats - 1;
Seats = current;
stringstream ss;
ss << current;
string strCurrent = ss.str();
int seatPos = line.find_last_of(':');
line.replace(seatPos + 2, string::npos, strCurrent);
}
out << line << endl;
}
out.close();
in.close();
remove("D:/Flight.txt");
rename("D:/Flight Temp.txt", "D:/Flight.txt");
cout << "Seat Reserved Successfuly!" << endl;
}
};
void display() {
ifstream in("D:/Flight.txt");
if (!in) {
cout << "Error: File Can't Open!" << endl;
}
else {
string line;
while (getline(in, line)) {
cout << line << endl;
}
}
}
int main() {
Airline flight1("F101", "UAE", "England", 50);
Airline flight2("F202", "UAE", "USA", 40);
Airline flight3("F303", "UAE", "Canada", 2);
ofstream out("D:/Flight.txt");
if (!out) {
cout << "Error: File can't open!" << endl;
}
else {
out << "\t " << flight1.getFlight() << " : " << flight1.getDes() << " : " << flight1.getDep() << " : " <<
" : " << flight1.getSeat() << endl << endl;
out << "\t " << flight2.getFlight() << " : " << flight2.getDes() << " : " << flight2.getDep() <<
" : " << flight2.getSeat() << endl << endl;
out << "\t " << flight3.getFlight() << " : " << flight3.getDes() << " : " << flight3.getDep() <<
" : " << flight3.getSeat() << endl << endl;
cout << "Data Saved Successfuly!" << endl;
out.close();
}
bool exit = false;
while (!exit) {
system("cls");
cout << "\t Welcome To Airline Management System" << endl;
cout << "\t ************************************" << endl;
cout << "\t 1.Reserve A Seat." << endl;
cout << "\t 2.Exit." << endl;
cout << "\t Enter Your Choice: ";
int val;
cin >> val;
if (val == 1) {
system("cls");
display();
string flight;
cout << "Enter Flight No: ";
cin >> flight;
if (flight == flight1.getFlight() && flight1.getSeat() > 0) {
flight1.update(flight);
}
else if (flight1.getSeat() <= 0) {
cout << "Sorry, Seats Not Available!" << endl;
}
if (flight == flight2.getFlight() && flight2.getSeat() > 0) {
flight2.update(flight);
}
else if (flight2.getSeat() <= 0) {
cout << "Sorry, Seat Not Available!" << endl;
}
if (flight == flight3.getFlight() && flight3.getSeat() > 0) {
flight3.update(flight);
}
else if (flight3.getSeat() <= 0) {
cout << "Sorry, Seat Not Available!" << endl;
}
Sleep(5000);
}
else if (val == 2) {
system("cls");
exit = true;
cout << "Good Luck!" << endl;
Sleep(3000);
}
}
}