Question

In: Computer Science

Write a C program that prompts the user to enter some information about up to 20...

Write a C program that prompts the user to enter some information about up to 20 individuals (think of a way to welcome and prompt the user). It must be stored in a structure. Once data is entered, the program output it as shown in sample run below. Your program should include a structure with a tag name of: “information”. It should contain the following data as members: a struct to store employee's name, defined as: struct name fullname e.g. a float to store employee's pay_rate, a float to store employee's hours, a float to store employee's retirement percentage, a struct to store a hire date, defined as: struct date the data type struct name will consist of: char last_name[20]; char first name [15]; char middle initial[1]; and the data type struct date: int yyyy; int mm; int dd; You need to define an array of type: struct information. You can call this array: employees[20] or whatever name you wish. Use a 21% tax rate. The dialog with the user must be as follows:

Whatever Title you want Here

How many employees do you wish to process? 2

Employee #1: Enter first name: Minnie

Enter last name: Mouse

Enter middle initial:

Enter hours worked: 40

Enter pay_rate: 33.50

Enter 401K percentage:.03

Enter hire date (mm/dd/yyyy): 01/02/1993

Employee #2:

Enter first name: Johnny

Enter last name: Carson

Enter middle initial: M Enter hours worked: 30

Enter pay_rate:

50 Enter 401K percentage: .025

Enter hire date (mm/dd/yyyy): 11/10/1942 /

*After the entries a report will come out. You may design it yourself or use this sample as a template. Make sure decimals align!! */

Jim's Employees Payroll Report – 9/22/2020 --------------------------------------------------------

Name Hire Date Hrs Rate Gross Pay Taxes 401K Net Pay Mouse Minnie 01/02/1993 40.00 33.50 1340.00 281.40 40.20 1018.40 Johnny M Carson 11/17/1942 30.00 50.00 1500.00 315.00 37.50 1147.50 Total Payroll 70.00 83.50 2840.00 596.40 77.70 2165.90 Note:

The black text represents the "output" from your program and is shown for clarity only here. Also note that what the user types in is indicated by the blue area above. I also did not show examples of data validation – which you can handle in your own way. Hints/other requirements: • Use safer_gets to read in character array data. • You should use %di (instead of %i) as the format specifier for the date fields because if you enter an integer item starting with the number 0 (zero), C will interpret that number as "octal", which will cause erroneous results. For this reason, I recommend that you use %d in the scanf statement when prompting the user for any int type data. • You do not need to use user-defined functions or string functions in this program (however, feel free to if you'd like to). • You are not permitted to use pointers in this program. (That will be in another assignment!) • You may use some string functions from the notes and chat sessions • You need to perform validation on all the fields entered except the name. • The date can have any label you wish, like birth date, hire date, etc. • For 3 points extra credit you can have the report the current date. Good luck! (Carry On by Crosby, Stills, Nash & Young plays in the background…) (my apologies for any typos found in the description above)

Solutions

Expert Solution

#include <stdio.h>
#include<string.h>

struct information {
    
 struct fullname
               {
                   char last_name[20]; 
                   char first_name [15]; 
                   char middle_initial[1];
                   
               }fn;
 float pay_rate,hours,retirement_percentage;
 struct date{
             int yyyy;
             int mm;
             int dd;
            }dt;
  
                 
            }employee[20];      //array of structure to hold up to 20 records
            
            
int valid_date(int d,int m,int y)   // this code can be written in main() also
{
   //int d,m,y;
   int daysinmonth[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
   int valid = 0;
    // leap year checking, if ok add 29 days to february
   if(y % 400 == 0 || (y % 100 != 0 && y % 4 == 0))
    daysinmonth[1]=29;
 
   // days in month checking
   if (m<13)
   {
      if( d <= daysinmonth[m-1] )
        valid=1;
   }
 
   if (valid==1)
      printf("It is a valid date!\n");
   else
      printf("It's not valid date!");
    return valid;
}

int main()
{
    int i,n,d,m,y,valid=1;
    printf("\nWecome to employee Database\n");
    printf("\nHow many employees do you wish to process?");
    scanf("%d",&n);
    for(i=0;i<n;i++)
      {
          printf("\nEmployee #%d: Enter first name:",i+1);
          scanf("%s",employee[i].fn.first_name);  //gets() can be used to input 
          printf("\nEnter last name:");
          scanf("%s",employee[i].fn.last_name);
          printf("\n Enter middle initial:");
          scanf("%s",employee[i].fn.middle_initial);
          printf("\nEnter hours worked:");
          scanf("%f",&employee[i].hours);
         if(employee[i].hours<0)
          {
          printf("invalid:hours should be >=0");
          valid =0;break;
         }

          printf("\n Enter pay_rate:");
          scanf("%f",&employee[i].pay_rate);
        if(employee[i].pay_rate<=0)
          {
          printf("invalid:pay_rate should be >0");
          valid =0;break;
         }
          printf("\nEnter 401K percentage:");
          scanf("%f",&employee[i].retirement_percentage);
         if(!(employee[i]. retirement_percentage >0 && employee[i]. retirement_percentage<1 ))
          {
          printf("invalid: retirement_percentage should be in between 0 and 1");
          valid =0;break;
         }

          printf("\nEnter hire date (mm/dd/yyyy):");
          scanf("%d/%d/%d",&m,&d,&y);
          if(valid_date(d,m,y)==1)
          {
          employee[i].dt.mm=m;
          employee[i].dt.dd=d;
          employee[i].dt.yyyy=y;
          }
      else{ valid=0;break;}
      }
          
       if(valid==1)
        {
         printf("\nName\t Hire_Date\t Hrs\t Rate\t Gross_Pay\t Taxes\t 401K_per\t Net_Pay\n");
          for(i=0;i<n;i++)
          {
             float gross_pay=employee[i].pay_rate *employee[i].hours;
             float taxes=(gross_pay * 21)/100;
             float per=gross_pay * employee[i].retirement_percentage;
             float net_pay=gross_pay-taxes-per;
             printf("%s %s %s\t",employee[i].fn.first_name,employee[i].fn.middle_initial,employee[i].fn.last_name);
            if(employee[i].dt.mm<10)
            { printf("0%d/", employee[i].dt.mm);}
           else { printf("%d/", employee[i].dt.mm);}
           if(employee[i].dt.dd<10)
            { printf("0%d/", employee[i].dt.dd);}
           else { printf("%d/", employee[i].dt.dd);}
             printf("%d\t", employee[i].dt.yyyy);
             printf("%.2f\t%.2f\t%.2f\t%.2f\t",employee[i].hours,employee[i].pay_rate,gross_pay,taxes);
             printf("%.2f\t%.2f\n",per,net_pay);
             
          }
}
              
          
          return 0;
}
      

Related Solutions

Write a C program that prompts the user to enter some information about up to 20...
Write a C program that prompts the user to enter some information about up to 20 individuals (think of a way to welcome and prompt the user). It must be stored in a structure. Once data is entered, the program output it as shown in sample run below. Your program should include a structure with a tag name of: “information”. It should contain the following data as members: a struct to store employee's name, defined as: struct name fullname e.g....
Write a C++ console program that prompts a user to enter information for the college courses...
Write a C++ console program that prompts a user to enter information for the college courses you have completed, planned, or are in progress, and outputs it to a nicely-formatted table. Name the CPP as you wish (only use characters, underscores and number in your file name. DO NOT use blank). Its output should look something like this: Course Year Units Grade ---------- ---- ----- ----- comsc-110 2015 4 A comsc-165 2016 4 ? comsc-200 2016 4 ? comsc-155h 2014...
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
( USE C++ ) The program prompts the user to enter a word. The program then...
( USE C++ ) The program prompts the user to enter a word. The program then prints out the word with letters in backward order. For example, if the user enter "hello" then the program would print "olleh" show that it works .
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
C programming. Write a program that prompts the user to enter a 6x6 array with 0...
C programming. Write a program that prompts the user to enter a 6x6 array with 0 and 1, displays the matrix, and checks if every row and every column have the even number of 1’s.
C++ Write a program that prompts the user to enter 50 integers and stores them in...
C++ Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT