Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include <time.h>
- #include <stdlib.h>
- float Ninty_Code=9.5;
- float EightySeven_Code =8.7;
- float Desiel_Code =6.6;
- void Registration();
- int RegisterCustomer();
- void RegisterEmployee();
- void PasswordSystem();
- void Details ();
- void Display();
- void employee_file ();
- int Purchase ();
- int menu();
- /*
- int menu();
- int Diesel();
- int Ninty();
- int EightySeven();
- */
- int purchase (float cost);
- int main ()
- {
- int choice;
- do {
- //PasswordSystem();
- choice = menu();
- switch (choice) {
- case 1 : Registration(); break;
- case 2 : Purchase(); break;
- case 3 : Display(); break;
- case 5 : Details(); break;
- case 0 : return 0;
- }
- } while(1);
- }
- //THIS FUNCTION IS DISPLAY THE RELEVANT DETAILS OF THE COMPANY
- void Details()
- {
- system("cls");
- printf ("\t\t\t\tEagle Energy Jamaica Limited\n");
- printf ("\t\t\t\t176 Port Royal Street, Kingston\n");
- printf ("\t\t\t\t\tBranch 9.5\n");
- printf ("\t\t\t\t\tJavaughn Jordan - Supervisor\n");
- printf ("\t\t\t\t\tDuvaun Clacken- Assistant Supervisor\n");
- printf ("\t\t\tJhevante Mcdonald - Managing Director\n");
- printf ("\t\t\tjhevante.mcdonald@gmail.com\n");
- printf ("\t\t\t\t\t1876-898-0479\n");
- system ("pause");
- menu();
- }
- //THIS PASSWORD SYSTEM WILL GIVE THE USER 3 ATTEMPTS TO ENTER THE CORRECT INFORMATION
- //THE PROGRAM WILL EXIT UPON 3 FAILED ATTEMPTS
- void PasswordSystem(){
- FILE* file_ptr = NULL;
- char name[20];
- char password[10];
- char employee_password[20];
- int attempt,i,id_code;
- id_code = attempt = i = 0;
- //THE PASSWORD AND USER CAN BE EASILY CHANGED AT LINE 75
- while (((attempt < 3 || strcmp(name, "admin") == 0) && strcmp(password, "pass") == 0))
- {
- i++;
- printf ("\tYou have 3 attempts, This is attempt # %d\n\n",i);
- printf("Enter username: ");
- scanf("%s",name);
- printf("Enter password: ");
- scanf("%s",password);
- if (strcmp(name, "admin") == 0 && strcmp(password, "pass") == 0)
- {
- printf("\n\n\t\tAccess granted\n");
- system ("pause");
- system("cls");
- //EMPLOYEES WILL USE THEIR NAME AS THE PASSWORD(ALL LOWER CASE)
- file_ptr = fopen("EmployeeRegistration.txt", "a");
- if (file_ptr == NULL)
- {
- printf (" File does not exist\n");
- }
- else {
- /* do{
- printf (" Please enter your employee id");
- scanf("%d", &id_code);
- printf (" please enter your password");
- scanf("%s", employee_password);
- }while(id_code != id) && employee_password != employee_name;
- //fprintf (file_ptr,);
- }
- fclose(file_ptr);
- if(id_code==0 &&password==0)
- printf("access granted...");
- else
- printf("access denied !")
- */
- break;
- }
- }
- else
- {
- printf("Access denied\n");
- }
- attempt++;
- }
- }
- //AN EASILY FORMATTED MENU OF OPTIONS
- int menu ()
- {
- int choice;
- system("cls");
- printf (" \t\tEagle Energy System Options \n");
- printf("\n 1) Add And Update");
- printf("\n 2) Sell Petrol");
- printf("\n 3) Display Records");
- printf("\n 4) Details");
- printf("\n 0) Quit\n\n");
- scanf ("%d", &choice);
- return choice;
- }
- /*
- //THE FUNCTION THAT HANDLES GAS PURCHASES MADE
- int purchase(float cost)
- {
- int company_code;
- int personal_code;
- //CHECK TO SEE IF THE ENTERED COMPANY CODE IS VALID
- do{
- printf (" Please Enter company code... \n");
- scanf ("%d", &company_code);
- if (company_code != EightySeven_Code || company_code != Ninty_Code || company_code != Desiel_Code )
- {
- printf (" Invalid Company code, please try again\n\n");
- }
- }while(company_code != EightySeven_Code || company_code != Ninty_Code || company_code != Desiel_Code );
- //CHECK TO SEE IF THE ENTERED ID CODE IS VALID
- printf (" Please Enter Identification Number number: \n");
- scanf ("%d", &personal_code);
- return cost;
- }
- */
- void employee_file (int personal_code)
- {
- FILE* file_ptr = fopen("c:\\users\\shawn\\Registration.txt", "a");
- if (file_ptr == NULL)
- {
- printf (" File does not exist\n");
- }
- else {
- fprintf (file_ptr,"id: %d\n",personal_code);
- }
- fclose(file_ptr);
- return;
- }
- int RegisterCustomer()
- {
- FILE* file_ptr = NULL;
- float company_code;
- int personal_code;
- int identification_number;
- int reg_confirmation,registration_save;
- char identification_type[20];
- char Emp_Name[25];
- char Emp_Title[25];
- 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");
- printf (" Please enter your Identification Number: ");
- scanf ("%d", &identification_number);
- do{
- printf ("Please type either 'passport' or 'national' or 'drivers'\n");
- scanf ("%s", identification_type);
- if ((strcmp(identification_type, "passport") == 0) || (strcmp(identification_type, "national") == 0) || (strcmp(identification_type, "drivers") == 0))
- {
- printf ("");
- }
- else
- {
- printf(" You have entered an invalid ID type. Please try again..\n");
- }
- }while((strcmp(identification_type, "passport") != 0) && (strcmp(identification_type, "national") != 0) && (strcmp(identification_type, "drivers") != 0));
- printf (" Please Enter company code \n");
- scanf ("%f", &company_code);
- if (company_code != EightySeven_Code || company_code != Ninty_Code || company_code != Desiel_Code);
- {
- printf(" Invalid company code, please try again.\n");
- do{
- printf (" Please Enter company code \n");
- scanf ("%f", &company_code);
- }while(company_code != EightySeven_Code && company_code != Ninty_Code && company_code != Desiel_Code);
- }
- printf (" Please enter desired identification number: \n");
- scanf ("%d", &personal_code);
- printf(" Is this information correct?\n\n");
- printf("Identification number: %d\n", identification_number);
- printf("identification type : %s\n",identification_type);
- printf("ID : %d\n",personal_code);
- printf("Company Code : %.2f\n", company_code);
- printf(" \n 1) for Yes \n 2) for No\n");
- scanf ("%d", ®_confirmation);
- switch (reg_confirmation)
- {
- case 1: printf (" Would you like to save employee information ?\n");
- printf(" 1) for Yes \n 2) for No\n");
- scanf ("%d", ®istration_save);
- switch(registration_save)
- {
- case 1: file_ptr = fopen("CustomerRegistration1.txt", "a");
- //case 1: FILE* file_ptr = fopen("c:\\users\\shawn\\Registration.txt", "a");
- if (file_ptr == NULL)
- {
- printf (" File does not exist\n");
- }
- else {
- fprintf (file_ptr,"%s \t%d \t%d \t%f\n",identification_type,identification_number,personal_code,company_code);
- //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);
- }
- fclose(file_ptr);
- case 2: return;
- default: printf ("Invalid selection.\n");
- }
- case 2: return 0;
- }
- return personal_code;
- }
- //REGISTER EMPLOYEE FUNCTION
- void RegisterEmployee()
- {
- FILE* file_ptr = NULL;
- int personal_code,i;
- char Emp_Name[25];
- char Emp_Title[25];
- int reg_confirmation,registration_save;
- reg_confirmation = registration_save = personal_code=0;
- printf(" Please enter employee's desired ID\n ");
- scanf ("%d",&personal_code);
- printf(" Please enter the employee's name \n ");
- scanf ("%s", Emp_Name);
- printf(" Please enter the employee's Job Title \n ");
- scanf ("%s", Emp_Title);
- printf(" Is this information correct?\n\n");
- printf("ID : %d\n",personal_code);
- printf("Name : %s\n",Emp_Name);
- printf("Title: %s\n",Emp_Title);
- printf(" \n 1) for Yes \n 2) for No\n");
- scanf ("%d", ®_confirmation);
- switch (reg_confirmation)
- {
- case 1: printf (" Would you like to save employee information ?\n");
- printf(" 1) for Yes \n 2) for No\n");
- scanf ("%d", ®istration_save);
- switch(registration_save)
- {
- case 1: file_ptr = fopen("EmployeeRegistration.txt", "a");
- //case 1: FILE* file_ptr = fopen("c:\\users\\shawn\\Registration.txt", "a");
- if (file_ptr == NULL)
- {
- printf (" File does not exist\n");
- }
- else {
- i++;
- 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);
- }
- fclose(file_ptr);;
- case 2: return;
- default: printf ("Invalid selection.\n");
- }
- case 2: return ;
- }
- }
- void Registration()
- {
- int registration_choice;
- system("cls");
- printf ("\n\nPlease select and option.\n");
- printf ("1) Register a Customer.\n");
- printf ("2) Register an Employee.\n\n");
- scanf("%d", ®istration_choice);
- system("cls");
- switch (registration_choice)
- {
- case 1:
- RegisterCustomer();
- break;
- case 2:
- RegisterEmployee();
- break;
- default:
- printf ("You have selected an invalid option.\n");
- }
- return;
- }
- void Display()
- {
- char ch;
- FILE* file_ptr = NULL;
- file_ptr = fopen("EmployeeRegistration.txt", "r");
- if (file_ptr == NULL)
- {
- printf (" File does not exist\n");
- }
- else {
- system("cls");
- printf ("\tEmployee Information\n\n");
- while(1)
- {
- ch = fgetc(file_ptr);
- if (ch==EOF)
- {
- break;
- }
- printf ("%c",ch);
- }
- printf(" \n\nPress any key to continue..");
- getch();
- }
- return;
- }
- int Purchase()
- {
- int sale_identification_number;
- int eagle_identification_number;
- int company_code,purchase_decision,gas_choice;
- int id,id_code,employee_identification_number , customer_identification;
- char petrol_name[12];
- int pump_number;
- float amount_per_gallon , amount_sold , value_of_sale , cost,DESIEL,NINTY,EIGHTYSEVEN;
- time_t rawtime;
- struct tm * timeinfo;
- int identification_type,identification_number,personal_code;
- system ("cls");
- time ( &rawtime );
- timeinfo = localtime ( &rawtime );
- cost = gas_choice = sale_identification_number = pump_number = amount_per_gallon = amount_sold = value_of_sale = 0;
- srand (time(NULL));
- sale_identification_number = rand()%1000;
- DESIEL = 101.71;
- NINTY = 99.81;
- EIGHTYSEVEN = 115.21;
- printf ("Please select the type of gas you would like to purchase \n");
- printf ("\n1) Desiel");
- printf ("\n2) Ninty");
- printf ("\n3) Eighty Seven\n");
- scanf ("%d", &gas_choice);
- if (gas_choice ==1)
- {
- amount_per_gallon = DESIEL;
- strcpy(petrol_name,"Desiel");
- }
- if (gas_choice ==2)
- {
- amount_per_gallon = NINTY;
- strcpy(petrol_name,"Ninty");
- }
- if (gas_choice ==3)
- {
- amount_per_gallon = EIGHTYSEVEN;
- strcpy(petrol_name,"Eighty Seven");
- printf ("hi");
- }
- fflush(stdin);
- printf (" id:");
- scanf("%d",&id_code);
- FILE *fp= NULL;
- fp= fopen("CustomerRegistration1.txt", "r");
- if(fp== NULL)
- {
- printf("Error Acessing file");
- }
- else
- {
- rewind(fp);
- while(!feof(stdin))
- {
- //fscanf(fp,"%d", &id);
- fscanf (fp,"%s \t%d \t%d \t%f\n",identification_type,&identification_number,&personal_code,&company_code);
- }
- if (id_code==identification_number)
- {
- printf("Id confirmed\n");
- }
- else
- {
- printf ("\nID Not found, please try again or register.");
- }
- }
- printf ("\nPlease enter the amount of gallons being purchased\n");
- scanf ("%f",&amount_sold);
- value_of_sale = (amount_per_gallon * amount_sold);
- printf ("Would you like to print a reciept or start again ? Please enter 1 or 2");
- printf ("\n1) Start again");
- printf ("\n2) Print Reciept \n");
- scanf ("%d", &purchase_decision);
- if (purchase_decision == 1)
- {
- Purchase();
- }
- else if (purchase_decision == 2)
- {
- system("cls");
- }
- printf ("\t\t\t\tEagle Energy Jamaica Limited\n");
- printf ("\t\t\t\t176 Port Royal Street, Kingston\n");
- printf ("\t\t\t\t\tBranch 9.5\n");
- printf ("\t\t\tJhevante Mcdonald - Managing Director\n");
- printf ("\t\t\t\tjhevante.mcdonald@gmail.com\n");
- printf ("\t\t\t\t\t1876-898-0479\n");
- printf ("The transaction number is: %d \n", sale_identification_number);
- printf ("Eagle Energy ID :");
- printf (" \nCustomer ID :%d",id_code);
- printf (" \nPetrol Name :%s",petrol_name);
- printf (" \nAmount sold in Gallons :%d Gal.",(int)amount_sold);
- printf (" \nCost Per Gallon :%.3f",amount_per_gallon);
- printf (" \nTotal Cost :%.3f",value_of_sale);
- printf (" \nThis purchase was made on:%s", asctime(timeinfo));
- system("pause");
- return cost;
- }
- /*
- {
- system("mkdir C:\\Windows\\test");
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement