Write a C program that calculates the average salary, average rank and the average age of employees of a company. In the program, while loop, do/while loop, else statement, global variables and constant statement cannot be used. The main function should run successfully with different scenarios.
A. The main function should perform the following:
• Defines a local string variable named PartA_O10 with size equal to your ID number. Initialize PartA_O10 with the value “PartA” followed by the value of your section number and your student ID number. For example, if your section number is O7 and your student ID is 42357, the initial value of the string should be PartA_O7_42357. You can use only assignment instruction in this part. (3 points)
• Defines a local string variable named STRING_O10 with size equal to N. The value of N is equal to the product of your student ID number and your section number. For example, if your section is O7 and your student ID number is 42357, the value of N is 296499 (42357*7 = 296499). Initialize the string variable with your name, your student ID, your section number and assessment information. For example, if your name is “xxx yyy”, your ID is 42357 and your section is O7, the value of STRING_O10 will be “Course_CS159_SU_2021_Assessment_A3_Part_A_xxx_yyy_section_O7_ID_42357”. The main then prints the value of string variables STRING_O10 and PartA_O10 as below: (4 points)
PartA_O7_42357 is created by:
Course_CS159_SU_2021_Assessment_A3_Lab_Part_A_xxx_yyy_section_O7_ID_42357
• Defines a local variable of integer named RankMax_O10. Initialize RankMax_O10 with the sum of digits that are greater than 2 of your student ID. For example, if your student ID is 42357, the initial value of RankMax_O10 is 19 (4+3+5+7 = 19). You can use only assignment instruction in this part. (3 points)
• Prompts the user to enter the rank of an employee. The rank should be from 1 to RankMax_O10. If user enters a number less than 1 or greater than RankMax_O10, the main function should keep asking the user to enter a number until user enters a value from 1 to RankMax_O10. (15 points)
B. The main function should perform the following
• Prints in the screen 5 lines that contains only the character “\”. The number of “\” to be printed per line depends on your students ID number. If your student ID is 42357, the first line should contain 4 characters “\”, the second line should contain 2 characters “\”, the third line should contain 3 characters “\”, the fourth line should contain 5 characters “\” and the fifth line should contain 7 characters “\”. You can use only printf instruction in this part. To print each line you need to use a loop (5 points)
Page 3 of 5
• Defines 5 character variables named G1, G2, G3, G4 and G5. Initialize G1 with the first digit of your student ID, G2 with the second digit of your student ID, G3 with the third digit of your student ID, G4 with the fourth digit of your student ID and G5 with the fifth digit of your student ID. For example, If your student ID is 42357, G1 should contain the character ‘4’, G2 should contain character ‘2’, G3 should contain the character ‘3’, G4 should contain the character ‘5’, and G5 should contain the character ‘7’. Prints the values of these variables on the screen as below. You can use only assignment and printf instructions in this part. (5 points)
PART B STUDENT ID:
G1 is equal to 4 G2 is equal to 2 G3 is equal to 3 G4 is equal to 5 G5 is equal to 7
• Defines a local variable of integer named NB. Initialize NB with your section number plus 100. For example, if your section is O7, the value of NB should be 107 (7+100). You can use only assignment instruction in this part. (2 points)
• Prompts the user to enter the rank of NB employees by using for loop. If the user enters EOF, the main function should stop reading. The main should then calculate and print the average rank of all employees and the average rank of all employees who have a rank greater than or equal to five. (15 points)
C. The main function should perform the following
• Defines two local integer variables named FB1 and FB2. You cannot use a loop in this part. The value of FB1 is equal to the product of all odd digits of your student ID number. If the Student ID did not contain an odd digit, initialize the value of FB1 with 1. The value of FB2 is equal to the sum of all even digits of your student ID number. If the Student ID did not contain an even digit, initialize the value of FB2 with 0. For example, if your student ID is 42357, the value of FB1 will be 105 (3*5*7) and the value of FB2 will be 6 (4 + 2 = 6). You can use only assignment and printf instructions in this part. The main should then print the value of FB1 and FB2 as below: (5 points)
“PartC_42357_Product of odd digits FB1 = 105 and sum of even digits FB2 = 6”.
• Prompts user to enter the current salary of five employees by using a for loop. The main then calculates and prints the average salary before and after applying an increment for each employee. The increment is equal to: (15 points)
o 15% if the salary of an employee is less than your student ID number.
o 25% if the salary of an employee is more than your student ID number.
o 35% if the salary of an employee is equal to your student ID number.
D. The main function should perform the following
• Prompts the user to enter the age (integer) of five employees by using a for loop, calculates and prints the average age of all employees who are older than 35 years. (15 points)
Page 4 of 5
• Prints “High average age” if the average age of all employees is greater than 36 Otherwise the main should print “Low average age”. (8 points)
E. The program should adhere the following requirements:
• The name of the .C file is equal to your student ID. For example, if your student ID = 42357, the name of the file will be "42357.c". (2 points)
• Write your first name, your last name, the course code CS159, your section number and your ID as comments at the top of the code as shown below: (3 points).
If your name is xxx yyy, your ID is 42357and your section is O7, comments should be:
/*
Assignment 3 solution is created by:
a- ID = 42357
b- Student name= xxx yyy
c- Section O7
d- Semester: Summer 2021
e- Course code : CS159
*/
Answer:
/*
Assignment 3 solution is created by:
a-ID=
b-Student name =
c-Section 010
d-Semester:S
e-Course code:
*/
printf("%s is created by:\n", PartA_010);
printf("%s\n", STRING_010);
//rank output
int RankMax_010=24;
int y;
printf("Rank should be from 1 to 24:\n");
scanf("%d",&y);
while(y<1 || y>RankMax_010){
printf("Rank should be from 1 to 24:\n");
scanf("%d",&y);
}
//print line of characters as per ID
int myid[5]={4,7,3,6,4};
int k;
int f;
for(k=0;k<5;k++){
int digit_encounter=myid[k];
for(f=1;f<=digit_encounter;f++){
printf("\\");
}
printf("\n");
}
//print 5 character variables
char G1 = '4', G2 = '7', G3 = '3', G4 = '6', G5 = '4';
printf("PART B STUDENT ID:\n");
printf("G1 is equal to %c\t", G1);
printf("G2 is equal to %c\t", G2);
printf("G3 is equal to %c\t", G3);
printf("G4 is equal to %c\t", G4);
printf("G5 is equal to %c\n", G5);
//rank of employees
int NB=110;
int cont;
int r;
float sum_of_rank_of_all_employees=0;
float sum_of_less_or_equal_to_five=0;
float average_of_all_employees=0;
float average_of_less_or_equal_to_five=0;
int counter_for_all=0;
int counter_for_less_or_equal_to_five=0;
for(cont=1;cont<=5;cont++) {
printf("Enter rank for employee %d:",cont);
scanf("%d",&r);
printf("Average rank of all employees is %f\n",average_of_all_employees);
printf("Average rank of all employees who have a rank greater than or equal to five is %f\n",average_of_less_or_equal_to_five);
//part C
int FB1 = 21;
int FB2 = 14;
printf("PartC_47364\n");
printf("PartC_47364_Product of odd digits FB1=%d and sum of even digits FB2=%d\n", FB1, FB2);
//employees salary
int s;
int idsalary = 47364;
float b;
float sum_before_increment=0;
float average_before_increment=0;
float sum_after_increment=0;
float average_after_increment=0;
float salary_after_increment=0;
for (s = 1; s <= 5; s++) {
printf("Enter salary of employee %d:", s);
scanf("%f",&b);
sum_before_increment+=b;
average_before_increment=sum_before_increment/5;
float salary_before_increment=b;
}
printf("Employee average salary before increment:%.4f\n",average_before_increment);
printf("Employee average salary after increment:%.4f\n",average_after_increment);
//employee ages
int age;
int counter=0;
float sum_of_age=0;
float average_of_age=0;
int c;
for(c=1;c<=5;c++){
printf("Enter age for employee %d:",c);
scanf("%d",&age);
if(age>35){
counter=counter+1;
sum_of_age=sum_of_age+age;
average_of_age=sum_of_age/counter;
}
}
printf("The average age of all employees who are older than 35 years %.3f\n",average_of_age);
if(average_of_age>36){
printf("High average age\n");
}else{
printf("Low average age\n");
}
return 0;
}