Car Rental Management System:
In the following program, add the following concepts : 1-Inheritance 2-virtual functions or operator overloading also do multi-filing.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;
class car { int no; char name[30]; char color[10]; int distance; int price; public: int distance1() { return distance; } void copy(int r,car ob2) { strcpy(name,ob2.name); no=ob2.no; strcpy(color,ob2.color); distance=ob2.distance+r; price=ob2.price; } int namec(char name1[30]) { if(strcmpi(name,name1)) return 1; else return 0; } int reno() { return no; } void display1() { cout<>no; cout<<"NAME:"; cin>>name; cout<<"COLOUR:"; cin>>color; cout<<"DISTANCE:"; cin>>distance; cout<<"PRICE PER DAY:"; cin>>price; } }ob1; class info { char name[20]; int age,carno; char adress[30]; long number; int days; public: int namec(char name1[30]) { if(strcmpi(name,name1)) return 1; else return 0; } void input(int n) { cout<<" ENTER THE NAME: "; cin>>name; cout<<" ENTER THE AGE: "; cin>>age; if(age<18) { cout<<" YOU ARE UNDERAGE THEREBY NOT ALLOWED TO DRIVE"; getch(); exit(0); } cout<<" ENTER THE ADRESS: "; cin>>adress; cout<<" ENTER THE PHONE NUMBER: "; cin>>number; carno=n; cout<<" INPUT THE NO OF DAYS: "; cin>>days; } void display3() { cout< ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// void modify(int no,int t=0) { char b[10]; char a[30]; if(t==0) { strcpy(b,"ob2"); strcpy(a,"info.dat"); } else if(t==1||t==11) { strcpy(b,"ob1"); strcpy(a,"sports.dat"); } else if(t==2||t==22) { strcpy(b,"ob1"); strcpy(a,"leisure.dat"); } else if(t==3||t==33) { strcpy(b,"ob1"); strcpy(a,"suv.dat"); } ofstream filin("sefault.dat",ios::binary); ifstream filout(a,ios::binary); if(t!=0) { while(filout.read((char *)&ob1,sizeof(ob1))) if(ob1.reno()!=no) { filin.write((char *)&ob1,sizeof(ob1)); } } else while(filout.read((char *)&ob2,sizeof(ob2))) if(ob2.cno()!=no) filin.write((char *)&ob2,sizeof(ob2)); filin.close(); filout.close(); remove(a); //the problem is here rename("sefault.dat",a); if(t==1||t==2||t==3) { ofstream filin1("sefault.dat",ios::binary|ios::app); ifstream filout1("!!cars.dat",ios::binary); while(filout1.read((char *)&ob1,sizeof(ob1))) if(ob1.reno()!=no) filin1.write((char *)&ob1,sizeof(ob1)); filin1.close(); filout1.close(); remove("!!cars.dat"); rename("sefault.dat","!!cars.dat"); } } void display(char nameofcar[],int t=0) { ifstream filin(nameofcar,ios::binary); cout<>no; ifstream filin("info.dat",ios::binary); while(filin.read((char*)&ob2,sizeof(ob2))) if(ob2.cno()==no) { cout<<"WHAT TYPE OF CAR DID YOU RENT"; cout<<" 1.SPORTS CAR"; cout<<" 2.LEISURA CAR"; cout<<" 3.SUV"; int op2; cout<<" ENTER YOUR OPTION:"; cin>>op2; int distance; cout<<" ENTER THE DISTANCE TRAVELLED:"; cin>>distance; int n1=ob2.cno(); char ab[20]; switch(op2) { case 1: display("sports.dat",n1); strcpy(ab,"sports.dat"); break; case 2: display("leisure.dat",n1); strcpy(ab,"leisure.dat"); break; case 3: display("suv.dat",n1); strcpy(ab,"suv.dat"); break; } int r; filin.close(); car ob3; ofstream filin1(ab,ios::binary|ios::app); ifstream filin2("!!cars.dat",ios::binary); while(filin2.read((char *)&ob1,sizeof(ob1))) { cout<<"inside if"; getch(); if(ob1.reno()==no) { ob3.copy(distance,ob1); filin1.write((char *)&ob3,sizeof(ob3)); } } filin1.close(); filin2.close(); modify(no); } else { filin.close(); cout<<"INVALID NO"; getch(); goto top; } } void rent(char nameofcar[30]) { nor: system("cls"); int no; int t=0; display(nameofcar); cout<<" INPUT THE CAR NO:"; cin>>no; ifstream filin(nameofcar,ios::binary); while(filin.read((char *)&ob1,sizeof(ob1))) if(ob1.reno()==no) { system("cls"); display(nameofcar,no); t=1; cout<<" "; ob2.input(no); ofstream file("info.dat",ios::app|ios::binary); file.write((char *)&ob2,sizeof(ob2)); file.close(); int n; if(strcmpi(nameofcar,"sports.dat")==0) n=11; else if(strcmpi(nameofcar,"leisure.dat")==0) n=22; else n=33; modify(no,n); } if(t==0) { cout<<" INVALID NO"; getch(); goto nor; } filin.close(); getch(); system("cls"); } void display2() { cout<>option; system("cls"); cout<<" "; switch(option) { case 1: { int n; char namecar1[30]; cout<<"NO OF CARS TO BE INPUTED: "; cin>>n; cout<<" ENTER THE TYPE OF CAR: "; cout<<" 1.SPORTS CAR"; cout<<" 2.LEISURE CAR"; cout<<" 3.SUV"; int op3; cout<<" ENTER YOUR OPTION: "; cin>>op3; system("cls"); cout<<" "; switch(op3) { case 1: strcpy(namecar1,"sports.dat"); break; case 2: strcpy(namecar1,"leisure.dat"); break; case 3: strcpy(namecar1,"suv.dat"); break; } ofstream filin(namecar1,ios::binary|ios::app); ofstream filin2("!!cars.dat",ios::binary|ios::app); for(int i=0;i>op3; system("cls"); cout<<" "; char namecar1[30]; switch(op3) { case 1: strcpy(namecar1,"sports.dat"); break; case 2: strcpy(namecar1,"leisure.dat"); break; case 3: strcpy(namecar1,"suv.dat"); } display(namecar1); cout<<" ENTER THE CAR NO:"; cin>>op3; fstream filin(namecar1,ios::binary|ios::in|ios::out); fstream filin2("!!cars.dat",ios::binary|ios::in|ios::out); while(filin.read((char *)&ob1,sizeof(ob1))) { if(ob1.reno()==op3) { ob1.input(); filin.seekp(-sizeof(ob1),ios::cur); filin.write((char *)&ob1,sizeof(ob1)); } } while(filin2.read((char *)&ob1,sizeof(ob1))) { if(ob1.reno()==op3) { ob1.input(); filin2.seekp(-sizeof(ob1),ios::cur); filin2.write((char *)&ob1,sizeof(ob1)); } } filin.close(); filin2.close(); } case 3: { system("cls"); cout<<" SELECT THE CAR TO BE DELETED"; cout<<" ENTER THE TYPE OF CAR: "; cout<<" 1.SPORTS CAR"; cout<<" 2.LEISURA CAR"; cout<<" 3.SUV"; int op3; cout<<" ENTER YOUR OPTION:"; cin>>op3; system("cls"); cout<<" "; char namecar1[30]; int t; switch(op3) { case 1: strcpy(namecar1,"sports.dat"); t=1; break; case 2: strcpy(namecar1,"leisure.dat"); t=2; break; case 3: strcpy(namecar1,"suv.dat"); t=3; } display(namecar1); cout<<" ENTER THE REFERENCE NO:"; int refno; cin>>refno; modify(refno,t); break; } case 4: display("!!cars.dat"); break; case 5: display2(); } } void gotoxy(int x, int y) { HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); COORD CursorPosition; CursorPosition.X = x; // Locates column CursorPosition.Y = y; // Locates Row SetConsoleCursorPosition(console,CursorPosition); // Sets position for next thing to be printed } void box() { char c1=178, c2=177, c3=176; gotoxy(1,2); for(int i=1; i<=1840; i++) { int j=0; gotoxy(j,2); cout<=79) j=0; } } void setcolor(unsigned short color) //begining of set color funtion { HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); //gets std handle SetConsoleTextAttribute(hCon,color); //Sets Console Text Attribute HCon color. } void carrental() { for(int i=0;i<=3;i++) { system("cls"); if(i==1||i==3) setcolor(1); else setcolor(0); int wait=0; while(++wait<1000000000) ; for(int i=0;i<=3;i++) { cprintf("*"); } cout<<" *"; wait=0; while(++wait<1000000000) ; } getch(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////// void main() { setcolor(2); box(); int op; do { system("cls"); setcolor(5); gotoxy(32,8); setcolor(3); setcolor(15); cprintf("WHAT DO YOU WANT TO DO:"); gotoxy(32,10); setcolor(5); cprintf(" 1.RENT A CAR "); gotoxy(32,12); setcolor(5); cprintf(" 2.RETURN A CAR "); gotoxy(32,14); setcolor(5); cprintf(" 3.EDIT "); gotoxy(33,16); cprintf(" 4.EXIT "); gotoxy(33,18); setcolor(15); cprintf(" ENTER THE OPTION: "); cin>>op; switch(op) { case 1: system("cls"); cout<<" DO YOU WANT TO RENT A:"; cout<<" 1.SPORTS CAR"; cout<<" 2.LEISURE CAR"; cout<<" 3.SUV"; int op2; cout<<" ENTER YOUR OPTION:"; cin>>op2; switch(op2) { case 1: rent("sports.dat"); break; case 2: rent("leisure.dat"); break; case 3: rent("suv.dat"); break; } break; case 2: returning(); break; case 3: creator(); getch(); break; } }while(op<=3); } void setcolor(int ForgC) { WORD wColor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi;
//We use csbi for the wAttributes word. if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) { //Mask out all but the background attribute, and add in the forgournd color wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F); SetConsoleTextAttribute(hStdOut, wColor); } return;}