In: Computer Science
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:
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;
struct date
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!! */
Name
MouseMinnie Johnny M Carson
Total Payroll
Jim's Employees Payroll Report – 9/22/2020 --------------------------------------------------------
Hire Date Hrs Rate Gross Pay Taxes 401K Net Pay
01/02/1993 40.00 33.50 1340.00 281.40 40.20 1018.40 11/17/1942 30.00 50.00 1500.00 315.00 37.50 1147.50
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.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct info
{
char Name[40];
char address[40];
char city[30];
char state[10];
long zip;
int age;
char gender;
};
int main()
{
struct info people[10];
int num,i;
printf("Information extracted from structure\n");
printf("Number of names contained? ");
scanf("%d",&num);
fflush(stdin);
printf("\n\n");
for(i=0;i<num;i++)
{
printf("Enter name: ");
gets(people[i].Name);
printf("Enter street Address: ");
gets(people[i].address);
printf("Enter city: ");
gets(people[i].city);
printf("Enter state(2 chars only): ");
gets(people[i].state);
printf("Enter zipcode: ");
scanf("%ld",&people[i].zip);
printf("Enter Age: ");
scanf("%d",&people[i].age);
while(people[i].age<1||people[i].age>120)
{printf("must be between 1 and 120\n");
printf("\nEnter Age:");
scanf("%d",&people[i].age);
}
printf("Enter gender(M or F): ");
scanf("%s",&people[i].gender);
fflush(stdin);
printf("\n");
}
printf("The information you entered is:\n");
for(i=0;i<num;i++)
{
printf("\n");
puts(people[i].Name);
puts(people[i].address);
printf("%s",people[i].city);
printf(" %s",people[i].state);
printf(" %05ld",people[i].zip);
if(people[i].gender=='m'||people[i].gender== 'M')
printf("\nHe is %d years old",people[i].age);
else
printf("\nShe is %d years old",people[i].age);
printf("\n");
}
getch();
return 0;
}
Note: If you have any related doubts, queries, feel free to ask by commenting down below.
And if my answer suffice your requirements, then kindly upvote.
Happy Learning