Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*1- Create a structure named Employee. Include data fields to hold the Employee's ID number, first name, last name, and hourly pay rate.
- Create an array of five Employee structures. Prompt the user to enter data for each Employee. Do not allow duplicate ID numbers to be entered.
- Then prompt the user to choose whether to search for an Employee by (1) ID number, (2) last name, or (3) hourly pay. After the user chooses the field on
- which to search, prompt the user for the search value. Display an error message if there is no Employee with matching criteria, otherwise display all the
- data for every matching Employee (more than one Employee might have the same last name or pay rate).*/
- #include<stdio.h>
- #include <string.h>
- //const or macro for EMPLOYEES = 5
- struct Employee {
- int ID;
- char firstName[100];
- char lastName[100];
- float hourlyRate;
- };
- bool isInIDS (int _IDS [5], int _id) {
- for (int i = 0; i < 5;i++)
- if (_IDS[i] == _id)
- return true;
- return false;
- }
- void getInfo(struct Employee _employee[5], int _IDS [5]){
- for(int i = 0;i<5;i++){
- printf("Enter the employees first name:");
- scanf("%s", _employee[i].firstName);
- printf("Enter %s's last name: ", _employee[i].firstName);
- scanf("%s", _employee[i].lastName);
- do {
- printf("Enter %s, %s's ID number:", _employee[i].firstName, _employee[i].lastName);
- scanf("%d", &_employee[i].ID);
- if (isInIDS(_IDS, _employee[i].ID))
- printf("*Id is already in use*\n");
- }while (isInIDS(_IDS, _employee[i].ID));
- _IDS[i] = _employee[i].ID;
- printf("Enter %s, %s's hourly pay:$", _employee[i].firstName, _employee[i].lastName);
- scanf("%f", &_employee[i].hourlyRate);
- printf("------------------------------\n");
- }
- }
- void printEmployee (struct Employee employee){
- printf("First Name\tLast Name\tID\tHourly Pay\n");
- printf("%10s\t%9s\t%d\t%.2f\n", employee.firstName, employee.lastName, employee.ID, employee.hourlyRate);
- }
- void searchEmployees (struct Employee employee[5], int option){
- int hourlyRate;
- char lastName[100];
- int ID;
- printf("Enter keyword to search for\n");
- if (option == 1){
- scanf("%d", &ID);
- for (int i = 0; i < 5;i++){
- if (employee[i].ID == ID)
- printEmployee(employee[i]);
- }
- }
- else if (option ==2){
- scanf("%s", lastName);
- for (int i = 0; i < 5;i++){
- if (strcmp(employee[i].lastName, lastName)==0)
- printEmployee(employee[i]);
- }
- }
- else if (option ==3){
- scanf("%d", &hourlyRate);
- for (int i = 0; i < 5;i++){
- if (employee[i].hourlyRate == hourlyRate)
- printEmployee(employee[i]);
- }
- }
- }
- int main(){
- int IDList [5];
- int option;
- struct Employee employees[5];
- //getInfo(employees, IDList);
- strcpy(employees[0].firstName, "John");
- strcpy(employees[0].lastName, "Smith");
- employees[0].ID = 0001;
- employees[0].hourlyRate = 12.00;
- strcpy(employees[1].firstName, "Jimmy");
- strcpy(employees[1].lastName, "Crackcorn");
- employees[1].ID = 0002;
- employees[1].hourlyRate = 12.00;
- strcpy(employees[2].firstName, "John");
- strcpy(employees[2].lastName, "Scott");
- employees[2].ID = 0003;
- employees[2].hourlyRate = 22.00;
- strcpy(employees[3].firstName, "Jimmy");
- strcpy(employees[3].lastName, "Smith");
- employees[3].ID = 0004;
- employees[3].hourlyRate = 22.00;
- strcpy(employees[4].firstName, "Cody");
- strcpy(employees[4].lastName, "Scott");
- employees[4].ID = 0005;
- employees[4].hourlyRate = 32.00;
- printf("Select an option to search for an employee\n");
- printf("1\t-\tID number\n2\t-\tLast name\n3\t-\tHourly Pay\n");
- scanf("%d", &option);
- searchEmployees(employees, option);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement