Guest User

Untitled

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