Advertisement
Guest User

Untitled

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