Sei sulla pagina 1di 7

#include<fstream.

h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<process.h>
//****************************************************
// ALL CLASSES
//****************************************************
class menu
{
public:
void menu1();
void menu2();
void menu3();
};
//****************************************************
class showroom
{
int modelno, year;
float price;
char color[25], modeltype[25];
public:
void input();
void show();
int model();
};
//****************************************************
class purchase
{
char name[25],fname[25], date[25], address[25];
int carmodel, reg, cno;
public:
void details();
void bill();
};
//****************************************************
// DEALER MENU FUNCTIONS
//****************************************************
void dealer_create()
{
showroom cars;
fstream afile;
int num;
cout<<"Enter Number Of Models: "<<endl;
cin>>num;
afile.open("car.dat",ios::binary|ios::app);
for(int i =0; i<num;i++)
{
cars.input();
cout<<endl;
afile.write((char*)&cars,sizeof(showroom));

}
afile.close();
}
//****************************************************
void dealer_display()
{
showroom cars;
clrscr();
fstream afile;
afile.open("car.dat",ios::in|ios::binary);
if(afile==0)
cout<<"No Data. File Is Empty."<<endl;
else
{
while(afile.read((char*)&cars,sizeof(showroom)))
{
cars.show();
cout<<endl;

}
afile.close();
}
}
//****************************************************
void dealer_search()
{
int x;
showroom cars;
fstream afile;
afile.open("car.dat",ios::in|ios::binary);
cout<<"Enter Model No: "<<endl;
cin>>x;
int z=0;
while(afile.read((char*)&cars,sizeof(showroom)))
{
if(x==cars.model())
{
z=1;
cout<<endl<<"Model No Is Present";
cout<<endl;
cars.show();
cout<<endl;
}
}
if(z==0)
{
cout<<"Model No Not Present";
cout<<endl;
}
afile.close();
}
//****************************************************
void dealer_modify()
{
showroom cars;
int x;
fstream afile,tfile;
afile.open("car.dat",ios::in|ios::binary);
tfile.open("temp.dat",ios::out|ios::binary);
cout<<"Enter Model No To Edit: ";
cin>>x;
while(afile.read((char*)&cars,sizeof(showroom)))
{
if(x==cars.model())
{
cars.input();
tfile.write((char*)&cars,sizeof(showroom));
}
else
{
tfile.write((char*)&cars,sizeof(showroom));
}
}
afile.close();
tfile.close();
remove("car.dat");
rename("temp.dat","car.dat");
}
//****************************************************
void dealer_delete()
{
showroom cars;
int x;
fstream afile, tfile;
afile.open("car.dat",ios::in|ios::binary);
tfile.open("temp.dat",ios::out|ios::binary);
cout<<"Enter Model No To Be Deleted:";
cin>>x;
while(afile.read((char*)&cars,sizeof(showroom)))
{
if(x!=cars.model())
tfile.write((char*)&cars,sizeof(showroom));
}
afile.close();
tfile.close();
remove("car.dat");
rename("temp.dat","car.dat");
cout<<endl;
cout<<"Model No Deleted"<<endl<<endl;
}
//****************************************************
// CUSTOMER MENU FUNCTIONS
//****************************************************
void custom_details()
{
showroom cars;
purchase car;
fstream afile;
afile.open("car.dat",ios::in|ios::binary);
while(afile.read((char*)&cars,sizeof(showroom)))
{
cars.show();
cout<<endl;
}
afile.close();
}
//***************************************************
void custom_buy()
{
purchase car;
car.details();
car.bill();
cout<<endl;
}
//****************************************************
// MENU FUNCTION DEFINITATIONS
//****************************************************
void menu::menu1()
{
menu m;
int choice;
cout<<"\t\t\t\t===CAR PLAZA==="<<endl;
cout<<" ****************************"<<endl;
cout<<" * | | *"<<endl;
cout<<" * | | *"<<endl;
cout<<" * | | * "<<endl;
cout<<" ***----------------------------------------- ***"<<endl;
cout<<" * | | *"<<endl;
cout<<" * ***| |*** *"<<endl;
cout<<" * ********* ************** ****************"<<endl;
cout<<" * . * * . *"<<endl;
cout<<" *** *** "<<endl;
cout<<endl<<endl;
cout<<"1. Dealer's Page"<<endl<<endl;
cout<<"2. Customer's Page"<<endl<<endl;
cout<<"3. Exit"<<endl<<endl;
cout<<"\tEnter Your Choice: " ;
cin>>choice;
cout<<endl;
switch(choice)
{
case 1:
m.menu2();
break;
case 2:
m.menu3();
break;
case 3:
cout<<"Good BYE"<<endl;
exit(0);
}
}
//****************************************************
void menu::menu2()
{
menu m;
int n;
char ch='y';
while(ch=='y')
{
clrscr();
cout<<"\t\t\t===Dealer's Page==="<<endl;
cout<<endl<<endl;
cout<<"\tSelect One OF The Options: "<<endl<<endl;
cout<<"1. Create A File"<<endl<<endl;
cout<<"2. Display A File"<<endl<<endl;
cout<<"3. Search A Model"<<endl<<endl;
cout<<"4. Modify A Model"<<endl<<endl;
cout<<"5. Delete A Model"<<endl<<endl;
cout<<"6. Main Menu"<<endl<<endl;
cout<<"7. Quit"<<endl<<endl;
cout<<"\tEnter your choice: ";
cin>>n;
cout<<endl;
clrscr();
switch(n)
{
case 1:
dealer_create();
break;
case 2:
dealer_display();
break;
case 3:
dealer_search();
break;
case 4:
dealer_modify();
break;
case 5:
dealer_delete();
break;
case 6:
m.menu1();
break;
case 7:
cout<<endl<<"Have A Nice Day!"<<endl;
cout<<"Press Any Key To Continue"<<endl;
getch();
break;
}
cout<<"Do You Want To Continue With Program ? : ";
cin>>ch;
}
}
//****************************************************
void menu::menu3()
{
int n;
char ch;
menu m;
showroom cars;
purchase car;
do
{
clrscr();
cout<<"\t\t\t===CUSTOMER'S PAGE==="<<endl;
cout<<"\tSelect One Option: "<<endl;
cout<<endl<<"1.Display details"<<endl;
cout<<endl<<"2.Buy A Car"<<endl;
cout<<endl<<"3.Main Menu"<<endl;
cout<<endl<<"4.Exit"<<endl;
cout<<endl;
cout<<"\tEnter choice: ";
cin>>n;
cout<<endl;
clrscr();
switch(n)
{
case 1:
custom_details();
break;
case 2:
custom_buy();
break;
case 3:
m.menu1();
break;
case 4:
cout<<"Nice Working With You :)"<<endl;
exit(0);
break;
}
cout<<"Wish To Continue With Program?(Y/N):"<<endl;
cin>>ch;
} while(ch=='y'||ch=='Y');
}
//****************************************************
// SHOWROOM CLASS MEMBER FUNCTION'S DEFINITIONS
//****************************************************
void showroom::input()
{
clrscr();
cout<<"Enter The Following Details: ";
cout<<endl<<"Enter Model Number: ";
cin>>modelno;
cout<<endl<<"Enter Year Of manufacture: ";
cin>>year;
cout<<endl<<"Enter color: ";
gets(color);
cout<<endl<<"Enter Price: ";
cin>>price;
cout<<endl<<"Enter Model Type: ";
gets(modeltype);
}
//*****************************************************
void showroom::show()
{
cout<<endl<<"Model No Is: "<<modelno;
cout<<endl<<"Model Type Is:" <<modeltype;
cout<<endl<<"Year Of Manufacture Is: "<<year;
cout<<endl<<"Color Is : "<<color;
cout<<endl<<"Price Is: "<<price;
}
//*****************************************************
int showroom::model()
{
return modelno;
}
//****************************************************
// PURCHASE CLASS MEMBER FUNCTION'S DEFINITIONS
//****************************************************
void purchase::bill()
{
clrscr();
cout<<"\t\t\t\t====CAR PLAZA==="<<endl;
cout<<"\nCongratulations!"<<endl;
cout<<"-----------------";
cout<<endl<<"1. Name: "<<name;
cout<<endl<<"2. Father's Name: "<<fname;
cout<<endl<<"3. Address: "<<address;
cout<<endl<<"4. Contact No: "<<cno;
cout<<endl<<"5. Car Model: "<<carmodel;
cout<<endl<<"6. Registration No: "<<reg;
cout<<endl<<"7. Date Of Purchase: "<<date;
cout<<endl<<"-----------------";
}
//****************************************************
void purchase::details()
{
clrscr();
cout<<endl<<"Enter The flollowing details: ";
cout<<endl<<"Enter Name: ";
gets(name);
cout<<endl<<"Enter Father's Name: ";
gets(fname);
cout<<endl<<"Enter address: ";
gets(address);
cout<<endl<<"Enter contact No: ";
cin>>cno;
cout<<endl<<"Enter Car No: ";
cin>>carmodel;
cout<<endl<<"Enter Registration No: ";
cin>>reg;
cout<<endl<<"Enter date: ";
gets(date);
}
//****************************************************
//****************************************************
void main()
{
clrscr();
menu m;
showroom cars;
purchase car;
m.menu1();
getch();
}

Potrebbero piacerti anche