Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C program: Using arrays write a program that reads and displays teacher

ID: 3817720 • Letter: C

Question

Create a C program: Using arrays write a program that reads and displays teachers salaries and names and average median salary. In addition display the teachers with the top and bottom salaries.
Requirements: 1. Properly document code using Coding standards. 2. Use a 50 element integer type array for salaries. 3.Use 50 element char array for first and last names. 4. Initialize all variables properly. 5. Input: Read the first and last name for each teachers and their yearly salary until a blank line is inputted for the teachers first name. A blank first name will end of the input. 6. Output: After all of the teacher's names and salaries are received, produce output as below: a. "Teacher 1: John Smith Salary(per year) : $80000 " (note the tabbed output for readability) b." Teacher 2: Jane Tarzan Salary(per year) : $81000 " c. ect. d. After all teachers have been output as above, the following line: i. "The average salary is $80000 per year" ii. "The top salary is Jane Tarzan at $81000" iii. "The bottom salary is John Smith at $80000" 7.Sort the output ascending by salary using the bubble sort algorithm. addition Using arrays write a program reads and displays teacher salaries and names and average median salary. In display the teachers with the top and bottom salaries. Requirements: 1. Properly document code using the CIS 161 Coding standards. 2. Use a 50 element integer type array for salaries. Use 50 element char arrays for first and last names. 4. Initialize all variables properly. 5. put: Read the first and last name for each teacher and their yearly salary until a blank line is inputted for the teacher's first name. A blank first name will be the end of the input. 6. Output: After all of the teacher's names and salaries are received, produce output as below: a. "Teacher 1: John Smith Salary (per year) $80000" (note the tabbed output for readability) b. "Teacher 2: Jane Tarzan Salary (per year): S81000" c, etc d. After all teachers have been output as above. the following line i. "The average salary is 80000 per year" ii. "The top salary is Jane Tarzan at 81000" iii. "The bottom salary is John Smith at 80000" 7. Extra Credit sort the output ascending by salary using the bubble sort algorithm. Below is more information regarding bubble sort: a. http:/Awww.progr source code program bubhle sort b, http://www.c-sharpcom 3d39h4 bubble sort in C-Sharp

Explanation / Answer

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int calculate_avg(int salary[],int length)
{
int i,avg=0;
for(i=0;i<length;i++)
{
avg=avg+salary[i];
}
avg=avg/length;
return avg;
}
int calculate_max(int salary[],int length,int *index)
{
int i,max=salary[0];
for(i=0;i<length;i++)
{
if(max<salary[i])
{
*index=i;
max=salary[i];
}
}
return max;
}
int calculate_min(int salary[],int length,int *index)
{
int i,min=salary[0];
for(i=0;i<length;i++)
{
if(min>salary[i])
{   
*index=i;
min=salary[i];
}
}
return min;
}
int main(){
char firstname[50][50]={''};
char lastname[50][50]={''};
char first[50]={''},last[50]={''},temp_first[50]={''},temp_last[50]={''};
int salary[50],i,length,j,max_index=-1,min_index=-1;
int avg,max,min,temp_sal;
for(i=0;i<50;i++)
{
salary[i]=0;
}
scanf("%s",first);
j=0;
while(first[0]!='')
{
strcpy(firstname[j],first);
scanf("%s",last);
strcpy(lastname[j],last);
scanf("%d",&salary[j]);
j=j+1;
memset(first,'',50);
memset(last,'',50);
scanf("%s",first);
}
avg=calculate_avg(salary,j);
max=calculate_max(salary,j,&max_index);
min=calculate_min(salary,j,&min_index);
for(i=0;i<j;i++)
{
printf("Teacher %d:%s %s Salary(per year):$%d ",i+1,firstname[i],lastname[i],salary[i]);
}
printf("The average salary is $%d per year ",avg);
printf("The top salary is %s %s at $%d per year ",firstname[max_index],lastname[max_index],max);
printf("The bottom salary is %s %s at $%d per year ",firstname[min_index],lastname[min_index],min);
length=j;
for(i=0;i<length-1;i++)
{
for(j=0;j<length-i-1;j++)
{
if(salary[j]>salary[j+1])
{
temp_sal=salary[j];
salary[j]=salary[j+1];
salary[j+1]=temp_sal;
strcpy(temp_first,firstname[j]);
strcpy(firstname[j],firstname[j+1]);
strcpy(firstname[j+1],temp_first);
strcpy(temp_last,lastname[j]);
strcpy(lastname[j],lastname[j+1]);
strcpy(lastname[j+1],temp_last);
}
}
}
printf("Output after Sorting accordng to salaries ");
for(i=0;i<length;i++)
{
printf("Teacher %d:%s %s Salary(per year):$%d ",i+1,firstname[i],lastname[i],salary[i]);
}
return 0;
}