Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.10 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #define max 10
  7.  
  8. typedef struct employee
  9. {
  10. int personal_code;
  11. char Emp_Name[25];
  12. char Emp_Title[25];
  13. }EMPLOYEE;
  14. EMPLOYEE emp[max];
  15.  
  16. typedef struct customer
  17. {
  18. float company_code;
  19. int personal_code;
  20. int identification_number;
  21. int reg_confirmation,registration_save;
  22. char identification_type[20];
  23. }CUSTOMER;
  24. CUSTOMER cus[max];
  25.  
  26. typedef struct company
  27. {
  28. int company_id;
  29. char company_name[20];
  30. char contact_person[20];
  31. int contact_number;
  32. }COMPANY;
  33. COMPANY comp[max];
  34.  
  35. struct salesdata
  36. {
  37.  
  38. }SALES;
  39.  
  40. void Registration();
  41. void Register1();
  42. void Update1();
  43.  
  44. int RegisterCustomer();
  45. void RegisterEmployee();
  46. void RegisterCompany();
  47. void UpdateCompany();
  48. void UpdateEmployee();
  49. void UpdateCustomer();
  50. void PasswordSystem();
  51. void Details ();
  52. void Display();
  53.  
  54. void DisplayCustomer();
  55. void DisplayEmployee();
  56. void DisplayPurchases(float);
  57. float Purchase ();
  58. void menu();
  59. void pmenu();
  60. void Credit();
  61. void Search();
  62.  
  63. float EightySeven_Code = 8.7;
  64. float Ninty_Code = 9.0;
  65. float Diesel_Code =9.5;
  66. int count=0; //counter for customers
  67. int count2=0; //counter for employees
  68.  
  69. int main ()
  70. {
  71. int choice;
  72. char username[15];
  73.  
  74. printf("\t\t\tEagle Energy Jamaica Ltd.\n\n");
  75. printf(" Welcome, please log in as a manager, cashier or pump attendant:\n");
  76. scanf("%s",username);
  77.  
  78. if ((strcmp(username,"manager")==0))
  79. {
  80. menu();
  81. }
  82. else if ((strcmp(username,"cashier")==0))
  83. {
  84. menu();
  85. }
  86. else if ((strcmp(username,"pump")==0))
  87. {
  88. pmenu();
  89. }
  90. else
  91. {
  92. printf("Your input did not match a position, please try again...");
  93. getch();
  94. main();
  95. }
  96. }
  97.  
  98. //THIS PASSWORD SYSTEM WILL GIVE THE USER 3 ATTEMPTS TO ENTER THE CORRECT INFORMATION
  99. //THE PROGRAM WILL EXIT UPON 3 FAILED ATTEMPTS
  100. /*void PasswordSystem()
  101. {
  102. FILE* file_ptr = NULL;
  103. char name[20];
  104. char password[10];
  105. int attempt,i;
  106. int id_code;
  107. char password1[20];
  108.  
  109. attempt = i = 0;
  110. //THE SYSTEM PASSWORD AND USER CAN BE EASILY CHANGED AT LINE 100
  111.  
  112. i++;
  113. printf ("\tYou have 3 attempts, This is attempt # %d\n\n",i);
  114. printf("Enter SYSTEM username: ");
  115. scanf("%s",name);
  116. printf("Enter SYSTEM password: ");
  117. scanf("%s",password);
  118. while (((attempt < 3 || strcmp(name, "admin") == 0) && strcmp(password, "pass") == 0))
  119. {
  120. if (strcmp(name, "admin") == 0 && strcmp(password, "pass") == 0)
  121. {
  122. printf("\n\n\t\tAccess granted\n");
  123. system ("pause");
  124. system("cls");
  125. //EMPLOYEES WILL USE THEIR NAME AS THE PASSWORD(ALL LOWER CASE)
  126. file_ptr = fopen("EmployeeRegistration.dat", "rb");
  127. if (file_ptr == NULL)
  128. {
  129. printf (" File does not exist\n");
  130. }
  131. else {
  132. printf (" Employee's password is their name\n");
  133. //fscanf (file_ptr,"%d %s %s \n",&EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
  134. fread (&EMPLOYEE,sizeof(EMPLOYEE),1,file_ptr);
  135. printf("hi1\n");
  136. printf("%d %s %s \n",EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
  137. printf("hi2\n");
  138. printf(" Please enter your employee ID\n");
  139. scanf ("%d",&id_code);
  140. printf(" Please enter password\n");
  141. scanf ("%s",password1);
  142. while(!feof(file_ptr))
  143. {
  144. if((id_code == EMPLOYEE.personal_code) && (strcmp(password1,EMPLOYEE.Emp_Name) == 0))
  145. {
  146. printf("access granted...");
  147. printf("Id confirmed\n");
  148. system ("pause");
  149. break;
  150. system("cls");
  151. }
  152. else
  153. {
  154. printf("access denied !");
  155. break;
  156. }
  157. }
  158. }
  159. }
  160. else {
  161. printf (" ");
  162. }
  163. }
  164. fclose(file_ptr);
  165. attempt++;
  166. }*/
  167.  
  168. void PasswordSystem()
  169. {
  170.  
  171. }
  172.  
  173. void menu ()
  174. {
  175. int choice;
  176.  
  177. system("cls");
  178. printf (" \t\tEagle Energy System Options \n");
  179. printf("\n 1) Add & Update");
  180. printf("\n 2) Display Records");
  181. printf("\n 3) Search for Customer");
  182. printf("\n 4) Details");
  183. printf("\n 0) Quit\n\n");
  184. scanf ("%d", &choice);
  185.  
  186. switch (choice)
  187. {
  188. case 1 : Registration(); break;
  189. case 2 : Display(); break;
  190. case 3 : Search(); break;
  191. case 4 : Details(); break;
  192. case 0 : return;
  193. }
  194.  
  195. }
  196.  
  197. void pmenu()
  198. {
  199. int choice;
  200.  
  201. system("cls");
  202. printf (" \t\tEagle Energy System Options \n");
  203. printf("\n 1) Sell Petrol");
  204. printf("\n 2) Search for Customer");
  205.  
  206. scanf ("%d", &choice);
  207.  
  208. switch (choice)
  209. {
  210. case 1: Purchase();break;
  211. case 2: Search(); break;
  212. default: pmenu(); break;
  213. }
  214.  
  215. pmenu();
  216. }
  217.  
  218. void Registration()
  219. {
  220. int registration_choice;
  221. system("cls");
  222. printf ("\n\nPlease select an option.\n");
  223. printf ("1) Register a Customer/Employee.\n");
  224. printf ("2) Update a Customer/Employee.\n\n");
  225. scanf("%d", &registration_choice);
  226. system("cls");
  227. switch (registration_choice)
  228. {
  229. case 1:
  230. Register1();
  231. break;
  232. case 2:
  233. Update1();
  234. break;
  235. default:
  236. printf ("You have selected an invalid option.\n");
  237. }
  238.  
  239. return;
  240. }
  241.  
  242. void Register1()
  243. {
  244. int registration_choice;
  245. registration_choice=0;
  246.  
  247. printf ("\n\nPlease select an option.\n");
  248. printf ("1) Register a Customer.\n");
  249. printf ("2) Register an Employee.\n\n");
  250. scanf("%d", &registration_choice);
  251. switch (registration_choice)
  252. {
  253. case 1:
  254. RegisterCustomer();
  255. break;
  256. case 2:
  257. RegisterEmployee();
  258. break;
  259. default:
  260. printf ("You have selected an invalid option.\n");
  261. }
  262. return;
  263. }
  264.  
  265. int RegisterCustomer()
  266. {
  267. float company_code;
  268. int registration_save,reg_confirmation,personal_code,option;
  269. FILE* file_ptr = NULL;
  270. personal_code = 0;
  271.  
  272. system("cls");
  273. printf (" We accept PASSPORT, NATIONAL ID and DRIVER's LICENSES\n as form of identification, please enter your ID # then enter the type of \n identification.\n\n");
  274. printf (" Please enter your Identification Number: ");
  275. scanf ("%d", &cus[count].identification_number);
  276. // do{
  277. printf (" Please select the form of identification: \n");
  278. printf (" 1. Passport\n");
  279. printf (" 2. National ID\n");
  280. printf (" 3. Driver's License'\n");
  281. scanf ("%d",&option);
  282. switch(option)
  283. {
  284. case 1: strcpy(cus[count].identification_type, "passport");
  285. break;
  286. case 2: strcpy(cus[count].identification_type, "national");
  287. break;
  288. case 3: strcpy(cus[count].identification_type, "drivers");
  289. break;
  290. default: printf(" You have entered an invalid ID type. Please try again..\n");
  291. RegisterCustomer();
  292. }
  293. /* fflush(stdin);
  294. gets(cus[].identification_type);
  295. // scanf ("%s", cus[].identification_type);
  296. if ((strcmp(cus[].identification_type, "passport") == 0) || (strcmp(cus[].identification_type, "national") == 0) || (strcmp(cus[].identification_type, "drivers") == 0))
  297. {
  298. printf (" ");
  299. }
  300. else
  301. {
  302. printf(" You have entered an invalid ID type. Please try again..\n");
  303. }
  304. }while((strcmp(cus[].identification_type, "passport") != 0) || (strcmp(cus[].identification_type, "national") != 0) || (strcmp(cus[].identification_type, "drivers") != 0));*/
  305. do{
  306. printf ("\n Please enter company code: ");
  307. scanf ("%f", &cus[count].company_code);
  308. if ((cus[count].company_code == EightySeven_Code) || (cus[count].company_code == Ninty_Code) || (cus[count].company_code == Diesel_Code))
  309. {
  310. break;
  311. }
  312. else
  313. {
  314. printf(" Invalid company code, please try again.\n");
  315. }
  316. }while ((cus[count].company_code != EightySeven_Code) && (cus[count].company_code != Ninty_Code) && (cus[count].company_code != Diesel_Code));
  317.  
  318. printf (" Please enter desired identification number: \n");
  319. scanf ("%d", &cus[count].personal_code);
  320.  
  321. printf("\n\n Is this information correct?\n\n");
  322. printf("Identification number: %d\n", cus[count].identification_number);
  323. printf("identification type : %s\n",cus[count].identification_type);
  324. printf("ID : %d\n",cus[count].personal_code);
  325. printf("Company Code : %.1f\n", cus[count].company_code);
  326. printf(" \n 1) for Yes \n 2) for No\n");
  327. scanf ("%d", &reg_confirmation);
  328. switch (reg_confirmation)
  329. {
  330. case 1: printf (" Would you like to save employee information ?\n");
  331. printf(" 1) for Yes \n 2) for No\n");
  332. scanf ("%d", &registration_save);
  333. switch(registration_save)
  334. {
  335. case 1: file_ptr = fopen("CustomerRegistration1.dat", "ab");
  336. //case 1: FILE* file_ptr = fopen("c:\\users\\shawn\\Registration.txt", "a");
  337. if (file_ptr == NULL)
  338. {
  339. printf (" File does not exist\n");
  340. }
  341. else {
  342. //fprintf (file_ptr,"%s %d %d %f\n",cus[].identification_type,cus[].identification_number,cus[].personal_code,cus[].company_code);
  343. fwrite(&cus[count], sizeof(CUSTOMER), 1, file_ptr);
  344. }
  345. fclose(file_ptr);
  346. count++;
  347. menu();
  348. case 2: return;
  349. default: printf ("Invalid selection.\n");
  350. }
  351.  
  352. case 2: return 0;
  353. }
  354. return personal_code;
  355. }
  356.  
  357. void RegisterEmployee()
  358. {
  359. FILE* file_ptr = NULL;
  360. int personal_code;
  361. int reg_confirmation,registration_save;
  362. reg_confirmation = registration_save = personal_code=0;
  363.  
  364. do
  365. {
  366. system("cls");
  367. printf(" Please enter employee's desired ID\n ");
  368. scanf ("%d",&emp[count2].personal_code);
  369. printf(" Please enter the employee's first name \n ");
  370. scanf ("%s", emp[count2].Emp_Name);
  371. printf(" Please enter the employee's job title \n ");
  372. fflush(stdin);
  373. gets(emp[count2].Emp_Title);
  374. printf(" \n\nIs this information correct?\n\n");
  375. printf("ID : %d\n",emp[count2].personal_code);
  376. printf("Name : %s\n",emp[count2].Emp_Name);
  377. printf("Title: %s\n",emp[count2].Emp_Title);
  378. printf(" \n 1) Yes \n 2) Retry\n 3) Return to main menu..\n");
  379. scanf ("%d", &reg_confirmation);
  380. }while((reg_confirmation != 1) && (reg_confirmation!=3));
  381.  
  382. switch (reg_confirmation)
  383. {
  384. case 1: printf (" Would you like to save employee information ?\n");
  385. printf(" 1) for Yes \n 2) for No\n");
  386. scanf ("%d", &registration_save);
  387. switch(registration_save)
  388. {
  389. case 1: file_ptr = fopen("EmployeeRegistration.dat", "ab");
  390. //case 1: FILE* file_ptr = fopen("c:\\users\\shawn\\Registration.txt", "a");
  391. if (file_ptr == NULL)
  392. {
  393. printf (" File does not exist\n");
  394. }
  395. else {
  396. // fprintf (file_ptr,"%d %s %s \n",EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
  397. fwrite(&emp[count],sizeof(EMPLOYEE),1, file_ptr);
  398. }
  399. fclose(file_ptr);
  400. count2++;
  401. case 2: return;
  402. default: printf ("Invalid selection.\n");
  403. }
  404.  
  405. case 2: return ;
  406. }
  407. }
  408.  
  409. void Update1()
  410. {
  411. int update_choice;
  412.  
  413. printf ("\n\nPlease select an option.\n");
  414. printf ("1) Update a Customer.\n");
  415. printf ("2) Update an Employee.\n\n");
  416. scanf("%d", &update_choice);
  417. switch (update_choice)
  418. {
  419. case 1:
  420. UpdateCustomer();
  421. break;
  422. case 2:
  423. UpdateEmployee();
  424. break;
  425. default:
  426. printf ("You have selected an invalid option.\n");
  427. }
  428. return;
  429. }
  430.  
  431. void UpdateCustomer()
  432. {
  433. int position=-1, i,code;
  434. int option, reg_confirmation, registration_save;
  435.  
  436. FILE* file_ptr = NULL;
  437.  
  438. file_ptr = fopen("CustomerRegistration1.dat", "rb");
  439. if (file_ptr == NULL)
  440. {
  441. printf (" Error opening file..\n");
  442. }
  443. else
  444. {
  445. fread(&cus[count],sizeof(CUSTOMER),1,file_ptr);
  446.  
  447. printf("Please enter the personal code for the record you want to change: ");
  448. scanf("%d",&code);
  449.  
  450. for(i=0;i<count;i++)
  451. {
  452. if(code==cus[i].personal_code)
  453. position=i;
  454. }
  455.  
  456. if(position==-1)
  457. {
  458. printf("Record not found!");
  459. menu();
  460. }
  461. else
  462. {
  463. printf (" Please enter your Identification Number: ");
  464. scanf ("%d", &cus[position].identification_number);
  465. printf (" Please select the form of identification: \n");
  466. printf (" 1. Passport\n");
  467. printf (" 2. National ID\n");
  468. printf (" 3. Driver's License'\n");
  469. scanf ("%d",&option);
  470. switch(option)
  471. {
  472. case 1: strcpy(cus[position].identification_type, "passport");
  473. break;
  474. case 2: strcpy(cus[position].identification_type, "national");
  475. break;
  476. case 3: strcpy(cus[position].identification_type, "drivers");
  477. break;
  478. default: printf(" You have entered an invalid ID type. Please try again..\n");
  479. // RegisterCustomer();
  480. }
  481.  
  482. do
  483. {
  484. printf ("\n Please enter company code: ");
  485. scanf ("%f", &cus[position].company_code);
  486. if ((cus[position].company_code == EightySeven_Code) || (cus[position].company_code == Ninty_Code) || (cus[position].company_code == Diesel_Code))
  487. {
  488. break;
  489. }
  490. else
  491. {
  492. printf(" Invalid company code, please try again.\n");
  493. }
  494. }while ((cus[position].company_code != EightySeven_Code) && (cus[position].company_code != Ninty_Code) && (cus[position].company_code != Diesel_Code));
  495.  
  496. printf (" Please enter desired identification number: \n");
  497. scanf ("%d", &cus[position].personal_code);
  498.  
  499. printf("\n\n Is this information correct?\n\n");
  500. printf("Identification number: %d\n",cus[position].identification_number);
  501. printf("identification type : %s\n",cus[position].identification_type);
  502. printf("ID : %d\n",cus[position].personal_code);
  503. printf("Company Code : %.1f\n",cus[position].company_code);
  504. printf(" \n 1) for Yes \n 2) for No\n");
  505. scanf ("%d", &reg_confirmation);
  506. switch (reg_confirmation)
  507. {
  508. case 1: printf (" Would you like to save employee information ?\n");
  509. printf(" 1) for Yes \n 2) for No\n");
  510. scanf ("%d", &registration_save);
  511. switch(registration_save)
  512. {
  513. case 1: file_ptr = fopen("CustomerRegistration1.dat", "ab");
  514. if (file_ptr == NULL)
  515. {
  516. printf (" File does not exist\n");
  517. }
  518. else
  519. {
  520. //fprintf (file_ptr,"%s %d %d %f\n",cus[].identification_type,cus[].identification_number,cus[].personal_code,cus[].company_code);
  521. fwrite(&cus[position], sizeof(CUSTOMER), 1, file_ptr);
  522. }
  523. fclose(file_ptr);
  524.  
  525. default: printf ("Invalid selection.\n");
  526. }
  527. }
  528. }
  529. }
  530.  
  531. fclose(file_ptr);
  532. }
  533.  
  534. void UpdateEmployee()
  535. {
  536. int position=-1, i, code;
  537. int option, reg_confirmation, registration_save;
  538.  
  539. FILE* file_ptr = NULL;
  540.  
  541. file_ptr = fopen("EmployeeRegistration.dat", "rb");
  542. if (file_ptr == NULL)
  543. {
  544. printf (" Error opening file..\n");
  545. }
  546. else
  547. {
  548. fread(&emp[count2],sizeof(EMPLOYEE),1,file_ptr);
  549.  
  550. printf("Please enter the personal code for the record you want to change: ");
  551. scanf("%d",&code);
  552.  
  553. for(i=0;i<count;i++)
  554. {
  555. if(code==emp[i].personal_code)
  556. position=i;
  557. }
  558.  
  559. if(position==-1)
  560. {
  561. printf("Record not found!");
  562. menu();
  563. }
  564. else
  565. {
  566. do
  567. {
  568. //system("cls");
  569. printf(" Please enter employee's desired ID\n ");
  570. scanf ("%d",&emp[position].personal_code);
  571. printf(" Please enter the employee's first name \n ");
  572. scanf ("%s", emp[position].Emp_Name);
  573. printf(" Please enter the employee's job title \n ");
  574. fflush(stdin);
  575. gets(emp[position].Emp_Title);
  576. printf(" \n\nIs this information correct?\n\n");
  577. printf("ID : %d\n",emp[position].personal_code);
  578. printf("Name : %s\n",emp[position].Emp_Name);
  579. printf("Title: %s\n",emp[position].Emp_Title);
  580. printf(" \n 1) Yes \n 2) Retry\n 3) Return to main menu..\n");
  581. scanf ("%d", &reg_confirmation);
  582. }while((reg_confirmation != 1) && (reg_confirmation!=3));
  583.  
  584. switch (reg_confirmation)
  585. {
  586. case 1: printf (" Would you like to save employee information ?\n");
  587. printf(" 1) for Yes \n 2) for No\n");
  588. scanf ("%d", &registration_save);
  589. switch(registration_save)
  590. {
  591. case 1: file_ptr = fopen("EmployeeRegistration.dat", "ab");
  592. if (file_ptr == NULL)
  593. {
  594. printf (" File does not exist\n");
  595. }
  596. else
  597. {
  598. fwrite(&emp[count],sizeof(EMPLOYEE),1, file_ptr);
  599. }
  600. fclose(file_ptr);
  601.  
  602. case 2: return;
  603. default: printf ("Invalid selection.\n");
  604. }
  605.  
  606. case 2: return ;
  607. }
  608. }
  609. }
  610.  
  611. fclose(file_ptr);
  612. getch();
  613. }
  614.  
  615. float Purchase()
  616. {
  617. int sale_identification_number, i;
  618. int purchase_decision,gas_choice;
  619. int id_code=-1;
  620. char petrol_name[12];
  621. int pump_number;
  622. float amount_per_gallon , amount_sold , value_of_sale ,cost,Diesel,NINTY,EIGHTYSEVEN;
  623. char identification_type1[10];
  624. int identification_number1,personal_code1;
  625. float company_code1;
  626. time_t rawtime;
  627. struct tm * timeinfo;
  628. personal_code1 = company_code1 = identification_number1 = 0;
  629. system ("cls");
  630. time ( &rawtime );
  631. timeinfo = localtime ( &rawtime );
  632. cost = gas_choice = sale_identification_number = pump_number = amount_per_gallon = amount_sold = value_of_sale = 0;
  633. srand (time(NULL));
  634. sale_identification_number = rand()%1000;
  635.  
  636. Diesel = 101.71;
  637. NINTY = 99.81;
  638. EIGHTYSEVEN = 115.21;
  639.  
  640. printf ("Please select the type of gas you would like to purchase \n");
  641. printf ("\n1) Diesel");
  642. printf ("\n2) Ninty");
  643. printf ("\n3) Eighty Seven");
  644. printf ("\n>>: ");
  645. scanf ("%d", &gas_choice);
  646. if (gas_choice ==1)
  647. {
  648. amount_per_gallon = Diesel;
  649. strcpy(petrol_name,"Diesel");
  650. }
  651. if (gas_choice ==2)
  652. {
  653. amount_per_gallon = NINTY;
  654. strcpy(petrol_name,"Ninty");
  655.  
  656. }
  657.  
  658. if (gas_choice ==3)
  659. {
  660. amount_per_gallon = EIGHTYSEVEN;
  661. strcpy(petrol_name,"Eighty Seven");
  662. // printf ("hi");
  663. }
  664. fflush(stdin);
  665.  
  666. printf ("Please enter customer's ID Code:");
  667. scanf("%d",&id_code);
  668. FILE *fp = NULL;
  669. fp = fopen("CustomerRegistration1.dat", "rb");
  670. if(fp== NULL)
  671. {
  672. printf("Error Acessing file");
  673. }
  674. else
  675. {
  676. while(!feof(fp))
  677. {
  678. //fscanf(fp,"%d", &id);
  679. fscanf (fp,"%s %d %d %f\n",identification_type1,&identification_number1,&personal_code1,&company_code1);
  680. if (id_code==identification_number1)
  681. {
  682. printf("Id confirmed\n");
  683. system ("pause");
  684. getch();
  685. system("cls");
  686. break;
  687. }
  688.  
  689. }
  690. if (id_code==-1)
  691. {
  692. printf ("\nID Not found, please try again or register.");
  693. return;
  694. }
  695. fclose(fp);
  696. }
  697.  
  698. printf ("\nPlease enter the amount of gallons being purchased\n");
  699. scanf ("%f",&amount_sold);
  700.  
  701. value_of_sale = (amount_per_gallon * amount_sold);
  702.  
  703. FILE* file_ptr = NULL;
  704. file_ptr = fopen("purchases.dat","a+");
  705. fprintf(file_ptr,"%d %d %s %d %f %f %s",sale_identification_number,id_code,petrol_name,(int)amount_sold,amount_per_gallon,value_of_sale,asctime(timeinfo));
  706. fclose(file_ptr);
  707.  
  708. printf ("Would you like to print a reciept or start again ? Please enter 1 or 2");
  709. printf ("\n1) Start again");
  710. printf ("\n2) Print Reciept \n");
  711. scanf ("%d", &purchase_decision);
  712. if (purchase_decision == 1)
  713. {
  714. Purchase();
  715. }
  716. else if (purchase_decision == 2)
  717. {
  718. system("cls");
  719. }
  720.  
  721. printf ("\t\t\t\tEagle Energy Jamaica Limited\n");
  722. printf ("\t\t\t\t176 Port Royal Street, Kingston\n");
  723. printf ("\t\t\t\t\tBranch 9.5\n\n");
  724.  
  725. printf ("The transaction number is: %d \n", sale_identification_number);
  726. printf ("Eagle Energy ID :");
  727. printf (" \nCustomer ID :%d",id_code);
  728. //printf (" \nPetrol Name :%s",petrol_name);
  729. printf (" \nPetrol Name : %s",petrol_name);
  730. printf (" \nAmount sold in Gallons :%d Gal.",(int)amount_sold);
  731. printf (" \nCost Per Gallon :%.3f",amount_per_gallon);
  732. printf (" \nTotal Cost :%.3f",value_of_sale);
  733. printf (" \nThis purchase was made on:%s", asctime(timeinfo));
  734. cost = value_of_sale;
  735. system("pause");
  736. return cost;
  737. }
  738.  
  739. void Display()
  740. {
  741. int displaychoice;
  742. displaychoice = 0;
  743.  
  744. printf(" What data would you like to display ?\n");
  745. printf ("1)Customer Information\n");
  746. printf ("2)Employee Information\n");
  747. printf ("3)Purchase Information\n");
  748. scanf("%d",&displaychoice);
  749. switch (displaychoice)
  750. {
  751. case 1 : DisplayCustomer();
  752. break;
  753. case 2 : DisplayEmployee();
  754. break;
  755. // case 3 : DisplayPurchases(float cost );
  756. // break;
  757. }
  758. }
  759.  
  760. void DisplayCustomer()
  761. {
  762. FILE* file_ptr = NULL;
  763. file_ptr = fopen("CustomerRegistration1.dat", "rb");
  764. if (file_ptr == NULL)
  765. {
  766. printf (" File does not exist\n");
  767. }
  768. else
  769. {
  770. int i;
  771. system("cls");
  772. printf ("\t\t\tEagle Energy Jamaica Limited\n");
  773. printf ("\t\t\t Customer Information\n\n");
  774.  
  775. for(i=0;i<count;i++)
  776. {
  777. printf("Identification number: %d\n", cus[i].identification_number);
  778. printf("Identification type : %s\n",cus[i].identification_type);
  779. printf("ID : %d\n",cus[i].personal_code);
  780. printf("Company Code : %.1f\n\n", cus[i].company_code);
  781. }
  782. }
  783. fclose(file_ptr);
  784. getch();
  785. }
  786.  
  787.  
  788. void DisplayEmployee()
  789. {
  790. FILE* file_ptr = NULL;
  791. file_ptr = fopen("EmployeeRegistration.dat", "rb");
  792. if (file_ptr == NULL)
  793. {
  794. printf (" File does not exist\n");
  795. getch();
  796. }
  797. else
  798. {
  799. int i;
  800. system("cls");
  801. printf ("\t\t\tEagle Energy Jamaica Limited\n");
  802. printf ("\t\t\t Employee Information\n\n");
  803.  
  804. for(i=0;i<count;i++)
  805. {
  806. printf("ID : %d\n",emp[i].personal_code);
  807. printf("Name : %s\n",emp[i].Emp_Name);
  808. printf("Title: %s\n",emp[i].Emp_Title);
  809. }
  810. }
  811. getch();
  812. fclose(file_ptr);
  813. }
  814.  
  815. void DisplayPurchases(float cost)
  816. {
  817. FILE *file_get = NULL;
  818. struct purchase_info{
  819. int sale_id,code,sold;
  820. char name[7],thetime [50];
  821. float gallon,sale;
  822. } purchases;
  823.  
  824. printf("-------------------------------------------------------------------\n");
  825. printf("| Purchases |\n");
  826. printf("-------------------------------------------------------------------\n\n");
  827.  
  828. file_get = fopen("purchases.dat","r");
  829. if(file_get == NULL){
  830. printf("File not found");
  831. return;
  832. }
  833. else
  834. {
  835. while(!feof(file_get)){
  836. fscanf(file_get,"%d %d %s %d %f %f %s",&purchases.sale_id,&purchases.code,purchases.name,&purchases.sold,&purchases.gallon,&purchases.sale,purchases.thetime);
  837. printf ("\t\t\t\tEagle Energy Jamaica Limited\n");
  838. printf ("\t\t\t\t176 Port Royal Street, Kingston\n");
  839. printf ("\t\t\t\t\tBranch 9.5\n\n");
  840.  
  841. printf ("The transaction number is: %d \n", purchases.sale_id);
  842. printf ("Eagle Energy ID :");
  843. printf (" \nCustomer ID :%d",purchases.code);
  844. printf (" \nPetrol Name : %s",purchases.name);
  845. printf (" \nAmount sold in Gallons :%d Gal.",purchases.sold);
  846. printf (" \nCost Per Gallon :%.3f",purchases.gallon);
  847. printf (" \nTotal Cost :%.3f",purchases.sale);
  848. printf (" \nThis purchase was made on:%s", purchases.thetime);
  849. printf ("\n----------------------------------------------------------------------------\n");
  850. }
  851. }
  852. system("pause");
  853. }
  854.  
  855. //THIS FUNCTION IS DISPLAY THE RELEVANT DETAILS OF THE COMPANY
  856. void Details()
  857. {
  858. system("cls");
  859. printf ("\t\t\tEagle Energy Jamaica Limited\n");
  860. printf ("\t\t\t176 Port Royal Street, Kingston\n");
  861. printf ("\t\t\t\tBranch 9.5\n");
  862. printf ("\t\t\t 904-3921 / 904-3922\n\n\n");
  863. printf ("Javaughn Jordan - Supervisor\n");
  864. printf ("Duvaun Clacken- Assistant Supervisor\n");
  865. printf ("Jhevante Mcdonald - Managing Director\n");
  866. printf ("Tami-Ann Russell - Executive Director\n\n");
  867. system ("pause");
  868.  
  869. }
  870.  
  871. void Search()
  872. {
  873. int position=-1, i,code;
  874.  
  875. FILE* file_ptr = NULL;
  876.  
  877. file_ptr = fopen("CustomerRegistration1.dat", "rb");
  878. if (file_ptr == NULL)
  879. {
  880. printf (" Error opening file..\n");
  881. }
  882. else
  883. {
  884. fread(&cus[count],sizeof(CUSTOMER),1,file_ptr);
  885.  
  886. printf("Please enter the personal code for the record you want to search for: ");
  887. scanf("%d",&code);
  888.  
  889. for(i=0;i<count;i++)
  890. {
  891. if(code==cus[i].personal_code)
  892. position=i;
  893. }
  894.  
  895. if(position==-1)
  896. {
  897. printf("Record not found!");
  898. menu();
  899. }
  900. else
  901. {
  902. printf("Identification number: %d\n",cus[position].identification_number);
  903. printf("identification type : %s\n",cus[position].identification_type);
  904. printf("ID : %d\n",cus[position].personal_code);
  905. printf("Company Code : %.1f\n",cus[position].company_code);
  906. }
  907. }
  908. getch();
  909. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement