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>
- struct employee
- {
- int personal_code;
- char Emp_Name[25];
- char Emp_Title[25];
- }EMPLOYEE;
- struct customer
- {
- float company_code;
- int personal_code;
- int identification_number;
- int reg_confirmation,registration_save;
- char identification_type[20];
- }CUSTOMER;
- struct company
- {
- int company_id;
- char company_name[20];
- char contact_person[20];
- int contact_number;
- }COMPANY;
- struct salesdata
- {
- }SALES;
- void Registration();
- int RegisterCustomer();
- void RegisterEmployee();
- void RegisterCompany();
- void UpdateCompany();
- void UpdateEmployee();
- void UpdateCustomer();
- void PasswordSystem();
- void Details ();
- void Display();
- void DisplayCustomer();
- void DisplayEmployee();
- void DisplayPurchases(float);
- float Purchase ();
- int menu();
- void Credit();
- float EightySeven_Code = 8.7;
- float Ninty_Code = 9.0;
- float Desiel_Code =9.5;
- int main ()
- {
- int choice;
- //PasswordSystem();
- do {
- choice = menu();
- switch (choice)
- {
- case 1 : Registration(); break;
- case 2 : Purchase(); break;
- case 3 : Display(); break;
- case 4 : Details(); break;
- case 0 : return 0;
- }
- } while(1);
- }
- void RegisterCompany()
- {
- /*int i;
- COMPANY c[3];
- FILE *file_ptr = NULL;
- file_ptr=fopen("ComnanyInfo.txt","ab+");
- for (i=1;i==3;i++)
- {
- if (i=1)
- {
- COMPANY[0].company_id = Ninty_Code;
- strcpy(COMPANY[0].company_name, "90 Petrol JA");
- strcpy(COMPANY[0].contact_person,"Jhevante");
- COMPANY[0].contact_number = 18768980479;
- }
- if (i=2)
- {
- //87 COMPANY
- COMPANY[1].company_id = EightySeven_Code;
- strcpy(COMPANY[1].company_name, "Seven-Ate-9");
- strcpy(COMPANY[1].contact_person,"Tami");
- COMPANY[1].contact_number = 911;
- }
- if (i=3)
- {
- //DESIEL COMPANY
- COMPANY[2].company_id = Desiel_Code;
- strcpy(COMPANY[2].company_name, "Vinn Desiel");
- strcpy(COMPANY[2].contact_person,"hello");
- COMPANY[2].contact_number = 1;
- }
- fwite(a,sizeof(COMPANY),1,file_ptr);
- }
- fclose(fileptr);
- }
- */
- }
- //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");
- return;
- }
- //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];
- int attempt,i;
- int id_code;
- char password1[20];
- attempt = i = 0;
- //THE SYSTEM PASSWORD AND USER CAN BE EASILY CHANGED AT LINE 109
- i++;
- printf ("\tYou have 3 attempts, This is attempt # %d\n\n",i);
- printf("Enter SYSTEM username: ");
- scanf("%s",name);
- printf("Enter SYSTEM password: ");
- scanf("%s",password);
- while (((attempt < 3 || strcmp(name, "admin") == 0) && strcmp(password, "pass") == 0))
- {
- 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", "r");
- if (file_ptr == NULL)
- {
- printf (" File does not exist\n");
- }
- else {
- printf (" Employee's password is their name\n");
- fscanf (file_ptr,"%d %s %s \n",&EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
- printf("hi1\n");
- printf("%d %s %s \n",EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
- printf("hi2\n");
- printf(" Please enter your employee ID\n");
- scanf ("%d",&id_code);
- printf(" Please enter password\n");
- scanf ("%s",password1);
- while(!feof(file_ptr))
- {
- if((id_code == EMPLOYEE.personal_code) && (strcmp(password1,EMPLOYEE.Emp_Name) == 0))
- {
- printf("access granted...");
- printf("Id confirmed\n");
- system ("pause");
- break;
- system("cls");
- }
- else
- {
- printf("access denied !");
- break;
- }
- }
- }
- }
- else {
- printf (" ");
- }
- }
- fclose(file_ptr);
- 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;
- }
- int RegisterCustomer()
- {
- float company_code;
- int registration_save,reg_confirmation,personal_code;
- FILE* file_ptr = NULL;
- personal_code = 0;
- 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", &CUSTOMER.identification_number);
- do{
- printf ("Please type either 'passport' or 'national' or 'drivers'\n");
- scanf ("%s", CUSTOMER.identification_type);
- if ((strcmp(CUSTOMER.identification_type, "passport") == 0) || (strcmp(CUSTOMER.identification_type, "national") == 0) || (strcmp(CUSTOMER.identification_type, "drivers") == 0))
- {
- printf (" ");
- }
- else
- {
- printf(" You have entered an invalid ID type. Please try again..\n");
- }
- }while((strcmp(CUSTOMER.identification_type, "passport") != 0) && (strcmp(CUSTOMER.identification_type, "national") != 0) && (strcmp(CUSTOMER.identification_type, "drivers") != 0));
- do{
- 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");
- }
- else if((company_code == EightySeven_Code) && (company_code == Ninty_Code) && (company_code == Desiel_Code));
- {
- break;
- }
- }while((company_code != EightySeven_Code) && (company_code != Ninty_Code) && (company_code != Desiel_Code));
- printf (" Please enter desired identification number: \n");
- scanf ("%d", &CUSTOMER.personal_code);
- printf(" Is this information correct?\n\n");
- printf("Identification number: %d\n", CUSTOMER.identification_number);
- printf("identification type : %s\n",CUSTOMER.identification_type);
- printf("ID : %d\n",CUSTOMER.personal_code);
- printf("Company Code : %.1f\n", CUSTOMER.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 %d %d %f\n",CUSTOMER.identification_type,CUSTOMER.identification_number,CUSTOMER.personal_code,company_code);
- }
- fclose(file_ptr);
- case 2: return 0;
- default: printf ("Invalid selection.\n");
- }
- case 2: return 0;
- }
- return personal_code;
- }
- //REGISTER EMPLOYEE FUNCTION
- void RegisterEmployee()
- {
- FILE* file_ptr = NULL;
- int personal_code;
- int reg_confirmation,registration_save;
- reg_confirmation = registration_save = personal_code=0;
- do{
- printf(" Please enter employee's desired ID\n ");
- scanf ("%d",&EMPLOYEE.personal_code);
- printf(" Please enter the employee's First name \n ");
- scanf ("%s", EMPLOYEE.Emp_Name);
- printf(" Please enter the employee's Job Title \n ");
- scanf ("%s", EMPLOYEE.Emp_Title);
- printf(" Is this information correct?\n\n");
- printf("ID : %d\n",EMPLOYEE.personal_code);
- printf("Name : %s\n",EMPLOYEE.Emp_Name);
- printf("Title: %s\n",EMPLOYEE.Emp_Title);
- printf(" \n 1) Yes \n 2) Retry\n 3) Return to main menu..\n");
- scanf ("%d", ®_confirmation);
- }while((reg_confirmation != 1) && (reg_confirmation!=3));
- 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 {
- fprintf (file_ptr,"%d %s %s \n",EMPLOYEE.personal_code,EMPLOYEE.Emp_Name,EMPLOYEE.Emp_Title);
- }
- fclose(file_ptr);
- case 2: return;
- default: printf ("Invalid selection.\n");
- }
- case 2: return ;
- }
- }
- void Register1()
- {
- int registration_choice;
- registration_choice=0;
- printf ("\n\nPlease select and option.\n");
- printf ("1) Register a Customer.\n");
- printf ("2) Update an Employee.\n\n");
- scanf("%d", ®istration_choice);
- switch (registration_choice)
- {
- case 1:
- RegisterCustomer();
- break;
- case 2:
- RegisterEmployee();
- break;
- default:
- printf ("You have selected an invalid option.\n");
- }
- return;
- }
- void Registration()
- {
- int registration_choice;
- system("cls");
- printf ("\n\nPlease select and option.\n");
- printf ("1) Register a Customer/Employee.\n");
- printf ("2) Update a Customer/Employee.\n\n");
- scanf("%d", ®istration_choice);
- system("cls");
- switch (registration_choice)
- {
- case 1:
- Register1();
- break;
- case 2:
- UpdateEmployee();
- break;
- default:
- printf ("You have selected an invalid option.\n");
- }
- return;
- }
- void Display()
- {
- int displaychoice;
- displaychoice = 0;
- printf(" What data would you like to display ?\n");
- printf ("1)Customer Information\n");
- printf ("2)Employee Information\n");
- printf ("3)Purchase Information\n");
- scanf("%d",&displaychoice);
- switch (displaychoice)
- {
- case 1 : DisplayCustomer();
- break;
- case 2 : DisplayEmployee();
- break;
- // case 3 : DisplayPurchases(float cost );
- // break;
- }
- }
- void DisplayPurchases(float cost)
- {
- }
- void DisplayCustomer()
- {
- char ch;
- FILE* file_ptr = NULL;
- file_ptr = fopen("CustomerRegistration.txt", "r");
- if (file_ptr == NULL)
- {
- printf (" File does not exist\n");
- }
- else {
- system("cls");
- printf ("\tEmployee Information\n\n");
- printf ("Id Name Title\n");
- while(1)
- {
- ch = fgetc(file_ptr);
- if (ch==EOF)
- {
- break;
- }
- printf ("%c",ch);
- }
- printf(" \n\nPress any key to continue..");
- getch();
- }
- return;
- }
- void DisplayEmployee()
- {
- 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");
- printf ("Id Name Title\n");
- while(1)
- {
- ch = fgetc(file_ptr);
- if (ch==EOF)
- {
- break;
- }
- printf ("%c",ch);
- }
- printf(" \n\nPress any key to continue..");
- getch();
- }
- return;
- }
- float Purchase()
- {
- int sale_identification_number;
- int purchase_decision,gas_choice;
- int id_code;
- char petrol_name[12];
- int pump_number;
- float amount_per_gallon , amount_sold , value_of_sale , cost,DESIEL,NINTY,EIGHTYSEVEN;
- char identification_type1[10];
- int identification_number1,personal_code1;
- float company_code1;
- time_t rawtime;
- struct tm * timeinfo;
- personal_code1= company_code1 = identification_number1 = 0;
- 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 ("Please enter customer's ID Code:");
- scanf("%d",&id_code);
- FILE *fp= NULL;
- fp= fopen("CustomerRegistration1.txt", "r");
- if(fp== NULL)
- {
- printf("Error Acessing file");
- }
- else
- {
- while(!feof(fp))
- {
- //fscanf(fp,"%d", &id);
- fscanf (fp,"%s %d %d %f\n",identification_type1,&identification_number1,&personal_code1,&company_code1);
- if (id_code==identification_number1)
- {
- printf("Id confirmed\n");
- system ("pause");
- getch();
- system("cls");
- }
- else
- {
- printf ("\nID Not found, please try again or register.");
- }
- }
- fclose(fp);
- }
- 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));
- cost = value_of_sale;
- system("pause");
- return cost;
- }
- /*
- void Credit ()
- {
- int card_id_number;
- char contact_email[20];
- char contact_person[20];
- char company_name[20];
- float company_id_number;
- }
- */
- void UpdateEmployee()
- {
- struct employee y ={0,"Jhev","Boss"};
- FILE* file_ptr = NULL;
- file_ptr = fopen("EmployeeRegistration.txt", "rb");
- if (file_ptr == NULL)
- {
- printf (" Error opening file..\n");
- }
- else {
- fread(&y,sizeof(EMPLOYEE),1,file_ptr);
- printf ("%d",EMPLOYEE.personal_code);
- printf ("%s",EMPLOYEE.Emp_Name);
- printf ("%s",EMPLOYEE.Emp_Title);
- }
- fclose(file_ptr);
- }
- void UpdateCustomer()
- {
- }
- void UpdateCompany()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement