Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.46 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<string.h>
  5. #include <time.h>
  6. #include <stdlib.h>
  7.  
  8. struct employee
  9. {
  10. int personal_code;
  11. char Emp_Name[25];
  12. char Emp_Title[25];
  13. }EMPLOYEE;
  14.  
  15. struct customer
  16. {
  17. float company_code;
  18. int personal_code;
  19. int identification_number;
  20. int reg_confirmation,registration_save;
  21. char identification_type[20];
  22. }CUSTOMER;
  23.  
  24. struct company
  25. {
  26. int company_id;
  27. char company_name[20];
  28. char contact_person[20];
  29. int contact_number;
  30. }COMPANY;
  31.  
  32. struct salesdata
  33. {
  34.  
  35. }SALES;
  36.  
  37. void Registration();
  38. void Register1();
  39. void Update1();
  40.  
  41. int RegisterCustomer();
  42. void RegisterEmployee();
  43. void RegisterCompany();
  44. void UpdateCompany();
  45. void UpdateEmployee();
  46. void UpdateCustomer();
  47. void PasswordSystem();
  48. void Details ();
  49. void Display();
  50.  
  51. void DisplayCustomer();
  52. void DisplayEmployee();
  53. void DisplayPurchases(float);
  54. float Purchase ();
  55. int menu();
  56. void Credit();
  57.  
  58. float EightySeven_Code = 8.7;
  59. float Ninty_Code = 9.0;
  60. float Desiel_Code =9.5;
  61.  
  62. int main ()
  63. {
  64. int choice;
  65.  
  66. //PasswordSystem();
  67. do
  68. {
  69. choice = menu();
  70. switch (choice)
  71. {
  72. case 1 : Registration(); break;
  73. case 2 : Purchase(); break;
  74. case 3 : Display(); break;
  75. case 4 : Details(); break;
  76. case 0 : return 0;
  77. }
  78. } while(1);
  79. }
  80.  
  81. //THIS PASSWORD SYSTEM WILL GIVE THE USER 3 ATTEMPTS TO ENTER THE CORRECT INFORMATION
  82. //THE PROGRAM WILL EXIT UPON 3 FAILED ATTEMPTS
  83. void PasswordSystem()
  84. {
  85. FILE* file_ptr = NULL;
  86. char name[20];
  87. char password[10];
  88. int attempt,i;
  89. int id_code;
  90. char password1[20];
  91.  
  92. attempt = i = 0;
  93. //THE SYSTEM PASSWORD AND USER CAN BE EASILY CHANGED AT LINE 100
  94.  
  95. i++;
  96. printf ("\tYou have 3 attempts, This is attempt # %d\n\n",i);
  97. printf("Enter SYSTEM username: ");
  98. scanf("%s",name);
  99. printf("Enter SYSTEM password: ");
  100. scanf("%s",password);
  101. while (((attempt < 3 || strcmp(name, "admin") == 0) && strcmp(password, "pass") == 0))
  102. {
  103. if (strcmp(name, "admin") == 0 && strcmp(password, "pass") == 0)
  104. {
  105. printf("\n\n\t\tAccess granted\n");
  106. system ("pause");
  107. system("cls");
  108. //EMPLOYEES WILL USE THEIR NAME AS THE PASSWORD(ALL LOWER CASE)
  109. file_ptr = fopen("EmployeeRegistration.dat", "rb");
  110. if (file_ptr == NULL)
  111. {
  112. printf (" File does not exist\n");
  113. }
  114. else {
  115. printf (" Employee's password is their name\n");
  116. //fscanf (file_ptr,"%d %s %s \n",&EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
  117. fread (&EMPLOYEE,sizeof(EMPLOYEE),1,file_ptr);
  118. printf("hi1\n");
  119. printf("%d %s %s \n",EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
  120. printf("hi2\n");
  121. printf(" Please enter your employee ID\n");
  122. scanf ("%d",&id_code);
  123. printf(" Please enter password\n");
  124. scanf ("%s",password1);
  125. while(!feof(file_ptr))
  126. {
  127. if((id_code == EMPLOYEE.personal_code) && (strcmp(password1,EMPLOYEE.Emp_Name) == 0))
  128. {
  129. printf("access granted...");
  130. printf("Id confirmed\n");
  131. system ("pause");
  132. break;
  133. system("cls");
  134. }
  135. else
  136. {
  137. printf("access denied !");
  138. break;
  139. }
  140. }
  141. }
  142. }
  143. else {
  144. printf (" ");
  145. }
  146. }
  147. fclose(file_ptr);
  148. attempt++;
  149. }
  150.  
  151. int menu ()
  152. {
  153. int choice;
  154. system("cls");
  155. printf (" \t\tEagle Energy System Options \n");
  156. printf("\n 1) Add & Update");
  157. printf("\n 2) Sell Petrol");
  158. printf("\n 3) Display Records");
  159. printf("\n 4) Details");
  160. printf("\n 0) Quit\n\n");
  161. scanf ("%d", &choice);
  162.  
  163. return choice;
  164. }
  165.  
  166. void Registration()
  167. {
  168. int registration_choice;
  169. system("cls");
  170. printf ("\n\nPlease select an option.\n");
  171. printf ("1) Register a Customer/Employee.\n");
  172. printf ("2) Update a Customer/Employee.\n\n");
  173. scanf("%d", &registration_choice);
  174. system("cls");
  175. switch (registration_choice)
  176. {
  177. case 1:
  178. Register1();
  179. break;
  180. case 2:
  181. Update1();
  182. break;
  183. default:
  184. printf ("You have selected an invalid option.\n");
  185. }
  186.  
  187. return;
  188. }
  189.  
  190. void Register1()
  191. {
  192. int registration_choice;
  193. registration_choice=0;
  194.  
  195. printf ("\n\nPlease select an option.\n");
  196. printf ("1) Register a Customer.\n");
  197. printf ("2) Register an Employee.\n\n");
  198. scanf("%d", &registration_choice);
  199. switch (registration_choice)
  200. {
  201. case 1:
  202. RegisterCustomer();
  203. break;
  204. case 2:
  205. RegisterEmployee();
  206. break;
  207. default:
  208. printf ("You have selected an invalid option.\n");
  209. }
  210. return;
  211. }
  212.  
  213. int RegisterCustomer()
  214. {
  215. float company_code;
  216. int registration_save,reg_confirmation,personal_code,option;
  217. FILE* file_ptr = NULL;
  218. personal_code = 0;
  219.  
  220. system("cls");
  221. 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");
  222. printf (" Please enter your Identification Number: ");
  223. scanf ("%d", &CUSTOMER.identification_number);
  224. // do{
  225. printf (" Please select the form of identification: \n");
  226. printf (" 1. Passport\n");
  227. printf (" 2. National ID\n");
  228. printf (" 3. Driver's License'\n");
  229. scanf ("%d",&option);
  230. switch(option)
  231. {
  232. case 1: strcpy(CUSTOMER.identification_type, "passport");
  233. break;
  234. case 2: strcpy(CUSTOMER.identification_type, "national");
  235. break;
  236. case 3: strcpy(CUSTOMER.identification_type, "drivers");
  237. break;
  238. default: printf(" You have entered an invalid ID type. Please try again..\n");
  239. RegisterCustomer();
  240. }
  241. /* fflush(stdin);
  242. gets(CUSTOMER.identification_type);
  243. // scanf ("%s", CUSTOMER.identification_type);
  244. if ((strcmp(CUSTOMER.identification_type, "passport") == 0) || (strcmp(CUSTOMER.identification_type, "national") == 0) || (strcmp(CUSTOMER.identification_type, "drivers") == 0))
  245. {
  246. printf (" ");
  247. }
  248. else
  249. {
  250. printf(" You have entered an invalid ID type. Please try again..\n");
  251. }
  252. }while((strcmp(CUSTOMER.identification_type, "passport") != 0) || (strcmp(CUSTOMER.identification_type, "national") != 0) || (strcmp(CUSTOMER.identification_type, "drivers") != 0));*/
  253. do{
  254. printf ("\n Please enter company code: ");
  255. scanf ("%f", &CUSTOMER.company_code);
  256. if ((CUSTOMER.company_code != EightySeven_Code) && (CUSTOMER.company_code != Ninty_Code) && (CUSTOMER.company_code != Desiel_Code))
  257. {
  258. printf(" Invalid company code, please try again.\n");
  259. }
  260. else if((CUSTOMER.company_code == EightySeven_Code) || (CUSTOMER.company_code == Ninty_Code) || (CUSTOMER.company_code == Desiel_Code));
  261. {
  262. break;
  263. }
  264. }while((CUSTOMER.company_code != EightySeven_Code) && (CUSTOMER.company_code != Ninty_Code) && (CUSTOMER.company_code != Desiel_Code));
  265.  
  266. printf (" Please enter desired identification number: \n");
  267. scanf ("%d", &CUSTOMER.personal_code);
  268.  
  269. printf("\n\n Is this information correct?\n\n");
  270. printf("Identification number: %d\n", CUSTOMER.identification_number);
  271. printf("identification type : %s\n",CUSTOMER.identification_type);
  272. printf("ID : %d\n",CUSTOMER.personal_code);
  273. printf("Company Code : %.1f\n", CUSTOMER.company_code);
  274. printf(" \n 1) for Yes \n 2) for No\n");
  275. scanf ("%d", &reg_confirmation);
  276. switch (reg_confirmation)
  277. {
  278. case 1: printf (" Would you like to save employee information ?\n");
  279. printf(" 1) for Yes \n 2) for No\n");
  280. scanf ("%d", &registration_save);
  281. switch(registration_save)
  282. {
  283. case 1: file_ptr = fopen("CustomerRegistration1.dat", "ab");
  284. //case 1: FILE* file_ptr = fopen("c:\\users\\shawn\\Registration.txt", "a");
  285. if (file_ptr == NULL)
  286. {
  287. printf (" File does not exist\n");
  288. }
  289. else {
  290. //fprintf (file_ptr,"%s %d %d %f\n",CUSTOMER.identification_type,CUSTOMER.identification_number,CUSTOMER.personal_code,CUSTOMER.company_code);
  291. fwrite(&CUSTOMER, sizeof(CUSTOMER), 1, file_ptr);
  292. }
  293. fclose(file_ptr);
  294. case 2: return 0;
  295. default: printf ("Invalid selection.\n");
  296. }
  297.  
  298. case 2: return 0;
  299. }
  300. return personal_code;
  301. }
  302.  
  303. void RegisterEmployee()
  304. {
  305. FILE* file_ptr = NULL;
  306. int personal_code;
  307. int reg_confirmation,registration_save;
  308. reg_confirmation = registration_save = personal_code=0;
  309.  
  310. do
  311. {
  312. system("cls");
  313. printf(" Please enter employee's desired ID\n ");
  314. scanf ("%d",&EMPLOYEE.personal_code);
  315. printf(" Please enter the employee's first name \n ");
  316. scanf ("%s", EMPLOYEE.Emp_Name);
  317. printf(" Please enter the employee's job title \n ");
  318. fflush(stdin);
  319. gets(EMPLOYEE.Emp_Title);
  320. printf(" \n\nIs this information correct?\n\n");
  321. printf("ID : %d\n",EMPLOYEE.personal_code);
  322. printf("Name : %s\n",EMPLOYEE.Emp_Name);
  323. printf("Title: %s\n",EMPLOYEE.Emp_Title);
  324. printf(" \n 1) Yes \n 2) Retry\n 3) Return to main menu..\n");
  325. scanf ("%d", &reg_confirmation);
  326. }while((reg_confirmation != 1) && (reg_confirmation!=3));
  327.  
  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("EmployeeRegistration.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,"%d %s %s \n",EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
  343. fwrite(&EMPLOYEE,sizeof(EMPLOYEE),1, file_ptr);
  344. }
  345. fclose(file_ptr);
  346. case 2: return;
  347. default: printf ("Invalid selection.\n");
  348. }
  349.  
  350. case 2: return ;
  351. }
  352. }
  353.  
  354. void Update1()
  355. {
  356. int update_choice;
  357.  
  358. printf ("\n\nPlease select an option.\n");
  359. printf ("1) Update a Customer.\n");
  360. printf ("2) Update an Employee.\n\n");
  361. scanf("%d", &update_choice);
  362. switch (update_choice)
  363. {
  364. case 1:
  365. UpdateCustomer();
  366. break;
  367. case 2:
  368. UpdateEmployee();
  369. break;
  370. default:
  371. printf ("You have selected an invalid option.\n");
  372. }
  373. return;
  374. }
  375.  
  376. void UpdateCustomer()
  377. {
  378. struct customer x ={0,0,0,0,'c'};
  379. FILE* file_ptr = NULL;
  380.  
  381. file_ptr = fopen("CustomerRegistration1.dat", "rb");
  382. if (file_ptr == NULL)
  383. {
  384. printf (" Error opening file..\n");
  385. }
  386. else
  387. {
  388. fread(&x,sizeof(CUSTOMER),1,file_ptr);
  389.  
  390. printf ("%d",x.identification_number);
  391. printf ("%lf",x.company_code);
  392. printf ("%s",x.identification_type);
  393. printf ("%d",x.personal_code);
  394. printf ("%d",x.registration_save);
  395. printf ("%d",x.reg_confirmation);
  396. }
  397.  
  398. fclose(file_ptr);
  399. }
  400.  
  401. void UpdateEmployee()
  402. {
  403. struct employee y ={0,"Jhev","Boss"};
  404. FILE* file_ptr = NULL;
  405.  
  406. file_ptr = fopen("EmployeeRegistration.dat", "rb");
  407. if (file_ptr == NULL)
  408. {
  409. printf (" Error opening file..\n");
  410. }
  411. else
  412. {
  413. fread(&y,sizeof(EMPLOYEE),1,file_ptr);
  414.  
  415. printf ("%d",EMPLOYEE.personal_code);
  416. printf ("%s",EMPLOYEE.Emp_Name);
  417. printf ("%s",EMPLOYEE.Emp_Title);
  418. }
  419.  
  420. fclose(file_ptr);
  421.  
  422. }
  423.  
  424. float Purchase()
  425. {
  426. int sale_identification_number;
  427. int purchase_decision,gas_choice;
  428. int id_code;
  429. char petrol_name[12];
  430. int pump_number;
  431. float amount_per_gallon , amount_sold , value_of_sale , cost,DESIEL,NINTY,EIGHTYSEVEN;
  432. char identification_type1[10];
  433. int identification_number1,personal_code1;
  434. float company_code1;
  435. time_t rawtime;
  436. struct tm * timeinfo;
  437. personal_code1= company_code1 = identification_number1 = 0;
  438. system ("cls");
  439. time ( &rawtime );
  440. timeinfo = localtime ( &rawtime );
  441. cost = gas_choice = sale_identification_number = pump_number = amount_per_gallon = amount_sold = value_of_sale = 0;
  442. srand (time(NULL));
  443. sale_identification_number = rand()%1000;
  444.  
  445. DESIEL = 101.71;
  446. NINTY = 99.81;
  447. EIGHTYSEVEN = 115.21;
  448.  
  449. printf ("Please select the type of gas you would like to purchase \n");
  450. printf ("\n1) Desiel");
  451. printf ("\n2) Ninty");
  452. printf ("\n3) Eighty Seven\n");
  453. scanf ("%d", &gas_choice);
  454. if (gas_choice ==1)
  455. {
  456. amount_per_gallon = DESIEL;
  457. strcpy(petrol_name,"Desiel");
  458. }
  459. if (gas_choice ==2)
  460. {
  461. amount_per_gallon = NINTY;
  462. strcpy(petrol_name,"Ninty");
  463. }
  464.  
  465. if (gas_choice ==3)
  466. {
  467. amount_per_gallon = EIGHTYSEVEN;
  468. strcpy(petrol_name,"Eighty Seven");
  469. printf ("hi");
  470. }
  471. fflush(stdin);
  472.  
  473. printf ("Please enter customer's ID Code:");
  474. scanf("%d",&id_code);
  475. FILE *fp= NULL;
  476. fp= fopen("CustomerRegistration1.dat", "rb");
  477. if(fp== NULL)
  478. {
  479. printf("Error Acessing file");
  480. }
  481. else
  482. {
  483. while(!feof(fp))
  484. {
  485. //fscanf(fp,"%d", &id);
  486. fscanf (fp,"%s %d %d %f\n",identification_type1,&identification_number1,&personal_code1,&company_code1);
  487. if (id_code==identification_number1)
  488. {
  489. printf("Id confirmed\n");
  490. system ("pause");
  491. getch();
  492. system("cls");
  493. }
  494. else
  495. {
  496. printf ("\nID Not found, please try again or register.");
  497. }
  498. }
  499. fclose(fp);
  500. }
  501.  
  502. printf ("\nPlease enter the amount of gallons being purchased\n");
  503. scanf ("%f",&amount_sold);
  504.  
  505. value_of_sale = (amount_per_gallon * amount_sold);
  506.  
  507. printf ("Would you like to print a reciept or start again ? Please enter 1 or 2");
  508. printf ("\n1) Start again");
  509. printf ("\n2) Print Reciept \n");
  510. scanf ("%d", &purchase_decision);
  511. if (purchase_decision == 1)
  512. {
  513. Purchase();
  514. }
  515. else if (purchase_decision == 2)
  516. {
  517. system("cls");
  518. }
  519.  
  520. printf ("\t\t\t\tEagle Energy Jamaica Limited\n");
  521. printf ("\t\t\t\t176 Port Royal Street, Kingston\n");
  522. printf ("\t\t\t\t\tBranch 9.5\n");
  523. printf ("\t\t\tJhevante Mcdonald - Managing Director\n");
  524. printf ("\t\t\t\tjhevante.mcdonald@gmail.com\n");
  525. printf ("\t\t\t\t\t1876-898-0479\n");
  526. printf ("The transaction number is: %d \n", sale_identification_number);
  527. printf ("Eagle Energy ID :");
  528. printf (" \nCustomer ID :%d",id_code);
  529. printf (" \nPetrol Name :%s",petrol_name);
  530. printf (" \nAmount sold in Gallons :%d Gal.",(int)amount_sold);
  531. printf (" \nCost Per Gallon :%.3f",amount_per_gallon);
  532. printf (" \nTotal Cost :%.3f",value_of_sale);
  533. printf (" \nThis purchase was made on:%s", asctime(timeinfo));
  534. cost = value_of_sale;
  535. system("pause");
  536. return cost;
  537. }
  538.  
  539. void Display()
  540. {
  541. int displaychoice;
  542. displaychoice = 0;
  543.  
  544. printf(" What data would you like to display ?\n");
  545. printf ("1)Customer Information\n");
  546. printf ("2)Employee Information\n");
  547. printf ("3)Purchase Information\n");
  548. scanf("%d",&displaychoice);
  549. switch (displaychoice)
  550. {
  551. case 1 : DisplayCustomer();
  552. break;
  553. case 2 : DisplayEmployee();
  554. break;
  555. // case 3 : DisplayPurchases(float cost );
  556. // break;
  557. }
  558. }
  559.  
  560. void DisplayCustomer()
  561. {
  562. char ch;
  563. FILE* file_ptr = NULL;
  564. file_ptr = fopen("CustomerRegistration.dat", "rb");
  565. if (file_ptr == NULL)
  566. {
  567. printf (" File does not exist\n");
  568. }
  569. else {
  570. system("cls");
  571. printf ("\tEmployee Information\n\n");
  572. printf ("Id Name Title\n");
  573. while(1)
  574. {
  575. ch = fgetc(file_ptr);
  576. if (ch==EOF)
  577. {
  578. break;
  579. }
  580. printf ("%c",ch);
  581. }
  582. printf(" \n\nPress any key to continue..");
  583. getch();
  584. }
  585. return;
  586. }
  587.  
  588.  
  589. void DisplayEmployee()
  590. {
  591.  
  592. char ch;
  593. FILE* file_ptr = NULL;
  594. file_ptr = fopen("EmployeeRegistration.dat", "rb");
  595. if (file_ptr == NULL)
  596. {
  597. printf (" File does not exist\n");
  598. }
  599. else {
  600. system("cls");
  601. printf ("\tEmployee Information\n\n");
  602. printf ("Id Name Title\n");
  603. while(1)
  604. {
  605. ch = fgetc(file_ptr);
  606. if (ch==EOF)
  607. {
  608. break;
  609. }
  610. printf ("%c",ch);
  611. }
  612. printf(" \n\nPress any key to continue..");
  613. getch();
  614. }
  615. return;
  616. }
  617.  
  618. void DisplayPurchases(float cost)
  619. {
  620.  
  621. }
  622.  
  623. //THIS FUNCTION IS DISPLAY THE RELEVANT DETAILS OF THE COMPANY
  624. void Details()
  625. {
  626. system("cls");
  627. printf ("\t\t\tEagle Energy Jamaica Limited\n");
  628. printf ("\t\t\t176 Port Royal Street, Kingston\n");
  629. printf ("\t\t\t\tBranch 9.5\n");
  630. printf ("\t\t\t 904-3921 / 904-3922\n\n\n");
  631. printf ("Javaughn Jordan - Supervisor\n");
  632. printf ("Duvaun Clacken- Assistant Supervisor\n");
  633. printf ("Jhevante Mcdonald - Managing Director\n");
  634. // printf ("\t\t\tjhevante.mcdonald@gmail.com\n");
  635. // printf ("\t\t\t\t\t1876-898-0479\n");
  636. printf ("Tami-Ann Russell - Executive Director\n\n");
  637. system ("pause");
  638.  
  639. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement