Advertisement
Guest User

Untitled

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