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
*/
programming-in-c-assignments-questions-10-2021-1726.JPG
programming-in-c-assignments-questions-10-2021-1727.JPG


Answer:


/*
Assignment 3 solution is created by:
a-ID=
b-Student name =
c-Section 010
d-Semester:S
e-Course code:
*/

#include stdio.h
#include stdlib.h
#include string.h

/*
*
*/

int main() {
char PartA_010[] = "PartA_010_47364";
char STRING_010[473640] = "Course_CS159_SU_2021_Assessment_A3_Part_A_steven_Section_010_ID_47364";

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);

counter_for_all=counter_for_all+1;
sum_of_rank_of_all_employees=sum_of_rank_of_all_employees+r;
average_of_all_employees=sum_of_rank_of_all_employees/counter_for_all;

if(r>=5){
counter_for_less_or_equal_to_five=counter_for_less_or_equal_to_five+1;
sum_of_less_or_equal_to_five=sum_of_less_or_equal_to_five+r;
average_of_less_or_equal_to_five=sum_of_less_or_equal_to_five/counter_for_less_or_equal_to_five;
}
if(!r){
printf("\n") ;
}
}



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;

if(b salary_after_increment=salary_before_increment+(0.15*b);
}
else if(b>idsalary){
salary_after_increment=salary_before_increment+(0.25*b);

}else if(b==idsalary){
salary_after_increment=salary_before_increment+(0.35*b);

}
else{
printf("Error:\n");
}
sum_after_increment=sum_after_increment+salary_after_increment;
average_after_increment=sum_after_increment/5;

}
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;
}



Share To Friends Via:
        






More Questions For Programming in C:



  What are the types of errors that occur in C program? (Answered)
What are the types of errors that occur in C program? .
Posted On:Sat 13, March 2021 10:32:24 am
  Which level is C language belonging to? (Answered)
Which level is C language belonging to? .
Posted On:Sat 13, March 2021 10:35:35 am
  What is the difference between C and C++? (Answered)
What is the difference between C and C++? .
Posted On:Sat 13, March 2021 10:36:55 am
  Who developed C language? (Answered)
Who developed C language? .
Posted On:Sat 13, March 2021 10:38:43 am
  C language has been developed in which language? (Answered)
C language has been developed in which language? .
Posted On:Sat 13, March 2021 10:40:38 am
  Is C a structured programming language? (Answered)
Is C a structured programming language? .
Posted On:Sat 13, March 2021 10:42:58 am
  What is structured programming? (Answered)
What is structured programming? .
Posted On:Sat 13, March 2021 10:43:41 am
  What is meant by programming language? (Answered)
What is meant by programming language? .
Posted On:Sat 13, March 2021 10:45:05 am
  What is the difference between C and Java? (Answered)
What is the difference between C and Java? .
Posted On:Sat 13, March 2021 10:48:01 am
  State Whether C language is low level language, or middle level language? (Answered)
State Whether C language is low level language, or middle level language? .
Posted On:Sat 13, March 2021 10:49:17 am
  What is modular programming? (Answered)
What is modular programming? .
Posted On:Sat 13, March 2021 10:51:49 am
  Is C language case sensitive? (Answered)
Is C language case sensitive? .
Posted On:Sat 13, March 2021 10:52:38 am
  What is data type in C? (Answered)
What is data type in C? .
Posted On:Sat 13, March 2021 10:53:51 am
  What is the difference between interpreter and compiler? (Answered)
What is the difference between interpreter and compiler? .
Posted On:Sat 13, March 2021 10:56:44 am
  What is the difference between declaration and definition of a variable? (Answered)
What is the difference between declaration and definition of a variable? .
Posted On:Sat 13, March 2021 10:57:38 am
  What is a program flowchart? (Answered)
What is a program flowchart? .
Posted On:Sat 13, March 2021 11:00:32 am
  What is the syntax for comments in C? (Answered)
What is the syntax for comments in C? .
Posted On:Sat 13, March 2021 11:03:14 am
  List out some of C compilers? (Answered)
List out some of C compilers? .
Posted On:Sat 13, March 2021 11:04:10 am
  What is the difference between exit() and return() in C? (Answered)
What is the difference between exit() and return() in C? .
Posted On:Sat 13, March 2021 11:05:18 am
  What is the difference between calloc and malloc? (Answered)
What is the difference between calloc and malloc? .
Posted On:Sat 13, March 2021 11:07:06 am
  What are the different types of modifiers in C? (Answered)
What are the different types of modifiers in C? .
Posted On:Sat 13, March 2021 11:09:20 am
  What is a constant in C? (Answered)
What is a constant in C? .
Posted On:Sat 13, March 2021 11:10:14 am
  What are the types of constants in C? (Answered)
What are the types of constants in C? .
Posted On:Sat 13, March 2021 11:11:03 am
  What are dangling pointers in C? (Answered)
What are dangling pointers in C? .
Posted On:Sat 13, March 2021 11:11:51 am
  What is the difference between rand(), random(), and randomize()? (Answered)
What is the difference between rand(), random(), and randomize()? .
Posted On:Sat 13, March 2021 11:14:32 am
  What is bebugging? (Answered)
What is bebugging? .
Posted On:Sat 13, March 2021 11:15:50 am
  What is a compiler? (Answered)
What is a compiler? .
Posted On:Sat 13, March 2021 11:18:24 am
  What are all decisions control statements in C? (Answered)
What are all decisions control statements in C? .
Posted On:Sat 13, March 2021 11:20:02 am
  What is mean by debugging? (Answered)
What is mean by debugging? .
Posted On:Sat 13, March 2021 11:22:17 am
  What is static function in C? (Answered)
What is static function in C? .
Posted On:Sat 13, March 2021 11:25:27 am

More Questions Categories:


About Us

Contact us

Terms of use | Privacy policy

Follow Us:               

All Rights Reserved © 2024; pscustudies.com