Advertisement
Guest User

Untitled

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