📄 fightapplication.cpp
字号:
// TCP1241 Assignment 1 Trimester 2 2005/2006
// Lecture section, Tutorial section, ID, Name
//1. TMB02 , TMB2B, 1021109185, Loh Kah Hoe
//2. TMB02, TMB2B, 1041102888, Soo Feng Gee
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class reservation{
string cust_name, cust_IC, cust_age, flight_date, flight_time, flight_place;
int flight_code, number_of_ticket;
private:
ifstream in_stream_reservation;
ofstream out_stream_reservation;
public:
void main();
void sched();
void add();
void view();
void modify();
void del();
void display();
};
reservation res;
void reservation::main()
{
int an=0;
system("cls");
while(an<=6){
cout<<"(1) View flight schedule "<<endl;
cout<<"(2) Add flight booking "<<endl;
cout<<"(3) View booking "<<endl;
cout<<"(4) Cancel booking "<<endl;
cout<<"(5) Print ticket "<<endl;
cout<<"(6) Exit "<<endl;
cout<<endl;
cout<<"<Please enter your choice>";
input:
cin>>an;
if(an==1)
{ res.sched();}
else if (an==2)
{ res.add();}
else if (an==3)
{ res.view();}
else if (an==4)
{ res.del();}
else if (an==5)
{ res.display();}
else if (an==6)
{exit(0);}
else
cout<<"Please enter optional number 1 - 6:";
goto input;
}
system("pause");
}
void reservation::sched()
{
string name;
ifstream schedule("schedule.txt");
while (!schedule.eof())
{
getline (schedule, name);
cout << name << endl;
}
schedule.close(); // must close the file
cout << endl << endl;
system("PAUSE");
main();
}
void reservation::add()
{
int n;
int i;
char cont='Y';
while (cont=='Y' || cont=='y')
{
ofstream out;
out.open("data.txt", ios::app);
if (out.fail())
{
cout << "Input fail";
exit(1);
}
cout << " Airport Flights Booking System " << endl;
cout << "-------------------------------------------" << endl;
cout << endl;
//enter customer
cout << "Enter how many booking customer: ";
cin >> n;
cout << endl;
reservation info[n];
for (i=0; i<n; i++)
{
cout << "Enter customer name: ";
cin >> info[i].cust_name;
cout << "Enter customer IC: ";
cin >> info[i].cust_IC;
cout << "Enter customer age: ";
cin >> info[i].cust_age;
cout << "Enter customer flight date: ";
cin >> info[i].flight_date;
cout << "Enter customer flight time: ";
cin >> info[i].flight_time;
cout << "Enter customer flight place(From Kuala Lumpur to): ";
cin >> info[i].flight_place;
cout << "Enter customer flight code: ";
cin >> info[i].flight_code;
cout << endl;
}
//insert into files
for (i=0; i<n; i++)
{
out<<"Customer Name : "<< info[i].cust_name << endl;
out<<"Customer IC : "<< info[i].cust_IC << endl;
out<<"Customer Age : "<< info[i].cust_age << endl;
out<<"Flight Date : "<< info[i].flight_date << endl;
out<<"Flight Time : "<< info[i].flight_time << endl;
out<<"Flight Place(from Kuala Lumpur to): "<< info[i].flight_place << endl;
out<<"Flight Code : "<< info[i].flight_code << endl;
out<< endl;
}
//pop up at screen
for (i=0; i<n; i++)
{
cout<<"Customer Name : "<< info[i].cust_name << endl;
cout<<"Customer IC : "<< info[i].cust_IC << endl;
cout<<"Customer Age : "<< info[i].cust_age << endl;
cout<<"Flight Date : "<< info[i].flight_date << endl;
cout<<"Flight Time : "<< info[i].flight_time << endl;
cout<<"Flight Place(from Kuala Lumpur to): "<< info[i].flight_place << endl;
cout<<"Flight Code : "<< info[i].flight_code << endl;
cout<< endl;
}
out.close();
cout<<"Do you wan to continue? (y/n): ";
cin >> cont;
}
cout << endl;
system("PAUSE");
main();
}
void reservation::view()
{
string name;
ifstream reserve("data.txt");
while (!reserve.eof()){
getline (reserve, name);
cout << name << endl;
}
reserve.close(); // must close the file
cout << endl << endl;
system("PAUSE");
main();
}
void reservation::del()
{
ofstream del;
del.open("data.txt", ios::trunc);
del.close();
cout << endl;
system("PAUSE");
main();
}
void reservation::display()
{
string name;
ifstream reserve("data.txt");
while (!reserve.eof()){
getline (reserve, name);
cout << name << endl;
}
reserve.close(); // must close the file
cout << endl << endl;
system("PAUSE");
main();
}
int main()
{
system("cls");
res.main();
system("PAUSE");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -