Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- struct car
- {
- char brand[20];
- char model[30];
- char engine[100];
- char mileage[100];
- int passanger;
- float price;
- int id;
- int date;
- int month;
- int year;
- };
- struct sold
- {
- char brand[20];
- char model[30];
- float price;
- int date;
- int month;
- int year;
- };
- void admin();
- void visitor();
- void insert();
- void disp();
- void update();
- void delete();
- void si();
- void soi();
- void solddisplay();
- void soldsearch();
- void search();
- void compare();
- void system();
- void login();
- void back();
- void abcd();
- void main1();
- void main()
- {
- abcd();
- main1();
- }
- void main1()
- {
- system("color A");
- system("CLS");
- printf("\t\t\t\t\t\t\t\n");
- printf("\t\t\t\t============================================\n\n");
- printf("\t\t\t\tWELCOME TO MY VEHICLE MANAGEMENT SYSTEM\n");
- printf("\t\t\t\t============================================\n\n\n\n");
- printf("\t\t\t\t\t\t\t\n");
- int y;
- printf("press 1 or 2\n\t1.ADMIN\n\t2.Visitor\n");
- printf("\n\nEnter your choise : ");
- scanf("%d",&y);
- system("CLS");
- switch(y)
- {
- case 1:
- {
- login();
- break;
- }
- case 2:
- {
- visitor();
- break;
- }
- }
- getch();
- }
- void abcd()
- {
- system("color A");
- printf("\n\n\t\t\t\t\t\tProject Name: Vehicle Management System.\n\n");
- printf("\n\n\t\t\t\t\t\tStudent Name: Iktear uddin\n\n");
- printf("\n\n\t\t\t\t\t\tID : 173-35-2250\n\n");
- getch();
- }
- void login()
- {
- system("CLS");
- printf("\t\t\t\t============================================\n\n");
- printf("\t\t\t\tWELCOME TO MY VEHICLE MANAGEMENT SYSTEM\n");
- printf("\t\t\t\t============================================\n\n\n\n");
- char user[10]="emon",pass[6]="123456",u[10],p[6],ch;
- int i,n;
- printf("\n Enter Username: \n\t\t");
- scanf("%s",&u);
- printf("\n Enter Your Password: \n\t\t");
- for(i=0; i<6; i++)
- {
- ch=getch();
- p[i]=ch;
- ch='*';
- printf("%c",ch);
- }
- if(strcmpi(u,user)==0)
- {
- if(strcmpi(p,pass)==0)
- {
- printf("\n\n");
- system("CLS");
- admin();
- }
- else
- {
- printf("\n\n\n\t\t\aPassword error!!!! \n");
- getch();
- main1();
- }
- }
- else
- {
- printf("\n\n\n\t\t\t\tUser Doesn't Exist\n");
- getch();
- main1();
- }
- }
- void back()
- {
- int i;
- printf("\nDo you want to Continue press (0) or Back (1)\n");
- printf("\n\nEnter your choise : ");
- scanf("%d",&i);
- system("CLS");
- if(i==0)
- {
- admin();
- }
- else if(i==1)
- {
- printf("\n\n\t\t\tThank You\n\n\t\t\tLOADING");
- main1();
- }
- else
- {
- printf("Invalid Choice\n");
- back();
- }
- }
- void backx()
- {
- int i;
- printf("\nDo you want to Continue press (0) or Back (1)\n");
- printf("\n\nEnter your choise : ");
- scanf("%d",&i);
- system("CLS");
- if(i==0)
- {
- visitor();
- }
- else if(i==1)
- {
- printf("\n\n\t\t\tThank You\n\n\t\t\tLOADING");
- main1();
- }
- else
- {
- printf("Invalid Choice\n");
- back();
- }
- }
- void admin()
- {
- printf("\t\t\t\t============================================\n\n");
- printf("\t\t\t\tWELCOME TO MY VEHICLE MANAGEMENT SYSTEM\n");
- printf("\t\t\t\t============================================\n\n\n\n");
- int n=0;
- printf("\nchoose one\n1.Insert vehicle data\n2.Display vehicle data \n3.Update vehicle data \n4.Delete vehicle data \n5.sell info insert\n6.sold vehicle details \n");
- printf("\n\nEnter your choise : ");
- scanf("%d",&n);
- system("CLS");
- switch(n)
- {
- case 1:
- {
- insert();
- printf("\n\n");
- back();
- break;
- }
- case 2:
- {
- disp();
- printf("\n\n");
- back();
- break;
- }
- case 3:
- {
- update();
- printf("\n\n");
- back();
- break;
- }
- case 4:
- {
- disp();
- delete();
- printf("\n\n");
- back();
- break;
- }
- case 5:
- {
- si();
- printf("\n\n");
- back();
- break;
- }
- case 6:
- {
- soi();
- printf("\n\n");
- back();
- break;
- }
- default :
- {
- printf("\n\n\n\t\t\tInvalid input\n\t\t");
- }
- }
- }
- void si()
- {
- struct sold s;
- struct car ca;
- char model[10];
- disp();
- printf("\n\nfrom avobe list which model you have sold");
- scanf("%s",&model);
- system("CLS");
- FILE *fp;
- fp=fopen("CarDetails.txt","r");
- while(fread(&ca,sizeof(ca),1,fp))
- {
- if(strcmpi(ca.model,model)==0)
- {
- printf("\nBrand : %s\nModel : %s\nengine : %s\nMileage : %s\npassanger_capacity : %d\nPrice : %.2f\n",ca.brand,ca.model,ca.engine,ca.mileage,ca.passanger,ca.price);
- }
- }
- FILE *fp1;
- fp1=fopen("sold.txt","a");
- printf("\n\nNow Enter Your Sold car Data\n\n");
- printf("Enter The Brand name: \n");
- scanf("%s",&s.brand);
- printf("Enter Model number : \n");
- scanf("%s",&s.model);
- printf("Enter Price of the car in BDT :\n");
- scanf("%f",&s.price);
- printf("Enter sell Date :");
- scanf("%d",&s.date);
- printf("month :");
- scanf("%d",&s.month);
- printf("year :");
- scanf("%d",&s.year);
- printf("The record is successfully added");
- fwrite(&s,sizeof(s),1,fp1);
- fclose(fp);
- fclose(fp1);
- }
- void soi()
- {
- printf("\nchoose one\n\n 1. display all sold car details.\n 2. search sold model by date.\n\n");
- int y;
- scanf("%d",&y);
- switch(y)
- {
- case 1:
- {
- solddisplay();
- break;
- }
- case 2:
- {
- soldsearch();
- break;
- }
- default :
- {
- printf("\n\n\n\t\t\tInvalid input\n\t\t");
- }
- }
- }
- void solddisplay()
- {
- struct sold s;
- FILE *fp;
- fp=fopen("sold.txt","r");
- while(fread(&s,sizeof(s),1,fp))
- {
- printf("\nBrand : %s\nModel : %s\nPrice : %.2f\nsold date : %d-%d-%d\n\n",s.brand,s.model,s.price,s.date,s.month,s.year);
- }
- fclose(fp);
- }
- void soldsearch()
- {
- struct sold s;
- char another;
- int d,m,y;
- another='y';
- while(another== 'y')
- {
- printf("Enter date : \n");
- scanf("%d",&d);
- printf("Enter month : \n");
- scanf("%d",&m);
- printf("Enter year : \n");
- scanf("%d",&y);
- FILE *fp;
- fp=fopen("sold.txt","r");
- while(fread(&s,sizeof(s),1,fp))
- if(s.date==d && s.month==m && s.year==y)
- {
- printf("\nBrand : %s\nModel : %s\nPrice : %.2f\nsold date : %d-%d-%d\n\n",s.brand,s.model,s.price,s.date,s.month,s.year);
- }
- printf("\nwant to search again? (y/n) : \n\n");
- fflush(stdin);
- another=getch();
- fclose(fp);
- }
- }
- void insert()
- {
- char another;
- struct car ca;
- another='y';
- while(another== 'y')
- {
- FILE *fp;
- fp=fopen("CarDetails.txt","a");
- printf("Enter The Brand name: \n");
- scanf("%s",&ca.brand);
- printf("Enter Model number : \n");
- scanf("%s",&ca.model);
- printf("Enter engine details : \n");
- scanf("%s",&ca.engine);
- printf("Enter mileage : \n");
- scanf("%s",&ca.mileage);
- printf("Enter passanger capacity :\n");
- scanf("%d",&ca.passanger);
- printf("Enter Price of the car in BDT :\n");
- scanf("%f",&ca.price);
- printf("The record is successfully added");
- fwrite(&ca,sizeof(ca),1,fp);
- printf("\nDo you want to insert more car date? (y/n) : \n\n");
- fflush(stdin);
- another=getch();
- fclose(fp);
- }
- }
- void disp()
- {
- struct car ca;
- FILE *fp;
- fp=fopen("CarDetails.txt","r");
- while(fread(&ca,sizeof(ca),1,fp))
- {
- printf("\nBrand : %s\nModel : %s\nengine : %s\nMileage : %s\npassanger_capacity : %d\nPrice : %.2f\n",ca.brand,ca.model,ca.engine,ca.mileage,ca.passanger,ca.price);
- }
- fclose(fp);
- }
- void update()
- {
- char another;
- struct car ca;
- char nm[30];
- FILE *fp;
- fp = fopen("CarDetails.txt","r+");
- another='y';
- while(another== 'y')
- {
- printf("enter the model name you want to modify : ");
- scanf("%s",nm);
- system("CLS");
- rewind(fp);
- while(fread(&ca,sizeof(ca),1,fp))
- {
- if(strcmpi(ca.model,nm) == 0)
- {
- printf("\n\nEnter The Brand name: \n");
- scanf("%s",&ca.brand);
- printf("Enter Model number : \n");
- scanf("%s",&ca.model);
- printf("Enter engine details : \n");
- scanf("%s",&ca.engine);
- printf("Enter mileage : \n");
- scanf("%s",&ca.mileage);
- printf("Enter passanger capacity :\n");
- scanf("%d",&ca.passanger);
- printf("Enter Price of the car in BDT :\n");
- scanf("%f",&ca.price);
- fseek(fp,-sizeof(ca),SEEK_CUR);
- fwrite(&ca,sizeof(ca),1,fp);
- break;
- }
- }
- printf("\nmodify another record(y/n)\n\n");
- fflush(stdin);
- another=getch();
- }
- fclose(fp);
- }
- void delete ()
- {
- FILE *fp,*fp1;
- struct car ca;
- int found=0,count=0;
- char model[100];
- char another;
- another='y';
- while(another== 'y')
- {
- fp=fopen("CarDetails.txt","r");
- fp1=fopen("tempr.txt","w");
- printf("\n\n\nenter the product model number that you want to delete : ");
- scanf("%s",&model);
- system("CLS");
- while(1)
- {
- fread(&ca,sizeof(ca),1,fp);
- if(feof(fp))
- {
- break;
- }
- if(strcmpi(ca.model,model)==0)
- {
- found=1;
- }
- else
- {
- fwrite(&ca,sizeof(ca),1,fp1);
- }
- }
- fclose(fp);
- fclose(fp1);
- if(found==0)
- {
- printf("\n\nsorry no record found\n\n");
- }
- else
- {
- fp=fopen("CarDetails.txt","w");
- fp1=fopen("tempr.txt","r");
- while(1)
- {
- fread(&ca,sizeof(ca),1,fp1);
- if(feof(fp1))
- {
- break;
- }
- fwrite(&ca,sizeof(ca),1,fp);
- }
- }
- printf("\n\nData Deleted\n\n");
- printf("\nDo you want to delete more? (y/n) : \n\n");
- fflush(stdin);
- another=getch();
- fclose(fp);
- fclose(fp1);
- }
- }
- void visitor()
- {
- int z;
- printf("Press 1 or 2\n\t1.vehicle specifications\n\t2.Compare vehicles\n");
- printf("\n\nEnter your choise : ");
- scanf("%d",&z);
- system("CLS");
- switch(z)
- {
- case 1:
- {
- search();
- backx();
- break;
- }
- case 2:
- {
- compare();
- backx();
- break;
- }
- default :
- {
- printf("\n\n\n\t\t\tInvalid number\n\t\t");
- }
- }
- }
- void search()
- {
- struct car ca;
- char another;
- char model[10];
- another='y';
- while(another== 'y')
- {
- printf("Enter Which model you want so see : \n");
- scanf("%s",&model);
- system("CLS");
- FILE *fp;
- fp=fopen("CarDetails.txt","r");
- while(fread(&ca,sizeof(ca),1,fp))
- if(strcmpi(ca.model,model)==0)
- {
- printf("\nBrand : %s\nModel : %s\nengine : %s\nMileage : %s\npassanger_capacity : %d\nPrice : %.2f\n",ca.brand,ca.model,ca.engine,ca.mileage,ca.passanger,ca.price);
- }
- printf("\nwnat to see any other model?? (y/n) : \n\n");
- fflush(stdin);
- another=getch();
- fclose(fp);
- }
- }
- void compare()
- {
- struct car ca;
- double a,b;
- char model[10],model1[10];
- char another;
- another='y';
- while(another== 'y')
- {
- printf("Enter the first car model number : \n");
- scanf("%s",&model);
- printf("Enter the second car model number : \n");
- scanf("%s",&model1);
- FILE *fp;
- fp=fopen("CarDetails.txt","r");
- while(fread(&ca,sizeof(ca),1,fp))
- {
- if(strcmpi(ca.model,model)==0)
- {
- printf("\nBrand : %s\nModel : %s\nengine : %s\nMileage : %s\npassanger_capacity : %d\nPrice : %.2f\n",ca.brand,ca.model,ca.engine,ca.mileage,ca.passanger,ca.price);
- b=ca.price;
- }
- else if(strcmpi(ca.model,model1)==0)
- {
- printf("\nBrand : %s\nModel : %s\nengine : %s\nMileage : %s\npassanger_capacity : %d\nPrice : %.2f\n",ca.brand,ca.model,ca.engine,ca.mileage,ca.passanger,ca.price);
- b=ca.price;
- }
- }
- if (a>b)
- {
- printf("\n\n\t\t\t\tas per our research first car is better then second car\n");
- }
- else if (a<b)
- {
- printf("\n\n\t\t\t\tas per our research second car is better then first car\n");
- }
- printf("\n do you want to see another comparison? (y/n) : \n\n");
- fflush(stdin);
- another=getch();
- fclose(fp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement