Thursday, December 01, 2005

A$$ignment 1

Well, until now not sure that want to blog abt what. Guess i post the "ersult" hrhar i had done for the last whole weeks.

WARNING: PLease do not try to compile it in ur brain, since will let ur brain went overload. As a recommend use Dev C++ version 4.9.8.0 and above


// TCP1241 Assignment 1 Trimester 2 2005/2006
// Done by Choo Chia Poh, Teo Leong Kim, Tan Hsia-Liang
//Copy of the code is prohibited, All Right Reserved

#include <.iostream>
#include <.fstream>
#include <.string>
#include <.cstring>
#include <.conio.c>
#include <.stdlib.h>

using namespace std;
struct cust{
char username[255];
char password[255];
char name[255];
char ic[255];
char contact_no[255];
char address[255];
};

struct book{
char book_code[255];
char pass_name[255];
char pass_ic[255];
char flight_code[255];
char promo_code[255];
char tax[255];
char card_no[255];
int commit;
};

struct promo{
char promo_code[255];
char flight_code[255];
char seats_left[255];
char promo_price[255];
};

struct sche{
char flight_code[255];
char from[255];
char destination[255];
char date[255];
char time[255];
char price[255];
char seats_left[255];
};

void load_cust();
void load_book();
void load_promo();
void load_sche();
void login();
void menu1();
void menu2();
void add_entry();
void add_entry2();
void display_entry();
void display_entry2();
void add_user();
void add_book();
void modify_book();
void display_sche();
void display_book();
void add_book();
void write_entry();
void edit_pass_name(int);
void edit_card_no(int);
void edit_flight_code(int);
void edit_pass_ic(int);
void edit_promo_code(int);
void write_book();
void delete_entry();
void print();
void splash();
cust detial[30];
book book_detail[30];
promo promo_detail[30];
sche sche_detail[30];
book add_detial[1];


//Universal Variable for Login System===========================================
int total_index;
int index;
//==============================================================================

//Universal Variable for User Registration======================================
string username;
string password;
string password2;
string ic;
string contact;
string cust_name;
string address;
//==============================================================================

//Universal Variable for Modify System==========================================
int book_index;
//==============================================================================

//Universial Variable for flight timetable======================================
int sche_index;
//==============================================================================

//Universial Variable for Promo code checking===================================
int promo_index;
//==============================================================================

//Main Function=================================================================
int main()
{
splash();
menu1();
menu2();
system("Pause");
return 0;
}
//==============================================================================

//Menu 1 =======================================================================
void menu1()
{
int choice = 1;
while(choice!=0)
{
clrscr();
gotoxy(20, 5);
cout << "Welcome to Air Asia Online Reservation System" <<>> choice;
if(choice<1||choice>3)
gotoxy(27,15);
cerr << "Invalid choice, please retry again."; }while(choice<1||choice>3);

switch(choice)
{
case 1: clrscr(); login(); cin.ignore(); break;
case 2: clrscr(); add_user(); cin.ignore(); break;
case 3: clrscr(); exit(1); cin.ignore(); break;
}
}
}
//==============================================================================

//Menu 2========================================================================
void menu2()
{

int choice = 1;
while(choice!=0)
{
clrscr();
gotoxy(23, 3);
cout << "Welcome Mr./Ms. " <<>> choice;
if(choice<1||choice>7)
gotoxy(24, 20);
cerr << "Invalid choice, please retry again."; }while(choice<1||choice>7);
switch(choice)
{
case 1: clrscr(); add_book() ; cin.ignore(); break;
case 2: clrscr(); modify_book(); cin.ignore(); break;
case 3: clrscr(); delete_entry(); cin.ignore(); break;
case 4: clrscr(); display_sche(); cin.ignore(); break;
case 5: clrscr(); display_book() ; cin.ignore(); break;
case 6: clrscr(); print(); cin.ignore(); break;
case 7: clrscr(); menu1(); cin.ignore(); break;
}
}
}
//==============================================================================

//Loading function(customer.txt)================================================
//To load the customer.txt into the array
void load_cust()
{
string temp;
ifstream file_op("customer.txt", ios::in);
int i=0;
while (!file_op.eof())
{
file_op.getline(detial[i].username, 255, ';');
temp = detial[i].username;
temp.erase(0,1);
strcpy(detial[i].username, temp.c_str());

file_op.getline(detial[i].password, 255, ';');
temp = detial[i].password;
temp.erase(0,1);
strcpy(detial[i].password, temp.c_str());

file_op.getline(detial[i].name, 2000, ';');
temp = detial[i].name;
temp.erase(0,1);
strcpy(detial[i].name, temp.c_str());

file_op.getline(detial[i].ic, 2000, ';');
temp = detial[i].ic;
temp.erase(0,1);
strcpy(detial[i].ic, temp.c_str());

file_op.getline(detial[i].contact_no, 2000, ';');
temp = detial[i].contact_no;
temp.erase(0,1);
strcpy(detial[i].contact_no, temp.c_str());

file_op.getline(detial[i].address, 2000, ';');
temp = detial[i].address;
temp.erase(0,1);
strcpy(detial[i].address, temp.c_str());

i++;
}
total_index = i;

file_op.close();
}
//==============================================================================

//Loading function(booking.txt)=================================================
//To load the booking.txt into the array
void load_book()
{
string temp;
ifstream file_op("booking.txt", ios::in);
int i=0;
while (!file_op.eof())
{
file_op.getline(book_detail[i].book_code, 255, ';');
temp = book_detail[i].book_code;
temp.erase(0,1);
strcpy(book_detail[i].book_code, temp.c_str());

file_op.getline(book_detail[i].pass_name, 255, ';');
temp = book_detail[i].pass_name;
temp.erase(0,1);
strcpy(book_detail[i].pass_name, temp.c_str());

file_op.getline(book_detail[i].pass_ic, 255, ';');
temp = book_detail[i].pass_ic;
temp.erase(0,1);
strcpy(book_detail[i].pass_ic, temp.c_str());

file_op.getline(book_detail[i].flight_code, 255, ';');
temp = book_detail[i].flight_code;
temp.erase(0,1);
strcpy(book_detail[i].flight_code, temp.c_str());

file_op.getline(book_detail[i].promo_code, 255, ';');
temp = book_detail[i].promo_code;
temp.erase(0,1);
strcpy(book_detail[i].promo_code, temp.c_str());

file_op.getline(book_detail[i].tax, 255, ';');
temp = book_detail[i].tax;
temp.erase(0,1);
strcpy(book_detail[i].tax, temp.c_str());

file_op.getline(book_detail[i].card_no, 255, ';');
temp = book_detail[i].card_no;
temp.erase(0,1);
strcpy(book_detail[i].card_no, temp.c_str());

book_detail[i].commit = 0;
i++;
}
book_index = i;
file_op.close();
}
//==============================================================================

//Loading function(promotion.txt)===============================================
//To load the promotion.txt into the array
void load_promo()
{
string temp;
ifstream file_op("promotion.txt", ios::in);
int i=0;
while (!file_op.eof())
{
file_op.getline(promo_detail[i].promo_code, 255, ';');
temp = promo_detail[i].promo_code;
temp.erase(0,1);
strcpy(promo_detail[i].promo_code, temp.c_str());

file_op.getline(promo_detail[i].flight_code, 255, ';');
temp = promo_detail[i].flight_code;
temp.erase(0,1);
strcpy(promo_detail[i].flight_code, temp.c_str());

file_op.getline(promo_detail[i].seats_left, 255, ';');
temp = promo_detail[i].seats_left;
temp.erase(0,1);
strcpy(promo_detail[i].seats_left, temp.c_str());

file_op.getline(promo_detail[i].promo_price, 255, ';');
temp = promo_detail[i].promo_price;
temp.erase(0,1);
strcpy(promo_detail[i].promo_price, temp.c_str());

i++;
}
promo_index = i;
file_op.close();
}
//==============================================================================

//Loading function(schedule.txt)===============================================
//To load the schedule.txt into the array
void load_sche()
{
string temp;
ifstream file_op("schedule.txt", ios::in);
int i=0;
while (!file_op.eof())
{
file_op.getline(sche_detail[i].flight_code, 255, ';');
temp = sche_detail[i].flight_code;
temp.erase(0,1);
strcpy(sche_detail[i].flight_code, temp.c_str());

file_op.getline(sche_detail[i].from, 255, ';');
temp = sche_detail[i].from;
temp.erase(0,1);
strcpy(sche_detail[i].from, temp.c_str());

file_op.getline(sche_detail[i].destination, 255, ';');
temp = sche_detail[i].destination;
temp.erase(0,1);
strcpy(sche_detail[i].destination, temp.c_str());

file_op.getline(sche_detail[i].date, 255, ';');
temp = sche_detail[i].date;
temp.erase(0,1);
strcpy(sche_detail[i].date, temp.c_str());

file_op.getline(sche_detail[i].time, 255, ';');
temp = sche_detail[i].time;
temp.erase(0,1);
strcpy(sche_detail[i].time, temp.c_str());

file_op.getline(sche_detail[i].price, 255, ';');
temp = sche_detail[i].price;
temp.erase(0,1);
strcpy(sche_detail[i].price, temp.c_str());

file_op.getline(sche_detail[i].seats_left, 255, ';');
temp = sche_detail[i].seats_left;
temp.erase(0,1);
strcpy(sche_detail[i].seats_left, temp.c_str());

i++;
}
sche_index = i;
file_op.close();
}
//==============================================================================

//Login=========================================================================
//The login function for the system

void login()
{
load_cust();//load customer textfile to memory
int ch, i;
char username[255];
cin.ignore();
//for username
for(int chance = 0; chance <3; i =" 0;" i="0;" result =" 0;" result =" 2;" result ="="" result ="="" result ="="" chance ="="" index =" i;//to" chance =" 0;">> password;
int result;
if(strcmp(detial[index].password,password)==0)
result = 0;
else
result = 2;
if(result == 2 && chance <= 1) { gotoxy(24,20); cerr << "Password incorrect!"; } else if(result == 2 && chance == 2) { gotoxy(16,20); cerr << "Invalid password have key in, program exiting....."; getch(); exit(1); } else if (result == 0) break; }; system("cls"); menu2(); } //============================================================================== //User Registration============================================================= void add_user() { char answer, answer2; ofstream read("customer.txt", ios::out|ios::app); do{ do{ clrscr(); add_entry(); clrscr(); display_entry(); gotoxy(20, 17); cout << "Are the details above are correct? (Y/N): "; cin >> answer;
if(answer=='n'||answer=='N')
{
gotoxy(20, 17);
cout << "Do you want to reenter your entry? (Y/N): "; cin >> answer2;
}
else if(answer=='y'||answer=='Y')
{
read <<>> username;
password = 'asd';
password2 = 'wewqe';
cin.ignore();
while (password != password2)
{

cout << "Please enter a password: "; cin >> password;

cout <<"Please enter the password again: "; cin >> password2;
if(password != password2)
{
cout << "Both password are unmatch, please enter the password again.\n"; } }; cin.ignore(); cout << "Please enter your name: "; getline(cin,cust_name); cout << "Please enter your IC No.: "; cin >> ic;

cout << "Please enter your contact number: "; cin >> contact;

cin.ignore();
cout << "Please enter your address: "; getline(cin,address); } //============================================================================== //User Registration (Display)=================================================== void display_entry() { gotoxy(24, 5); cout << "Username : " << booking="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" entry="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" temp4 =" 0;" temp3="1;" temp =" atoi(book_detail[book_index-2].book_code);" i ="0;" temp =" strcmp(add_detial[0].flight_code,sche_detail[i].flight_code);" temp="="0)" i ="0;" temp =" strcmp(add_detial[0].promo_code,promo_detail[i].promo_code);" temp="="0)" temp2 =" i;" temp3="strcmp(add_detial[0].flight_code,promo_detail[temp2].flight_code);" temp4 =" atoi(promo_detail[temp2].seats_left);" temp =" 1;" temp="="1)" entry="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="">> answer;
if (tolower(answer)!='y'&& tolower(answer)!='n')
gotoxy(16,20);
cout << "You have enter a invalid respond, please try again\n"; }while(tolower(answer)!='y'&& tolower(answer)!='n'); } //============================================================================== //Write booking entry to text file============================================== void write_entry() { ofstream write("booking.txt", ios::out|ios::app); write << booking="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" i =" 1;" temp =" i;">> num;
if (num<1||num>temp)
cout << "Invalid choice, please retry again."; } while (num<1||num>temp);

do{
clrscr();
cout << "Please choose the attribute that you want to edit:" <<>> choice;
if(choice<1||choice>6)
cerr << "Invalid choice, please retry again."; }while(choice<1||choice>6);
switch(choice)
{
case 1: clrscr(); edit_pass_name(num); break;
case 2: clrscr(); edit_pass_ic(num); break;
case 3: clrscr(); edit_flight_code(num); break;
case 4: clrscr(); edit_promo_code(num); break;
case 5: clrscr(); edit_card_no(num); break;
case 6: clrscr(); write_book();menu2(); break;
};
}while(choice != 8);
}
//==============================================================================

//Edit pass_name================================================================
void edit_pass_name(int num)
{
cin.ignore();
char temp[255];
//cout << card_no="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" flight_code="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" i ="0;" temp =" strcmp(book_detail[num].flight_code,sche_detail[i].flight_code);" temp="="0)" pass_ic="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" promo_code="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" temp4 =" 0;" temp3="1;" i ="0;" temp =" strcmp(book_detail[num].promo_code,promo_detail[i].promo_code);" temp="="0)" temp2 =" i;" temp3="strcmp(book_detail[num].flight_code,promo_detail[temp2].flight_code);" temp4 =" atoi(promo_detail[temp2].seats_left);" temp =" 1;" temp="="1)" txt="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" i =" 0;" detial="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" j =" 0;" k =" 0;" i =" 1;" i =" 0;" timetable="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" i =" 1;" entry="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" i =" 1;" temp =" i;">> num;
if (num<1||num>temp)
cout << "Invalid choice, please retry again.\n"; } while (num<1||num>temp);

book_detail[num].commit = 1;

ofstream write("booking.txt", ios::out);
write << "B"; for (int i = 0; i < commit ="="" print="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" i =" 0;" j =" 1;">> respond;

//To get the ticket price
check3 = strcmp(temp_arr[respond].promo_code,"0");
if(check3 == 0)
{
for(int i = 0; i < check="strcmp(temp_arr[respond].flight_code,sche_detail[i].flight_code);" check ="="0)" temp1 =" atof(sche_detail[i].price);" i =" 0;" check="strcmp(temp_arr[respond].flight_code,promo_detail[i].flight_code);" check ="="0)" temp1 =" atof(promo_detail[i].promo_price);" i =" 0;" check2 ="strcmp(temp_arr[respond].flight_code,sche_detail[i].flight_code);" check2="="0)">***********<> " << endl;
cout << " ******** " << endl;
cout << " ****** " << endl;
cout << " **** " << endl;
cout << " ** " << endl;
cout << " * " << endl << "\n";
cout << " ~~~~ Now Everyone Can Fly ~~~~";
getch();
}

No comments: