Guest User

Untitled

a guest
Jan 4th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.69 KB | None | 0 0
  1. //header files included
  2. #include <iostream.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <process.h>
  6. #include <fstream.h>
  7. #include <string.h>
  8. #include <time.h>
  9. #include <iomanip.h>
  10. #include <stdlib.h>
  11. #include <dos.h>
  12.  
  13. //streams declared
  14. fstream user_file, temp, driver;
  15.  
  16. //functions prototype declared
  17. void spaces(); //function for spaces
  18. void open_in(); //function to open file in input mode
  19. void open_out(); //function to open file in output mode
  20. void close(); //function to close files
  21. int menu(); //function to provide user menu
  22. void loading();
  23. void ride(); //function for user ride
  24. int calculation(char a[], char b[]); //function for calculation
  25. int login(); //function for user login
  26. void open_temp(); //function to open temprory files
  27. void edit(); //function to exit
  28. void taxi();
  29. void thumb();
  30. void table();
  31. void getdriver();
  32.  
  33. //classes for users
  34. class info_user
  35. {
  36. int money;
  37. public:
  38. void get()
  39. {
  40. cout << "Enter your Initial money ";
  41. cin >> money;
  42. }
  43. void credit(int m)
  44. {
  45. money += m;
  46. cout << "MONEY " << money;
  47. }
  48. void debit(int m)
  49. {
  50. if (money - m > 0)
  51. {
  52. money -= m;
  53. cout << "MONEY " << money;
  54. }
  55. else if (money - m < 0)
  56. cout << "UNABLE TO COMPLETE REQUEST ";
  57. }
  58. void dis()
  59. {
  60. cout << "Money " << money << endl;
  61. }
  62. int paise()
  63. {
  64. return money;
  65. }
  66. };
  67. class user : public info_user
  68. {
  69. char id[78];
  70. int mob_no;
  71. char name[56];
  72. int pin_code;
  73. int like;
  74. public:
  75. void registers()
  76. {
  77. system("cls");
  78. cout << "Enter username "; cin >> name;
  79. cout << "Enter mob_no"; cin >> mob_no;
  80. cout << "Enter pin code "; cin >> pin_code;
  81. cout << "Enter password "; cin >> id;
  82. info_user::get();
  83. system("cls");
  84. }
  85. void display()
  86. {
  87. system("cls");
  88. spaces(); cout << "Mob_no :: " << mob_no << endl;
  89. spaces(); cout << "Name :: " << name << endl;
  90. spaces(); cout << "Pin code :: " << pin_code << endl;
  91. spaces(); info_user::dis();
  92. }
  93. void likes()
  94. {
  95. system("cls");
  96. thumb(); cout << " X " << like;
  97. delay(700);
  98. like += 1;
  99. system("cls");
  100.  
  101. thumb(); cout << " X " << like;
  102. }
  103. int name_s(char ch[])
  104. {
  105. if (strcmp(ch, name) == 0)
  106. return 1;
  107. else
  108. return 0;
  109. }
  110. int pass_s(char ch[])
  111. {
  112. if (strcmp(ch, id) == 0)
  113. return 1;
  114. else
  115. return 0;
  116. }
  117. }us;
  118.  
  119. //class for drivers
  120. class driver
  121. {
  122. char name[45];
  123. int id;
  124. int age;
  125. int expierence;
  126. char sex[45];
  127. int day;
  128. int route;
  129. public:
  130. void calculate_route()
  131. {
  132. int maxrand = 6;
  133. srand((unsigned)time(NULL));
  134. route = rand() % maxrand + 1;
  135. }
  136. void calculate_id()
  137. {
  138. int maxrand = 999;
  139. srand((unsigned)time(NULL));
  140. id = rand() % maxrand + 1;
  141. }
  142. void get()
  143. {
  144. spaces(); cout << "Enter name "; cin >> name;
  145. spaces(); cout << "Enter Age "; cin >> age;
  146. spaces(); cout << "Enter Expierence "; cin >> expierence;
  147. spaces(); cout << "Enter Sex(M/F) "; cin >> sex;
  148. calculate_id();
  149. calculate_route();
  150. }
  151. void dis()
  152. {
  153. spaces(); cout << "Name : " << name;
  154. spaces(); cout << "Id : " << id;
  155. spaces(); cout << "Age : " << age;
  156. spaces(); cout << "Sex(M/F) : " << sex;
  157. spaces(); cout << "Route : " << route << endl << endl;
  158. spaces(); cout << "OK YOU CAN JOIN BY "; calculate_day(); cout << endl;
  159. }
  160. void calculate_day()
  161. {
  162. int maxrand = 6;
  163. srand((unsigned)time(NULL));
  164. int j = rand() % maxrand;
  165. day = j + 1;
  166. calculate_date();
  167. }
  168. void calculate_date()
  169. {
  170. if (day == 1) cout << " Monday ";
  171. else if (day == 2) cout << " Tuesday ";
  172. else if (day == 3) cout << " Wednesday ";
  173. else if (day == 4) cout << " Thrusday ";
  174. else if (day == 5) cout << " Friday ";
  175. else if (day == 6) cout << " Saturday ";
  176. }
  177. void show()
  178. {
  179. cout << setw(4) << id
  180. << setw(7) << name
  181. << setw(10) << sex
  182. << setw(13) << age
  183. << setw(16) << route << endl;
  184. }
  185. void compare(char a[])
  186. {
  187. if (strcmp(a, sex) == 0)
  188. show();
  189. }
  190. }d;
  191.  
  192. //code begins
  193. void main()
  194. {
  195. char ch;
  196. while (1)
  197. {
  198. logout:
  199. int n, k = 100, m = 100, j;
  200. loading();
  201. taxi();
  202.  
  203. system("cls"); delay(700);
  204. spaces(); cout << "1.For SIGN IN " << endl; delay(700);
  205. spaces(); cout << "2.For SIGN UP " << endl; delay(700);
  206. spaces(); cout << "3.Apply for Drivers " << endl;
  207. cout << endl << endl << endl;
  208. cout << "Your Choice :: ";
  209. cin >> n;
  210.  
  211. if (n == 1)
  212. {
  213. j = login();
  214. cout << j << endl;
  215.  
  216. if (j != 0)
  217. k = menu();
  218. else
  219. exit(0);
  220. }
  221. else if (n == 2)
  222. {
  223. open_in();
  224. us.registers();
  225. user_file.write((char*)&us, sizeof(us));
  226. close();
  227. start:
  228. m = menu();
  229. }
  230. else if (n == 3)
  231. {
  232. open_out();
  233. system("cls");
  234. spaces(); cout << "REGISTRATION FORM " << endl;
  235.  
  236. d.get();
  237. driver.write((char*)&d, sizeof(d));
  238. spaces(); cout << "You are REGISTERED !! ";
  239. system("cls");
  240. d.dis();
  241. getch();
  242. goto logout;
  243. }
  244. else exit(0);
  245.  
  246. if (m == 1 || k == 1) goto logout;
  247. else if (m == 0 || k == 0) goto start;
  248.  
  249. cout << "To use our software again press Y for yes and N for no" << endl;
  250. cin >> ch;
  251. if (ch == 'N' || ch == 'n') { break; }
  252. }
  253. getch();
  254. }
  255.  
  256.  
  257. //functions included in code
  258.  
  259. //function for spaces
  260. void spaces()
  261. {
  262. cout << endl << endl << "\t\t ";
  263. }
  264. //function for open streams
  265. void open_out()
  266. {
  267. user_file.open("user.dat", ios::app | ios::out | ios::binary);
  268. driver.open("driver.dat", ios::app | ios::out | ios::binary);
  269. }
  270. //function for input streams
  271. void open_in()
  272. {
  273. user_file.open("user.dat", ios::app | ios::in | ios::binary);
  274. driver.open("driver.dat", ios::app | ios::in | ios::binary);
  275. }
  276. //function having temporary stream
  277. void open_temp()
  278. {
  279. temp.open("temp.dat", ios::app | ios::out | ios::binary);
  280. }
  281. //function to exit streams
  282. void close()
  283. {
  284. user_file.close();
  285. temp.close();
  286. driver.close();
  287. }
  288. //function to edit streams
  289. void edit()
  290. {
  291. remove("user.dat");
  292. rename("temp.dat", "user.dat");
  293. }
  294. //function to introduce tabular data
  295. void table()
  296. {
  297. cout << setw(4) << "________________________________________________________________________" << endl;
  298. cout << setw(4) << " Id " << setw(7) << "Name " << setw(10) << "Sex " << setw(13) << "Age " << setw(16) << " route " << endl << endl;
  299. cout << setw(4) << "_______________________________________________________________________" << endl;
  300. }
  301. //function to represent likes
  302. void thumb()
  303. {
  304. cout << " _____ " << endl;
  305. cout << " \ | " << endl;
  306. cout << " | | " << endl;
  307. cout << " ____/ \___ " << endl;
  308. cout << " | " << endl;
  309. cout << " ____ / " << endl;
  310. cout << " | " << endl;
  311. cout << " ____ / " << endl;
  312. cout << " | " << endl;
  313. cout << " ____ / " << endl;
  314. cout << " | " << endl;
  315. cout << " ____ / ";
  316. }
  317. //function for intro
  318. void loading()
  319. {
  320. spaces();
  321. cout << "L "; delay(700);
  322. cout << "O "; delay(700);
  323. cout << "A "; delay(700);
  324. cout << "D "; delay(700);
  325. cout << "I "; delay(700);
  326. cout << "N "; delay(700);
  327. cout << "G "; delay(700);
  328. system("cls");
  329. spaces();
  330. cout << "L O A D I N G "; delay(700); system("cls");
  331.  
  332. for (int i = 0; i < 2; i++)
  333. {
  334. spaces(); cout << "L O A D I N G ."; delay(700); system("cls");
  335. spaces(); cout << "L O A D I N G . ."; delay(700); system("cls");
  336. spaces(); cout << "L O A D I N G . . ."; delay(700); system("cls");
  337. spaces(); cout << "L O A D I N G "; delay(400); system("cls ");
  338. }
  339. }
  340. void taxi()
  341. {
  342. system("cls");
  343. spaces();
  344. cout << "W "; delay(400);
  345. cout << "E "; delay(400);
  346. cout << "L "; delay(400);
  347. cout << "C "; delay(400);
  348. cout << "O "; delay(400);
  349. cout << "M "; delay(400);
  350. cout << "E "; delay(700);
  351. cout << endl << endl << endl;
  352.  
  353. spaces(); cout << "t "; delay(700);
  354. cout << "o "; delay(700);
  355. cout << endl << endl ;
  356. spaces();
  357. cout << "Y "; delay(400);
  358. cout << "O "; delay(400);
  359. cout << "U "; delay(400);
  360. cout << "R's "; delay(400);
  361.  
  362.  
  363. cout << "\t\t|**********|" << endl ;
  364. cout << "\t\t\t\t\t| C ";delay (400); cout << "A "; delay (400); cout << "B |"<< endl;
  365. cout << "\t\t\t\t\t|**********|" << endl << endl << endl ;
  366. cout << "Prepared by :: MAYANK DUTTA(X11-C) " << endl ;
  367. cout << "Submitted to NISHA MAM " << endl ;
  368. }
  369. //function to offer choice
  370. int menu()
  371. {
  372. clrscr();
  373. system("cls");
  374. int m;
  375. spaces(); cout << "1.YOUR INFO" << endl; delay(400);
  376. spaces(); cout << "2.CREDIT MONEY " << endl; delay(400);
  377. spaces(); cout << "3.DEBIT MONEY" << endl; delay(400);
  378. spaces(); cout << "4.NEW RIDE " << endl; delay(400);
  379. spaces(); cout << "5.LIKE US" << endl; delay(400);
  380. spaces(); cout << "6.VIEW OUR DRIVERS" << endl; delay(400);
  381. spaces(); cout << "7.LOG OUT" << endl; delay(400);
  382. spaces(); cout << "8.EXIT " << endl << endl << endl; delay(400);
  383. cout << "YOUR CHOICE IS :: "; cin >> m;
  384.  
  385. if (m == 1)
  386. {
  387. close(); open_in();
  388. system("cls");
  389. char password[78];
  390. int k = 0, n;
  391.  
  392. spaces(); cout << "Enter password ::"; cin >> password;
  393. //system("cls");
  394. while (!user_file.eof() && user_file.read((char*)&us, sizeof(user)))
  395. {
  396. n = us.pass_s(password);
  397. cout << n << endl;
  398. if (n == 1)
  399. {
  400. k = 0;
  401. us.display();
  402. getch();
  403. break;
  404. }
  405. else
  406. k = 1;
  407. }
  408. if (k == 1)
  409. {
  410. spaces(); cout << "ERROR "; delay(600);
  411. }
  412. close();
  413. }
  414. else if (m == 2)
  415. {
  416. close();
  417. open_in();
  418. open_temp();
  419. system("cls");
  420. char password[45];
  421. cout << "Confirm your pass.. ";
  422. cin >> password;
  423.  
  424. while (!user_file.eof() && user_file.read((char*)&us, sizeof(user)))
  425. {
  426. int n = us.pass_s(password);
  427. if (n == 1)
  428. {
  429. int money;
  430. cout << "Enter money ";
  431. cin >> money;
  432. us.credit(money);
  433. getch();
  434. temp.write((char*)&us, sizeof(us));
  435. }
  436. else
  437. temp.write((char*)&us, sizeof(us));
  438. }
  439. close();
  440. edit();
  441. }
  442. else if (m == 3)
  443. {
  444. close();
  445. open_in();
  446. open_temp();
  447. system("cls");
  448. char password[45];
  449. cout << "Confirm your pass.. ";
  450. cin >> password;
  451.  
  452. while (!user_file.eof() && user_file.read((char*)&us, sizeof(us)))
  453. {
  454. int n = us.pass_s(password);
  455. if (n == 1)
  456. {
  457. int money;
  458. cout << "Enter money ";
  459. cin >> money;
  460. us.debit(money);
  461. getch();
  462. temp.write((char*)&us, sizeof(us));
  463. }
  464. else
  465. temp.write((char*)&us, sizeof(us));
  466. }
  467. close();
  468. edit();
  469. }
  470. else if (m == 4)
  471. {
  472. ride();
  473. }
  474. else if (m == 5)
  475. {
  476. close();
  477. open_in();
  478. open_temp();
  479. system("cls");
  480. char password[45];
  481. cout << "Confirm your pass.. ";
  482. cin >> password;
  483.  
  484. while (!user_file.eof() && user_file.read((char*)&us, sizeof(us)))
  485. {
  486. int n = us.pass_s(password);
  487. if (n == 1)
  488. {
  489. us.likes();
  490. getch();
  491. temp.write((char*)&us, sizeof(us));
  492. }
  493. else
  494. temp.write((char*)&us, sizeof(us));
  495. }
  496. close();
  497. edit();
  498. }
  499. else if (m == 6)
  500. {
  501. close();
  502. system("cls");
  503. open_in();
  504. table();
  505. while (!driver.eof() && driver.read((char*)&d, sizeof(d)))
  506. {
  507. d.show();
  508. getch();
  509. }
  510. close();
  511. }
  512. else if (m == 7)
  513. {
  514. return 1;
  515. }
  516. else if (m == 8)
  517. {
  518. exit(0);
  519. }
  520. return 0;
  521. }
  522. //function to represent ride
  523. void ride()
  524. {
  525. system("cls");
  526.  
  527. cout << " //////////// ///////// ///////// ///////////// " << endl;
  528. cout << " //// /// /// //// /// /// " << endl;
  529. cout << " /////////// /// //// //// ///////// " << endl;
  530. cout << " // /// /// /// /// // " << endl;
  531. cout << " / //// ////////////// ////////// ///// " << endl;
  532.  
  533. system("cls");
  534.  
  535. char from[45], to[45];
  536. spaces(); cout << "FROM :: " << endl;
  537. spaces(); cout << "A ";
  538. spaces(); cout << "B ";
  539. spaces(); cout << "C ";
  540. spaces(); cout << "D ";
  541. spaces(); cout << "E ";
  542. spaces(); cout << "F ";
  543. spaces(); cout << "G ";
  544. spaces(); cout << "H " << endl << endl;
  545. cout << "YOUR CHOICE IS :: "; cin >> from; system("cls");
  546.  
  547. spaces(); cout << "TO :: " << endl << endl;
  548. spaces(); cout << "A ";
  549. spaces(); cout << "B ";
  550. spaces(); cout << "C ";
  551. spaces(); cout << "D ";
  552. spaces(); cout << "E ";
  553. spaces(); cout << "F ";
  554. spaces(); cout << "G ";
  555. spaces(); cout << "H " << endl << endl;
  556. cout << "YOUR CHOICE IS :: "; cin >> to; system("cls");
  557.  
  558. int money = calculation(from, to);
  559. int present = us.paise();
  560.  
  561. if (money <= present)
  562. {
  563. spaces(); cout << "YOUR RIDE IS SUCCESFULLY PLACED ";
  564. us.debit(money);
  565. getdriver();
  566. }
  567. else if (money > present)
  568. {
  569. spaces(); cout << "INSUFFICIENT MONEY ";
  570. }
  571. system("cls");
  572. }
  573. //function to perform calculation
  574. int calculation(char a[], char b[])
  575. {
  576. int money;
  577. if (strcmp(a, b) == 0)
  578. cout << "What non-sense ";
  579. else if (strcmp(a, "A") == 0)
  580. {
  581. if (strcmp(b, "B") == 0) money = 2;
  582. else if (strcmp(b, "C") == 0)money = 3;
  583. else if (strcmp(b, "D") == 0)money = 4;
  584. else if (strcmp(b, "E") == 0)money = 5;
  585. else if (strcmp(b, "F") == 0)money = 6;
  586. else if (strcmp(b, "G") == 0)money = 7;
  587. else if (strcmp(b, "H") == 0)money = 8;
  588. }
  589. else if (strcmp(a, "B") == 0)
  590. {
  591. if (strcmp(b, "A") == 0) money = 2;
  592. else if (strcmp(b, "C") == 0)money = 3;
  593. else if (strcmp(b, "D") == 0)money = 4;
  594. else if (strcmp(b, "E") == 0)money = 5;
  595. else if (strcmp(b, "F") == 0)money = 6;
  596. else if (strcmp(b, "G") == 0)money = 7;
  597. else if (strcmp(b, "H") == 0)money = 8;
  598. }
  599. else if (strcmp(a, "C") == 0)
  600. {
  601. if (strcmp(b, "B") == 0) money = 2;
  602. else if (strcmp(b, "A") == 0)money = 3;
  603. else if (strcmp(b, "D") == 0)money = 4;
  604. else if (strcmp(b, "E") == 0)money = 5;
  605. else if (strcmp(b, "F") == 0)money = 6;
  606. else if (strcmp(b, "G") == 0)money = 7;
  607. else if (strcmp(b, "H") == 0)money = 8;
  608. }
  609. else if (strcmp(a, "D") == 0)
  610. {
  611. if (strcmp(b, "B") == 0) money = 2;
  612. else if (strcmp(b, "C") == 0)money = 3;
  613. else if (strcmp(b, "A") == 0)money = 4;
  614. else if (strcmp(b, "E") == 0)money = 5;
  615. else if (strcmp(b, "F") == 0)money = 6;
  616. else if (strcmp(b, "G") == 0)money = 7;
  617. else if (strcmp(b, "H") == 0)money = 8;
  618. }
  619. else if (strcmp(a, "E") == 0)
  620. {
  621. if (strcmp(b, "B") == 0) money = 2;
  622. else if (strcmp(b, "C") == 0)money = 3;
  623. else if (strcmp(b, "D") == 0)money = 4;
  624. else if (strcmp(b, "A") == 0)money = 5;
  625. else if (strcmp(b, "F") == 0)money = 6;
  626. else if (strcmp(b, "G") == 0)money = 7;
  627. else if (strcmp(b, "H") == 0)money = 8;
  628. }
  629. else if (strcmp(a, "F") == 0)
  630. {
  631. if (strcmp(b, "B") == 0) money = 2;
  632. else if (strcmp(b, "C") == 0)money = 3;
  633. else if (strcmp(b, "D") == 0)money = 4;
  634. else if (strcmp(b, "E") == 0)money = 5;
  635. else if (strcmp(b, "A") == 0)money = 6;
  636. else if (strcmp(b, "G") == 0)money = 7;
  637. else if (strcmp(b, "H") == 0)money = 8;
  638. }
  639. else if (strcmp(a, "G") == 0)
  640. {
  641. if (strcmp(b, "B") == 0) money = 2;
  642. else if (strcmp(b, "C") == 0)money = 3;
  643. else if (strcmp(b, "D") == 0)money = 4;
  644. else if (strcmp(b, "E") == 0)money = 5;
  645. else if (strcmp(b, "F") == 0)money = 6;
  646. else if (strcmp(b, "A") == 0)money = 7;
  647. else if (strcmp(b, "H") == 0)money = 8;
  648. }
  649. else if (strcmp(a, "H") == 0)
  650. {
  651. if (strcmp(b, "B") == 0) money = 2;
  652. else if (strcmp(b, "C") == 0)money = 3;
  653. else if (strcmp(b, "D") == 0)money = 4;
  654. else if (strcmp(b, "E") == 0)money = 5;
  655. else if (strcmp(b, "F") == 0)money = 6;
  656. else if (strcmp(b, "G") == 0)money = 7;
  657. else if (strcmp(b, "A") == 0)money = 8;
  658. }
  659. return money;
  660. }
  661. //function for login
  662. int login()
  663. {
  664. open_in();
  665. system("cls");
  666. char ch[56], ah[78];
  667. int k = 0;
  668. spaces(); cout << "Enter username::"; cin >> ch;
  669. spaces(); cout << "Enter password ::"; cin >> ah; delay(1000);
  670. system("cls");
  671.  
  672. while (!user_file.eof() && user_file.read((char*)&us, sizeof(user)))
  673. {
  674. int n = us.name_s(ch);
  675. int m = us.pass_s(ah);
  676. cout << n << " " << m << endl;
  677.  
  678. if (n == 1 && m == 1)
  679. {
  680. spaces(); cout << "WELCOME "; delay(600);
  681. return 1;
  682. break;
  683. }
  684. else
  685. k = 1;
  686. }
  687. if (k == 1)
  688. {
  689. spaces(); cout << "ERROR "; delay(600);
  690. return 0;
  691. }
  692. close();
  693. }
  694. //function to offer choice of drivers
  695. void getdriver()
  696. {
  697.  
  698. system("cls");
  699. char n[45];
  700. int k; char ch = 'y';
  701. spaces(); cout << "Want MALE driver or FEMALE driver(M/F) ?? ";
  702. spaces(); cin >> n;
  703. open_in();
  704. table();
  705. while (!driver.eof() && driver.read((char*)&d, sizeof(d)))
  706. {
  707. d.compare(n);
  708. }
  709. cout << "Choose your Id ::";
  710. cin >> k;
  711.  
  712. spaces(); cout << "RIDE BOOKED !! ";
  713. spaces(); cout << "THANKS !! ";
  714.  
  715. close();
  716. }
Add Comment
Please, Sign In to add comment