#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;
class item
{ //data members
private:
int number;
char type[15];
int price;
public:
// member function void
void get_item (void);
void put_item (void);
int get_code(void)
return number;
void update_price(int num)
price=num;
}
}; //End of class
// Member Function
void item :: get_item (void)
cout<<"Add number of destination:"; cin>>number;
fflush(stdin);
cout<<"Add type of vehicle:"; cin>>type;
cout<<"Add Price:"; cin>>price;
// Member Function
void item :: put_item (void)
//Display with field width
cout<<setw(6)<<number
<<setw(15)<<type
<<setw(6)<<price << endl;
//Function Prototypes
void add_record(void);
void show_record(void);
void show_all(void);
void delete_record(void);
void modify_record(void);
// Global Declaration
item it; //create object
fstream file; //Create stream object
//main Function
int main()
int profile;
cout<<"============================"<<endl;
cout<<"ANGKAS BOOKING"<<endl;
cout<<"============================"<<endl;
cout<<"Select your profile"<<endl;
cout<<"Enter A if you are a Admin"<<endl;
cout<<"Enter C if you are a Client"<<endl;
cin>>profile;
if(profile == '4'){
goto admin;
// else if(profile != '1'){
// goto user;
// }
// break;
admin:
system("cls");
int op, ordinary;
cout<<"1 ORDINARY"<<endl;
cout<<"2 VIP"<<endl;
// cout<<"3 Activities"<<endl;
cin>>op;
if (op == '1')
goto ordinary;}
/* else if(profile == '2'){
goto place;
}*/
/* else if(profile == '3'){
goto place;
}*/
ordinary:
int option;
while(1)
{system("cls");
cout<<"*MENU*"<<endl;
cout<<"1.Add New Places"<<endl;
cout<<"2.Display All Record"<<endl;
cout<<"3.Display Particular Record"<<endl;
cout<<"4.Delete Record"<<endl;
cout<<"5.Update/Modify Record"<<endl;
cout<<"6.Exit"<<endl;
cout<<"Enter Option No.:"; cin>>option;
switch (option)
{
case 1:{add_record();
cout<<"Press any key for Main Menu...";
getch();
break;
case 2:{// Funtion call to reacord
cout<<"---------------------------------------------\n";
cout<<setw(6)<<"number"<<setw(15)<<"type"<<setw(6)<<"price"<<endl;
cout<<"---------------------------------------------\n";
show_all();
cout<<"---------------------------------------------\n";
cout<<"Press any key for Main Menu...";
getch();
break;
case 3:{
show_record();
cout<<"Press any key to Main Menu..";
getch();
break;
case 4:{
delete_record();
cout<<"Press any key to Main Menu..";
getch();
break;
case 5:{
modify_record();
cout<<"Press any key to Main Menu..";
getch();
break;
case 6:{
exit(0);
Default:{
cout<<"Incorrect Option, Press any key for Main Menu..";
getch();
break;
}// End of Switch
} //End of While
return 0;
// Function to add record in file
void add_record()
char ch='y';
file.open("stock.dat", ios::app| ios::binary);
while(ch=='y' || ch=='Y')
it.get_item();
//write object into a file
file.write((char*)&it, sizeof(it));
cout<<"Add more records...(y/n)?";
cin>>ch;
file.close();
//function to display all records from file
void show_all (void)
file.open("stock.dat",ios::in| ios::binary);
if(! file) // if file open fails
{cout<<"file not found";
exit(0);
else
// read record from file into object
file.read((char*)&it, sizeof(it));
while (! file.eof()) //while end of file
it.put_item(); //display object
file.read((char*)&it, sizeof(it));
file.close(); //close a file
// funtion to display all records from file
void show_record (void)
{
int no, flag=0;
file.open("stock.dat", ios::in | ios::binary);
if(! file) //if file open fails
cout<<"file not found";
exit(0);
else
cout<<"enter number of room to search:";
cin>>no;
//read record from a file into object
file.read((char*)&it, sizeof(it));
while (! file.eof()) //while end of file
if(no==it.get_code())
flag=1;
cout<<"---------------------------------------------\n";
cout<<setw(6)<<"number"<<setw(15)<<"type"<<setw(6)<<"price"<<endl;
cout<<"---------------------------------------------\n";
it.put_item();//display object
cout<<"---------------------------------------------\n";
break;
file.read((char*)&it, sizeof(it));
if(flag==0)
{
cout<<"item not found.../n";
file.close(); //close a file
//Function to delete record from file
void delete_record()
int no;
cout<<"Enter the number of room to delete:";
cin>>no;
ofstream file2; //stream object
//open new.dat file for write operation
file2.open("new.dat", ios::out|ios::binary);
//open stock.dat file for write operation
file.open("stock.dat", ios::in| ios::binary);
if(! file) //if open file fails
cout<<"file not found";
exit(0);
else
//read record from stock.dat file into object
file.read((char*)&it, sizeof(it));
while(!file.eof()) //upto end of file
//if item code not match
if(no != it.get_code())
//write record into new.dat file
file2.write((char*)&it, sizeof(it));
//read record from stock.dat file into object
file.read((char*)&it, sizeof(it));
file2.close(); //close new.dat file
file.close(); //close stock.dat file
remove("stock.dat");
rename("new.dat", "stock.dat");
} //end of delete function
//Functio to modify record in a file
void modify_record(void)
int no,num;
cout<<"Enter number of room to modify:"; cin>>no;
cout<<"Enter the price issued:"; cin>>num;
file.open("stock.dat", ios::in | ios::out | ios::binary);
if (!file) //if open file fails
cout<<"File not found";
exit(0);
while(file.read((char*)&it, sizeof(it)))
{
if(it.get_code()==no)
it.update_price(num); //update object
//move put pointer to current position-1
int pos = sizeof(it);
file.seekp(-pos, ios::cur);
//Write object to stock.dat file
file.write((char*)&it, sizeof(it));
} //End of While
file.close(); //close stock.dat file
} //End of Function