Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.60 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. struct car
  5. {
  6. char brand[20];
  7. char model[30];
  8. char engine[100];
  9. char mileage[100];
  10. int passanger;
  11. float price;
  12. int id;
  13. int date;
  14. int month;
  15. int year;
  16. };
  17. struct sold
  18. {
  19. char brand[20];
  20. char model[30];
  21. float price;
  22. int date;
  23. int month;
  24. int year;
  25. };
  26.  
  27.  
  28. void admin();
  29. void visitor();
  30. void insert();
  31. void disp();
  32. void update();
  33. void delete();
  34. void si();
  35. void soi();
  36. void solddisplay();
  37. void soldsearch();
  38. void search();
  39. void compare();
  40. void system();
  41. void login();
  42. void back();
  43. void abcd();
  44. void main1();
  45.  
  46. void main()
  47. {
  48. abcd();
  49. main1();
  50. }
  51. void main1()
  52. {
  53. system("color A");
  54. system("CLS");
  55. printf("\t\t\t\t\t\t\t\n");
  56. printf("\t\t\t\t============================================\n\n");
  57. printf("\t\t\t\tWELCOME TO MY VEHICLE MANAGEMENT SYSTEM\n");
  58. printf("\t\t\t\t============================================\n\n\n\n");
  59. printf("\t\t\t\t\t\t\t\n");
  60. int y;
  61. printf("press 1 or 2\n\t1.ADMIN\n\t2.Visitor\n");
  62. printf("\n\nEnter your choise : ");
  63. scanf("%d",&y);
  64. system("CLS");
  65. switch(y)
  66. {
  67. case 1:
  68. {
  69. login();
  70. break;
  71. }
  72. case 2:
  73. {
  74. visitor();
  75. break;
  76. }
  77.  
  78. }
  79. getch();
  80.  
  81. }
  82. void abcd()
  83. {
  84. system("color A");
  85. printf("\n\n\t\t\t\t\t\tProject Name: Vehicle Management System.\n\n");
  86. printf("\n\n\t\t\t\t\t\tStudent Name: Iktear uddin\n\n");
  87. printf("\n\n\t\t\t\t\t\tID : 173-35-2250\n\n");
  88. getch();
  89. }
  90. void login()
  91. {
  92. system("CLS");
  93. printf("\t\t\t\t============================================\n\n");
  94. printf("\t\t\t\tWELCOME TO MY VEHICLE MANAGEMENT SYSTEM\n");
  95. printf("\t\t\t\t============================================\n\n\n\n");
  96. char user[10]="emon",pass[6]="123456",u[10],p[6],ch;
  97. int i,n;
  98. printf("\n Enter Username: \n\t\t");
  99. scanf("%s",&u);
  100. printf("\n Enter Your Password: \n\t\t");
  101. for(i=0; i<6; i++)
  102. {
  103. ch=getch();
  104. p[i]=ch;
  105. ch='*';
  106. printf("%c",ch);
  107. }
  108. if(strcmpi(u,user)==0)
  109. {
  110. if(strcmpi(p,pass)==0)
  111. {
  112. printf("\n\n");
  113. system("CLS");
  114. admin();
  115. }
  116. else
  117. {
  118. printf("\n\n\n\t\t\aPassword error!!!! \n");
  119. getch();
  120. main1();
  121. }
  122. }
  123. else
  124. {
  125. printf("\n\n\n\t\t\t\tUser Doesn't Exist\n");
  126. getch();
  127. main1();
  128. }
  129. }
  130. void back()
  131. {
  132. int i;
  133. printf("\nDo you want to Continue press (0) or Back (1)\n");
  134. printf("\n\nEnter your choise : ");
  135. scanf("%d",&i);
  136. system("CLS");
  137. if(i==0)
  138. {
  139. admin();
  140. }
  141. else if(i==1)
  142. {
  143. printf("\n\n\t\t\tThank You\n\n\t\t\tLOADING");
  144. main1();
  145. }
  146. else
  147. {
  148. printf("Invalid Choice\n");
  149. back();
  150. }
  151. }
  152. void backx()
  153. {
  154. int i;
  155. printf("\nDo you want to Continue press (0) or Back (1)\n");
  156. printf("\n\nEnter your choise : ");
  157. scanf("%d",&i);
  158. system("CLS");
  159. if(i==0)
  160. {
  161. visitor();
  162. }
  163. else if(i==1)
  164. {
  165. printf("\n\n\t\t\tThank You\n\n\t\t\tLOADING");
  166. main1();
  167. }
  168. else
  169. {
  170. printf("Invalid Choice\n");
  171. back();
  172. }
  173. }
  174. void admin()
  175. {
  176. printf("\t\t\t\t============================================\n\n");
  177. printf("\t\t\t\tWELCOME TO MY VEHICLE MANAGEMENT SYSTEM\n");
  178. printf("\t\t\t\t============================================\n\n\n\n");
  179. int n=0;
  180. 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");
  181. printf("\n\nEnter your choise : ");
  182. scanf("%d",&n);
  183. system("CLS");
  184. switch(n)
  185. {
  186. case 1:
  187. {
  188. insert();
  189. printf("\n\n");
  190. back();
  191. break;
  192.  
  193. }
  194. case 2:
  195. {
  196. disp();
  197. printf("\n\n");
  198. back();
  199. break;
  200. }
  201. case 3:
  202. {
  203. update();
  204. printf("\n\n");
  205. back();
  206. break;
  207. }
  208. case 4:
  209. {
  210. disp();
  211. delete();
  212. printf("\n\n");
  213. back();
  214. break;
  215. }
  216. case 5:
  217. {
  218. si();
  219. printf("\n\n");
  220. back();
  221. break;
  222. }
  223. case 6:
  224. {
  225. soi();
  226. printf("\n\n");
  227. back();
  228. break;
  229. }
  230. default :
  231. {
  232. printf("\n\n\n\t\t\tInvalid input\n\t\t");
  233. }
  234. }
  235. }
  236.  
  237. void si()
  238. {
  239. struct sold s;
  240. struct car ca;
  241. char model[10];
  242. disp();
  243. printf("\n\nfrom avobe list which model you have sold");
  244. scanf("%s",&model);
  245. system("CLS");
  246. FILE *fp;
  247. fp=fopen("CarDetails.txt","r");
  248. while(fread(&ca,sizeof(ca),1,fp))
  249. {
  250. if(strcmpi(ca.model,model)==0)
  251. {
  252. 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);
  253. }
  254. }
  255. FILE *fp1;
  256. fp1=fopen("sold.txt","a");
  257. printf("\n\nNow Enter Your Sold car Data\n\n");
  258. printf("Enter The Brand name: \n");
  259. scanf("%s",&s.brand);
  260. printf("Enter Model number : \n");
  261. scanf("%s",&s.model);
  262. printf("Enter Price of the car in BDT :\n");
  263. scanf("%f",&s.price);
  264. printf("Enter sell Date :");
  265. scanf("%d",&s.date);
  266. printf("month :");
  267. scanf("%d",&s.month);
  268. printf("year :");
  269. scanf("%d",&s.year);
  270. printf("The record is successfully added");
  271. fwrite(&s,sizeof(s),1,fp1);
  272. fclose(fp);
  273. fclose(fp1);
  274. }
  275. void soi()
  276. {
  277. printf("\nchoose one\n\n 1. display all sold car details.\n 2. search sold model by date.\n\n");
  278. int y;
  279. scanf("%d",&y);
  280. switch(y)
  281. {
  282. case 1:
  283. {
  284. solddisplay();
  285. break;
  286. }
  287. case 2:
  288. {
  289. soldsearch();
  290. break;
  291. }
  292. default :
  293. {
  294. printf("\n\n\n\t\t\tInvalid input\n\t\t");
  295. }
  296.  
  297. }
  298. }
  299. void solddisplay()
  300. {
  301. struct sold s;
  302. FILE *fp;
  303. fp=fopen("sold.txt","r");
  304. while(fread(&s,sizeof(s),1,fp))
  305. {
  306. 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);
  307. }
  308. fclose(fp);
  309. }
  310. void soldsearch()
  311. {
  312. struct sold s;
  313. char another;
  314. int d,m,y;
  315. another='y';
  316. while(another== 'y')
  317. {
  318. printf("Enter date : \n");
  319. scanf("%d",&d);
  320. printf("Enter month : \n");
  321. scanf("%d",&m);
  322. printf("Enter year : \n");
  323. scanf("%d",&y);
  324. FILE *fp;
  325. fp=fopen("sold.txt","r");
  326. while(fread(&s,sizeof(s),1,fp))
  327. if(s.date==d && s.month==m && s.year==y)
  328. {
  329. 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);
  330. }
  331. printf("\nwant to search again? (y/n) : \n\n");
  332. fflush(stdin);
  333. another=getch();
  334. fclose(fp);
  335. }
  336. }
  337. void insert()
  338. {
  339. char another;
  340. struct car ca;
  341. another='y';
  342. while(another== 'y')
  343. {
  344. FILE *fp;
  345. fp=fopen("CarDetails.txt","a");
  346. printf("Enter The Brand name: \n");
  347. scanf("%s",&ca.brand);
  348. printf("Enter Model number : \n");
  349. scanf("%s",&ca.model);
  350. printf("Enter engine details : \n");
  351. scanf("%s",&ca.engine);
  352. printf("Enter mileage : \n");
  353. scanf("%s",&ca.mileage);
  354. printf("Enter passanger capacity :\n");
  355. scanf("%d",&ca.passanger);
  356. printf("Enter Price of the car in BDT :\n");
  357. scanf("%f",&ca.price);
  358. printf("The record is successfully added");
  359. fwrite(&ca,sizeof(ca),1,fp);
  360. printf("\nDo you want to insert more car date? (y/n) : \n\n");
  361. fflush(stdin);
  362. another=getch();
  363. fclose(fp);
  364. }
  365. }
  366. void disp()
  367. {
  368. struct car ca;
  369. FILE *fp;
  370. fp=fopen("CarDetails.txt","r");
  371. while(fread(&ca,sizeof(ca),1,fp))
  372. {
  373. 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);
  374. }
  375. fclose(fp);
  376. }
  377. void update()
  378. {
  379. char another;
  380. struct car ca;
  381. char nm[30];
  382. FILE *fp;
  383. fp = fopen("CarDetails.txt","r+");
  384. another='y';
  385. while(another== 'y')
  386. {
  387. printf("enter the model name you want to modify : ");
  388. scanf("%s",nm);
  389. system("CLS");
  390. rewind(fp);
  391. while(fread(&ca,sizeof(ca),1,fp))
  392. {
  393. if(strcmpi(ca.model,nm) == 0)
  394. {
  395.  
  396. printf("\n\nEnter The Brand name: \n");
  397. scanf("%s",&ca.brand);
  398. printf("Enter Model number : \n");
  399. scanf("%s",&ca.model);
  400. printf("Enter engine details : \n");
  401. scanf("%s",&ca.engine);
  402. printf("Enter mileage : \n");
  403. scanf("%s",&ca.mileage);
  404. printf("Enter passanger capacity :\n");
  405. scanf("%d",&ca.passanger);
  406. printf("Enter Price of the car in BDT :\n");
  407. scanf("%f",&ca.price);
  408. fseek(fp,-sizeof(ca),SEEK_CUR);
  409. fwrite(&ca,sizeof(ca),1,fp);
  410. break;
  411. }
  412. }
  413. printf("\nmodify another record(y/n)\n\n");
  414. fflush(stdin);
  415. another=getch();
  416. }
  417. fclose(fp);
  418. }
  419. void delete ()
  420. {
  421. FILE *fp,*fp1;
  422. struct car ca;
  423. int found=0,count=0;
  424. char model[100];
  425. char another;
  426. another='y';
  427. while(another== 'y')
  428. {
  429. fp=fopen("CarDetails.txt","r");
  430. fp1=fopen("tempr.txt","w");
  431. printf("\n\n\nenter the product model number that you want to delete : ");
  432. scanf("%s",&model);
  433. system("CLS");
  434. while(1)
  435. {
  436. fread(&ca,sizeof(ca),1,fp);
  437. if(feof(fp))
  438. {
  439. break;
  440. }
  441. if(strcmpi(ca.model,model)==0)
  442. {
  443. found=1;
  444. }
  445. else
  446. {
  447. fwrite(&ca,sizeof(ca),1,fp1);
  448. }
  449. }
  450. fclose(fp);
  451. fclose(fp1);
  452. if(found==0)
  453. {
  454. printf("\n\nsorry no record found\n\n");
  455. }
  456. else
  457. {
  458. fp=fopen("CarDetails.txt","w");
  459. fp1=fopen("tempr.txt","r");
  460. while(1)
  461. {
  462. fread(&ca,sizeof(ca),1,fp1);
  463. if(feof(fp1))
  464. {
  465. break;
  466. }
  467. fwrite(&ca,sizeof(ca),1,fp);
  468. }
  469. }
  470. printf("\n\nData Deleted\n\n");
  471. printf("\nDo you want to delete more? (y/n) : \n\n");
  472. fflush(stdin);
  473. another=getch();
  474. fclose(fp);
  475. fclose(fp1);
  476. }
  477. }
  478. void visitor()
  479. {
  480. int z;
  481. printf("Press 1 or 2\n\t1.vehicle specifications\n\t2.Compare vehicles\n");
  482. printf("\n\nEnter your choise : ");
  483. scanf("%d",&z);
  484. system("CLS");
  485. switch(z)
  486. {
  487. case 1:
  488. {
  489. search();
  490. backx();
  491. break;
  492. }
  493. case 2:
  494. {
  495. compare();
  496. backx();
  497. break;
  498. }
  499. default :
  500. {
  501. printf("\n\n\n\t\t\tInvalid number\n\t\t");
  502. }
  503. }
  504. }
  505. void search()
  506. {
  507. struct car ca;
  508. char another;
  509. char model[10];
  510. another='y';
  511. while(another== 'y')
  512. {
  513. printf("Enter Which model you want so see : \n");
  514. scanf("%s",&model);
  515. system("CLS");
  516. FILE *fp;
  517. fp=fopen("CarDetails.txt","r");
  518. while(fread(&ca,sizeof(ca),1,fp))
  519. if(strcmpi(ca.model,model)==0)
  520. {
  521. 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);
  522.  
  523. }
  524. printf("\nwnat to see any other model?? (y/n) : \n\n");
  525. fflush(stdin);
  526. another=getch();
  527. fclose(fp);
  528. }
  529. }
  530. void compare()
  531. {
  532. struct car ca;
  533. double a,b;
  534. char model[10],model1[10];
  535. char another;
  536. another='y';
  537. while(another== 'y')
  538. {
  539. printf("Enter the first car model number : \n");
  540. scanf("%s",&model);
  541. printf("Enter the second car model number : \n");
  542. scanf("%s",&model1);
  543. FILE *fp;
  544. fp=fopen("CarDetails.txt","r");
  545. while(fread(&ca,sizeof(ca),1,fp))
  546. {
  547. if(strcmpi(ca.model,model)==0)
  548. {
  549. 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);
  550. b=ca.price;
  551. }
  552. else if(strcmpi(ca.model,model1)==0)
  553. {
  554. 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);
  555. b=ca.price;
  556. }
  557. }
  558. if (a>b)
  559. {
  560. printf("\n\n\t\t\t\tas per our research first car is better then second car\n");
  561. }
  562. else if (a<b)
  563. {
  564. printf("\n\n\t\t\t\tas per our research second car is better then first car\n");
  565. }
  566. printf("\n do you want to see another comparison? (y/n) : \n\n");
  567. fflush(stdin);
  568. another=getch();
  569. fclose(fp);
  570. }
  571. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement