C LANGUAGE ONLY!!!!!!!! Please include or provide with a link of whatever files
ID: 3557941 • Letter: C
Question
C LANGUAGE ONLY!!!!!!!!
Please include or provide with a link of whatever files are required or send to aimhigh1900@yahoo.com. Full points will be given if the program runs. Your task as a programmer is to create a menu driven program. Your program must-reads from already existing data file data.txt which contains the unknown number of records. You may think of record as struct in C: Define Employee as struct with the following field: First Name Last Name Gender Social Security Age Hours Worked Rate A pointer to Employee The salary should be calculated on the weekly basis of 40 hours. Any time over 40 hours worked, is considered to be overtime. When working overtime, employees get paid 1.5 of their normal salary. (For example: If an employee worked an hour overtime, and he was normally paid $20.00 per hour, his overtime would be calculated as $20.00 x 1.5 = $30.00) Since you have unknown number of records in Data.txt file. You must create A link list. Your Menu should allow the user to add, delete, print, sort by last name and Save the result of operation into file name result.txt. Sample 1. List all employees to the screen with their salary. 2. Add an employee to the payroll. 3. Delete an employee from the payroll. 4. List all the female employees. 5. List all employees with overtime. Alphabetize the list of employees. Who gets the highest salary? 8. Quit and Save. Extra Credit: provide necessary functions to allow two employee of opposite Sex to get married or divorce. Also function to print married people with their Spouse first name.
Explanation / Answer
The program itself is complete you can copy paste it entirely ..
If you need the c file pls comment i'll post it into my one-drive
/**
* A menu-driven program for elementary database management
* @author: Chaos12
* @language: C
* This program uses file handling in Binary mode
*/
// List of library functions
#include <stdio.h> //for input output functions like printf, scanf
#include <stdlib.h>
#include <conio.h>
#include <string.h> //string operations
/** List of Global Variable */
/**
function : gotoxy
@param input: x and y coordinates
@param output: moves the cursor in specified position of console
*/
/** Main function started */
int main(){
FILE *fp, *ft; // file pointers
char another, choice;
/** structure that represent a employee */
struct emp{
char fname[40]; //first name of employee
char lname[40]; //last name of employee
char gender;//Gender of employee
char ssecurity[9];//Social security (US) 9 digit
int age; // age of employee
float hw; // overtime of employee
};
struct emp e; // structure variable creation
char empname[40]; // string to store name of the employee
long int recsize; // size of each record of employee
float tmp; //for temporary salary calculations
/** open the file in binary read and write mode
* if the file result.txt already exists then it open that file in read write mode
* if the file doesn't exit it simply create a new copy
*/
fp = fopen("result.txt","rb+");
if(fp == NULL){
fp = fopen("result.txt","wb+");
if(fp == NULL){
printf("Connot open file");
exit(1);
}
}
// sizeo of each record i.e. size of structure variable e
recsize = sizeof(e);
// infinite loop continues untile the break statement encounter
while(1){
system("cls"); //clear the console window
gotoxy(30,10); // move the cursor to postion 30, 10 from top-left corner
printf("1. List all employees to the screen with their salary"); // List all employees to the screen with their salary.
gotoxy(30,12);
printf("2. Add an employee to the payroll."); // option for adding an employee to the payroll.
gotoxy(30,14);
printf("3. Delete an employee from the payroll."); // option for deleting an employee from the payroll.
gotoxy(30,16);
printf("4. List all the female employees."); // option for listing all the female employees.
gotoxy(30,18);
printf("5.List all employees with overtime"); // option for listing all employees with overtime
gotoxy(30,20);
printf("6. Exit"); // exit from the program
gotoxy(30,22);
printf("Your Choice: "); // enter the choice 1, 2, 3, 4, 5, 6
fflush(stdin); // flush the input buffer
choice = getche(); // get the input from keyboard
switch(choice){
case '1': // if user press 1
system("cls");
rewind(fp); //this moves file cursor to start of the file
while(fread(&e,recsize,1,fp)==1){ // read the file and fetch the record one record per fetch
tmp=40*20+1.5*e.hw; //salary calculations
printf(" First Name: %s Last Name: %s Gender (M/F) :%s Age : %d Social security id :%s Salary %.2f ",e.fname,e.lname,e.gender,e.age,e.ssecurity,tmp); // print the name, age , overtime ....
}
getch();
break;
case '2':
system("cls");
fseek(fp,0,SEEK_END); // search the file and move cursor to end of the file
// here 0 indicates moving 0 distance from the end of the file
another = 'y';
while(another == 'y'){ // if user want to add another record
printf(" Enter first name: ");
scanf("%s",e.fname);
printf(" Enter last name: ");
scanf("%s",e.lname);
printf(" Enter Gender: ");
scanf("%s",e.gender);
printf(" Enter age: ");
scanf("%d", &e.age);
printf(" Enter Social Security id: ");
scanf("%s",e.ssecurity);
printf(" Enter Overtime Hours: ");
scanf("%f", &e.hw);
fwrite(&e,recsize,1,fp); // write the record in the file
printf(" Add another record(y/n) ");
fflush(stdin);
another = getche();
}
break;
case '3':
system("cls");
another = 'y';
while(another == 'y'){
printf(" Enter First name of employee to delete: ");
scanf("%s",empname);
ft = fopen("Tresult.txt","wb"); // create a intermediate file for temporary storage
rewind(fp); // move record to starting of file
while(fread(&e,recsize,1,fp) == 1){ // read all records from file
if(strcmp(e.fname,empname) != 0){ // if the entered record match
fwrite(&e,recsize,1,ft); // move all records except the one that is to be deleted to temp file
}
}
fclose(fp);
fclose(ft);
remove("result.txt"); // remove the orginal file
rename("Tresult.txt","result.txt"); // rename the temp file to original file name
fp = fopen("result.txt", "rb+");
printf("Delete another record(y/n)");
fflush(stdin);
another = getche();
}
break;
case '4': // if user press 4 then list all female employees
system("cls");
printf("List of female employees ");
rewind(fp);
while(fread(&e,recsize,1,fp)==1){ // fetch all record from file
if(e.gender == 'F'){
tmp=40*20+1.5*e.hw; //salary calculations
printf(" First Name: %s Last Name: %s Gender (M/F) :%s Age : %d Social security id :%s Salary %.2f ",e.fname,e.lname,e.gender,e.age,e.ssecurity,tmp); // print the name, age , overtime ....
}
}
fflush(stdin);
break;
case '5': // if user press 5 then list all employees with overtime
system("cls");
printf("List of employees with overtime");
rewind(fp);
while(fread(&e,recsize,1,fp)==1){ // fetch all record from file
if(e.hw == NULL || e.hw ==0 ){ // if this line gives an erreo replace it with "if(e.hw ==0 )
tmp=40*20+1.5*e.hw; //salary calculations
printf(" First Name: %s Last Name: %s Gender (M/F) :%s Age : %d Social security id :%s Salary %.2f ",e.fname,e.lname,e.gender,e.age,e.ssecurity,tmp); // print the name, age , overtime ....
}
}
fflush(stdin);
break;
case '6':
fclose(fp); // close the file
exit(0); // exit from the program
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.