Question

Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...

Requesting help with the following C Program:

DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items:

  1. Enter a payroll record for one person
  2. Display all paycheck stubs
  3. Display total gross payroll from all pay records.
  4. Quit program

The program will reuse the DATE struct from the previous assignment.  You should also copy in the functions relating to a DATE.

The program will create a PAYRECORD struct with the following fields:

typedef struct {

            char name[100];

            int age;

            float hrlyWage;

            float hrsWorked;

            float regPay;

            float otPay;

            float totalPay;

            DATE payDate;

} PAYRECORD;

Requirements:

  • The program must store between 0 and 100 payroll records.
  • The user will input employee name, pay date, hours worked, and hourly rate of pay.
  • All employees are paid an hourly rate.
  • Employees get paid every week.
  • Overtime pay will be calculated as time and a half.
  • You will validate all input data:
    • Dates must be a real date
    • Hours worked must be more than zero and less than 100
    • Age must be 18 to 120
    • Hourly rate must be more than zero and less than 500 dollars

Bonus if your program stores all payroll data in a file and loads in stored payroll data from that file.

Cannot use global variables or goto statement.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include <stdio.h>
#include <stdlib.h>

#define CLS system("cls")
#define pause system("pause")

//Struct representing a date
typedef struct {
   int day;
   int month;
   int year;
} DATE;

//Struct to hold information about a payroll record
typedef struct {
   char name[100];
   int age;
   float hrlyWage;
   float hrsWorked;
   float regPay;
   float otPay;
   float totalPay;
   DATE payDate;
} PAYRECORD;

//We need an array of payroll records and a count of those records
PAYRECORD records[100000];
int recordCount = 0;

//Function prototypes
void printMenu();
void addRecord();
void searchRecords();
void sumRecords();

main() {

   char userChoice;

   //Simple menu, user exits when they select D or d
   do {
       printMenu();
       userChoice = getchar();
       getchar();


       if (userChoice == 'A' || userChoice == 'a') {
           CLS;
           addRecord();
       }
       else if (userChoice == 'B' || userChoice == 'b') {
           CLS;
           searchRecords();
       }
       else if (userChoice == 'C' || userChoice == 'c') {
           CLS;
           sumRecords();
       }
       else if (userChoice == 'D' || userChoice == 'd') {
           break;
       }
       else {
           CLS;
           printf("Invalid choice, choose a valid option!\n\n\n");
       }

   } while (userChoice != 'D' && userChoice != 'd');
}


//Prints the main menu to the user
void printMenu() {
   printf("Welcome to Payroll Management!\n\n");
   printf("Please choose an option below:\n\n");
   printf("A) Enter a new payroll record\n");
   printf("B) Search for payrolls by date\n");
   printf("C) Show aggregate payroll data\n");
   printf("D) Exit\n\n");
   printf("Select an option:     ");
}

//Function to add the user's payroll record to the array
void addRecord() {

   /*
   We start by getting information from the user about the employee, their name, age,
   number of hours worked, and salary.
   */
   printf("What is the employee's name?     ");
   gets(records[recordCount].name);

   printf("\n\nWhat is %s's age?     ", records[recordCount].name);
   scanf_s(" %d", &records[recordCount].age);

   printf("\n\nEnter their hourly salary:     ");
   scanf_s(" %f", &records[recordCount].hrlyWage);

   printf("\n\nHow many hours did %s work during this pay period?     ", records[recordCount].name);
   scanf_s(" %f", &records[recordCount].hrsWorked);

   /*
   The dates provided by the user are checked for validity, since this information must be correct
   in order for the search function to work properly. The month must be between 1 and 12, the day
   between 1 and 31, and the year between 1990 and 2017.
   */
   do {
       printf("\n\nEnter the month of the pay date (1-12):     ");
       scanf_s(" %d", &records[recordCount].payDate.month);
   } while (records[recordCount].payDate.month > 12 || records[recordCount].payDate.month < 0);

   do {
       printf("\n\nAnd the day of the month?     ");
       scanf_s(" %d", &records[recordCount].payDate.day);
   }
   while (records[recordCount].payDate.day > 31 || records[recordCount].payDate.day < 0);
  
   do {
       printf("\n\nAnd the year?     ");
       scanf_s(" %d", &records[recordCount].payDate.year);
       getchar();
   }
   while (records[recordCount].payDate.year > 2017 || records[recordCount].payDate.year < 1990);

   /*
   This program makes the assumption that the pay period is weekly. Thus, any hours worked over 40 will
   constitute overtime (OT), and are paid out at time-and-a-half (1.5x). Here, we determine how much,
   if any, overtime pay is needed.
   */
   if (records[recordCount].hrsWorked > 40) {
       records[recordCount].otPay = (records[recordCount].hrsWorked - 40) * records[recordCount].hrlyWage * 1.5;
       records[recordCount].regPay = records[recordCount].hrlyWage * 40;
   }
   else {
       records[recordCount].otPay = 0;
       records[recordCount].regPay = records[recordCount].hrsWorked * records[recordCount].hrlyWage;
   }

   //Total pay is simply normal pay + OT pay
   records[recordCount].totalPay = records[recordCount].regPay + records[recordCount].otPay;

   //The record has been added, so increment the counter
   recordCount++;

   CLS;

   printf("Payroll record successfully added!\n\n\n");
}

/*
This function asks the user to provide a date, searches the array of
payroll records for any matches, then prints out the matches back
to the user.
*/
void searchRecords() {
   DATE userDate;

   //We get the date from the user first
   do {
       printf("Enter the month of desired pay date:     ");
       scanf_s("%d", &userDate.month);
   } while (userDate.month > 12 || userDate.month < 0);

   do {
       printf("\n\nEnter the day of the month:     ");
       scanf_s("%d", &userDate.day);
   } while (userDate.day > 31 || userDate.day < 0);

   do {
       printf("\n\nEnter the year:     ");
       scanf_s("%d", &userDate.year);
       getchar();
   } while (userDate.year > 2017 || userDate.year < 1990);

   CLS;

   printf("Searching for records from %d/%d/%d\n\n", userDate.month, userDate.day, userDate.year);

   /*
   For each element in the payroll array, compare the user's date to the date in the element.
   If they are a match, print all info relating to that payorll record to the user. If not,
   go to the next element.
   */
   for (int i = 0; i < recordCount; i++) {
       if (records[i].payDate.day == userDate.day && records[i].payDate.month == userDate.month
           && records[i].payDate.year == userDate.year) {
           printf("Name: %s\n", records[i].name);
           printf("Age: %d\n", records[i].age);
           printf("Hourly wage: $%.2f/hr\n", records[i].hrlyWage);
           printf("Hours worked: %.2f\n", records[i].hrsWorked);
           printf("Regular pay: $%.2f\n", records[i].regPay);
           printf("OT pay: $%.2f\n", records[i].otPay);
           printf("Total pay: $%.2f\n\n", records[i].totalPay);
       }
   }

   pause;

   CLS;
}


/*
This function simply iterates over all the records, and sums the
individual figures (hrs worked, OT pay, etc.) into aggregate variables.
These aggregates are then printed to the user.
*/
void sumRecords() {
   float totalHrsWorked = 0;
   float totalRegPay = 0;
   float totalOtPay = 0;
   float totalTotalPay = 0;

   for (int i = 0; i < recordCount; i++) {
       totalHrsWorked += records[i].hrsWorked;
       totalRegPay += records[i].regPay;
       totalOtPay += records[i].otPay;
       totalTotalPay += records[i].totalPay;
   }

   printf("Total payroll figures:\n\n");
   printf("Hours worked: %.2f\n", totalHrsWorked);
   printf("Regular pay: $%.2f\n", totalRegPay);
   printf("OT pay: $%.2f\n", totalOtPay);
   printf("Total pay: $%.2f\n\n", totalTotalPay);

   pause;

   CLS;
}

Add a comment
Know the answer?
Add Answer to:
Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file  ...

    Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file   2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, iterators and containers. The program to process an input file below to calculate tax of 28% and output it...

  • Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee...

    Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee number, employee name, hourly pay rate, regular hours worked and overtime hours worked. The company pays its employees weekly, according to the following rules: regular pay = regular hours worked × hourly rate of pay overtime pay = overtime hours worked × hourly rate of pay × 1.5 total pay = regular pay + overtime pay Your program is to read the input data...

  • How would I do this problem? Write a C++ menu driven Payroll program. Must be user...

    How would I do this problem? Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file   2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, template, iterators and containers. The program to process an input file below to...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • Hello I am confused about this C++ program. I need to create a payroll C++ program...

    Hello I am confused about this C++ program. I need to create a payroll C++ program following these steps. Source file structure Your program will consist of three source files: main.cpp the main program Payroll.hppclass declaration for the Payroll class. Make sure you have an include guard. Payroll.cpp Payroll's member functions Class definition Create a Payroll class definition. The class has private members which originate from user input: number of hours worked hourly rate float float - and private members...

  • Inventory Program (C++) Write a program that uses a structure to store the following inventory data...

    Inventory Program (C++) Write a program that uses a structure to store the following inventory data in a file: - Item Description -Quantity on Hand -Wholesale cost -Retail cost -Date Added to Inventory The program should have a menu that allows the user to perform the following tasks: -Add new records to file -Display any record in the file -Change any record in the file Input Validation: The program should not accept quantities, or wholesale or retail costs, less than...

  • Turning this Pseudocode into the described C++ Program? (will include Pseudocode AND Description of the Program...

    Turning this Pseudocode into the described C++ Program? (will include Pseudocode AND Description of the Program below!) Pseudoode: start   Declarations num deptNum num salary num hrsWorked num SIZE = 7 num totalGross[SIZE] = 0 string DEPTS[SIZE] = “Personnel”, “Marketing”,   “Manufacturing”, “Computer Services”, “Sales”, “Accounting”, “Shipping”                                                      getReady()    while not eof detailLoop()    endwhile    finishUp() stop getReady()    output “Enter the department number, hourly salary, and number of hours worked”    input deptNum, salary, hrsWorked return detailLoop()    if deptNum >= 1 AND deptNum...

  • Write a modularized, menu-driven program to read a file with unknown number of records.

    ==============C++ or java================Write a modularized, menu-driven program to read a file with unknown number of records.Create a class Records to store the following data: first and last name, GPA , an Id number, and an emailInput file has unknown number of records; one record per line in the following order: first and last names, GPA , an Id number, and emailAll fields in the input file are separated by a tab (‘\t’) or a blank space (up to you)No error...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT