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:

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.

Solutions

Expert Solution

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


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