Advertisement
Guest User

Untitled

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