You are on page 1of 9

#include<iostream.

h>
#include<conio.h>
#include<stdlib.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
class automobile
{long price;
char name[20],colour[20],enginedesc[10],power[20],model[20];
public:int ccode,avb;
char status[20];
void input()
{cout<<"Car Code:";
cin>>ccode;
cout<<"\nCompany:";
gets(name);
cout<<"\nCar Name:";
gets(model);
cout<<"\nEngine:";
gets(enginedesc);
cout<<"\nPower:";
gets(power);
cout<<"\nColour:";
gets(colour);
cout<<"\nPrice:";
cin>>price;
cout<<"\nAvailability:";
cin>>avb;
cout<<"\nStatus:";
gets(status);
}
void output()
{cout<<ccode<<'\t'<<name<<'\t'<<model<<'\t'<<enginedesc<<'\t'<<power<<'\t
'<<colour<<'\t'<<price<<'\t'<<status<<"\n\n\n\n";}

void mod();

int getcode()
{return ccode;}
char*getname()
{return name;
}
char*getcolour()
{return colour;
}
long getprice()
{return price;
}
}C;
void user();
void search();
void delete1();
void append();
void modify();
void book();
void pass();
void booktd();
void services();
void display();
void createrecords();
void mod();
void delete2();
void refresh();

void main()
{ textcolor(6);
clrscr();
cout<<"\n\n\n\n\n\n\n\n\t\t\t***********************************\n\t\t\t*
\t\t\t\t *\n\t\t\t* \tWELCOME TO AUTOCARS\t *\n\t\t\t*\t\t\t\t
*\n\t\t\t*\tCar Booking Service\t *\n\t\t\t*\t\t\t\t *\n\t\t\t*\t\t\t\t
*\n\t\t";
cout<<"\t***********************************\n";
long j;
for(j=0;j<100000000;j++);
clrscr();
int choice;
char ch1;

do
{cout<<"\n\n\n\n\n\n\t\t\t***********************************\n\t\t\t*\t\
t\t\t *\n\t\t\t* \t MAIN MENU\t\t *\n\t\t\t*\t\t\t\t
*\n\t\t\t*\t1.ADMINISTRATOR MENU\t *\n\t\t\t*\t\t\t\t
*\n\t\t\t*\t2.USER MENU\t\t *\n\t\t\t*\t\t\t\t
*\n\t\t\t*\t3.EXIT(0)\t\t *\n\t\t\t*\t\t\t\t *\n\t\t";
cout<<"\t***********************************\n";

cout<<"\nWhat Would You Like To Access\n";


cin>>choice;
cout<<endl<<endl<<endl<<endl<<endl<<endl;
switch(choice)
{
case 1:pass();
break;
case 2:user();
break;
case 3:exit(0);
default:exit(0);
}
cout<<"\nWould You Like To Go Back To Main(Y/N)\n\n";
}while(ch1=='Y'||ch1=='y');
}

void pass()
{ char p[5];
int ch,d;
int i,q;
passstart:
i=0;
cout<<"Please Enter The 5 Character Password\n";
while(i<5)
{p[i]=getch();
cout<<"*";
i++;}
cout<<endl;
for(i=0;i<5;i++)
cout<<p[i];
cout<<"\n\n\n";
if(p[0]=='a'&&p[1]=='s'&&p[2]=='d'&&p[3]=='f'&&p[4]=='g')
{
start:
cout<<"\t\t\tADMINISTRATOR MENU\n\n\n\n";
cout<<"1.Create Records\n2.Add New Cars\n";
cout<<"3.Display Available Cars\n4.Modify Car Details\n";
cout<<"5.Delete Records\n6.Refresh\n7.Return To Main Menu\n";
cout<<"What Would You Like To Do:";
cin>>ch;
cout<<endl;
switch(ch)
{case 1:createrecords();goto start;
case 2:
append();goto start;
case 3:display();goto start;
case 4:
modify();goto start;
case 5:
delete1();goto start;
case 6:
refresh();goto start;
case 7: main();}}
else
{cout<<"\nAccess Denied";
cout<<"\nPress 1 To Try Again\nPress 2 To Go Back To Main\n";
cin>>q;
switch(q)
{case 1:goto passstart;
case 2:main();
default:main();
}
}
}

void user()
{
int option;
userstart:
cout<<"\nUSER MENU\n\n";
cout<<"1.Buy a car\n2.Book a Test Drive\n3.Servicing\n4.Return To Main
Menu\n";
cout<<"Enter your Choice:";
cin>>option;
cout<<endl;
switch(option)
{case 1:
search();
goto userstart;
case 2:booktd();
goto userstart;
case 3: services();
goto userstart;
case 4:main();
default:cout<<"INVALID ENTRY\nYou will be redirected to the user
menu\n";user();
}}

void search()
{go:
long lp,up;
int v,flag=0,k;
char n[10],t[10],c[10];
cout<<" Please Enter your Search Criteria";
cout<<"\n1:Company\n2:Price\n3:Colour\n\n";
cout<<" Please Enter the Criteria:\n";
cin>>v;
if(v==1)
{ifstream f1("AUTOMOBILE.DAT",ios::binary);
ofstream f2("temp.dat",ios::binary);
cout<<"\nEnter the Company of the car:";
gets(n);
f1.seekg(0);
while(f1.read((char*)&C,sizeof(C)))
{
if(strcmp(C.getname(),n)==0)
{flag=1;
f2.write((char*)&C,sizeof(C));
C.output();}}
f1.close();
f2.close();
if (flag==1)
book();
if (flag==0)
{cout<<"The Car you have searched for is currently unavailable\n";
cout<<"Press 1 to search again or Press 2 to go to the Main Menu\n";
cin>>k;
switch(k)
{case 1:goto go;
case 2:main();
}
}}
else if(v==2)
{ifstream f1("AUTOMOBILE.DAT",ios::binary);
ofstream f2("temp.dat",ios::binary);
cout<<"\nEnter the Price Range(lower limit & upper limit)\n";
cin>>lp>>up;
f1.seekg(0);
while(f1.read((char*)&C,sizeof(C)))
{
if(C.getprice()>=lp && C.getprice()<=up)
{flag=1;
f2.write((char*)&C,sizeof(C));
C.output();}}
f1.close();
f2.close();
if (flag==1)
book();
if (flag==0)
{cout<<"The Car you have searched for is currently unavailable\n";
cout<<"Press 1 to search again or Press 2 to go to the Main Menu\n";
cin>>k;
switch(k)
{case 1:goto go;
case 2:main();
default:main();
}
}}
else if(v==3)
{ifstream f1("AUTOMOBILE.DAT",ios::binary);
ofstream f2("temp.dat",ios::binary);
cout<<"\nEnter the colour\n";
gets(c);
while(f1.read((char*)&C,sizeof(C)))
{ if(strcmp(c,C.getcolour())==0)
{ flag=1;
f2.write((char*)&C,sizeof(C));
C.output();}}
f1.close();
f2.close();
if (flag==1)
book();
if (flag==0)
{cout<<"The Car you have searched for is currently unavailable\n";
cout<<"Press 1 to search again or Press 2 to go to the Main Menu\n";
cin>>k;
switch(k)
{case 1:goto go;
case 2:main();
}}}
else
{cout<<"Please enter a valid option. You will be redirected to the user
menu .\n";
user();}
}
void book()
{
int code,pos,w=0,flag=0;
select:
cout<<"Enter the Car Code of the car you want to book:";
cin>>code;
fstream f2("AUTOMOBILE.DAT",ios::binary|ios::in|ios::out);
fstream f1("temp.dat",ios::binary|ios::in|ios::out);
while(f1.read((char*)&C,sizeof(C)))
{
if(strcmp(C.status,"UNAVAILABLE")!=0)
if(C.getcode()==code)
{flag=1;
cout<<"\n\t\t\tCongratulations.\n";w=1;
cout<<"You have booked: \n";C.output();
cout<<"\nPlease contact our office for further instructions regarding the
booking\n\n\n";
while(f2)
{pos=f2.tellg();
f2.read((char*)&C,sizeof(C));
if(C.getcode()==code)
{C.avb--;
f2.seekg(pos);
f2.write((char*)&C,sizeof(C));
}}f2.close();
mod();cout<<"\t\t\tAVAILABILITY LIST\n\n\n";
display();}}
if(flag==0)
{cout<<"This Car is Currently unavailable.\n\n";
user();}

if(w==0)
{cout<<"Please Select a car from the above list\n";goto select;}
f1.close();
}

void refresh()
{int d;
cout<<"\nThis option will let you delete all records where the status is
UNAVAILABLE\nWould you like to continue(1-Yes)\n";
cin>>d;
switch(d)
{case 1 :delete2();break;
default:main();
}}

void append()
{
ofstream f1("AUTOMOBILE.DAT",ios::binary|ios::app);
char ans='y';
while(ans=='y' || ans=='Y')
{
C.input();

f1.write((char *)&C, sizeof(C));


cout<<"Data appended successfully..!!\n";
cout<<"\nWould you like to enter more ? (y/n)";
cin>>ans;
}

f1.close();}

void createrecords()
{char c;
ofstream f1("AUTOMOBILE.DAT",ios::binary);
do { C.input();
f1.write((char *) & C,sizeof(C));
cout<<"Do you want to add one more record?\n";
cout<<"y-for Yes\nn-for No\n";
cin>>c; }while(c=='y'||c=='Y');
f1.close();
}

void mod()
{int code,pos;
fstream f1("AUTOMOBILE.DAT",ios::in|ios::out|ios::binary);
while(f1)
{pos=f1.tellg();
f1.read((char*)&C,sizeof(C));
if(C.avb==0)
{strcpy(C.status,"UNAVAILABLE");
f1.seekg(pos);
f1.write((char*)&C,sizeof(C));
}}f1.close();
}

void delete2()
{
ofstream f2 ("temporary.dat",ios::binary);
ifstream f1("AUTOMOBILE.DAT",ios::binary);

while(f1.read((char*)&C,sizeof(C)))
{if(strcmp(C.status,"UNAVAILABLE")!=0)
{f2.write((char*)&C,sizeof(C));} }
f1.close();
f2.close();
remove("AUTOMOBILE.DAT");
rename("temporary.dat","AUTOMOBILE.DAT");
}

void display()
{
ifstream f1("AUTOMOBILE.DAT",ios::binary);
f1.seekg(0);
while(f1.read((char*)&C,sizeof(C)))
{
C.output();}
f1.close();}
void delete1()
{int cc;
ofstream f2 ("temporary.dat",ios::binary);
ifstream f1("AUTOMOBILE.DAT",ios::binary);
cout<<"Enter the Car Code to be deleted:";
cin>>cc;
while(f1.read((char*)&C,sizeof(C)))
{if(C.getcode()!=cc)
{f2.write((char*)&C,sizeof(C));} }
f1.close();
f2.close();
remove("AUTOMOBILE.DAT");
rename("temporary.dat","AUTOMOBILE.DAT");
}

void modify()
{int code,pos;
fstream f1("AUTOMOBILE.DAT",ios::in|ios::out|ios::binary);
cout<<"Enter the Car Code of the car to be Modified:";
cin>>code;
while(f1)
{pos=f1.tellg();
f1.read((char*)&C,sizeof(C));
if(C.getcode()==code)
{C.input();
f1.seekp(pos);
f1.write((char*)&C,sizeof(C));
}}f1.close();
}

void services()
{cout<<"\nSERVICING\n";
char n[20],n1[20],m[20],d[20];
cout<<"Enter the following details:\n";
cout<<"Please enter your name:";
gets(n);
cout<<"\nEnter the Company:";
gets(n1);
cout<<"\nEnter the Car Name:";
gets(m);
cout<<"\nEnter your preferred date(dd mm yyyy)\n";
gets(d);
cout<<"\nName of owner:"<<n;
cout<<"\nCompany:"<<n1;
cout<<"\nCar:"<<m;
cout<<"\n You have been booked for servicing on :"<<d;
cout<<"\n\n";
}

void booktd()
{char n[20],n1[20],m[20],d[20];
cout<<"Enter the following details:\n";
cout<<"Please enter your name:";
gets(n);
cout<<"\n Enter the Company:\n";
gets(n1);
cout<<"Enter the Car Name:\n";
gets(m);
cout<<"\nEnter your preferred date(dd mm yyyy):\n";
gets(d);
cout<<" Your Name :"<<n;
cout<<"\n You have booked a test drive on "<<d<<"for:";
cout<<"\nCompany:"<<n1;
cout<<"\nCar Name:"<<m;
}

You might also like