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

Using Lab Assignment 5’s program, write a program reads and displays teacher sal

ID: 3713665 • Letter: U

Question

Using Lab Assignment 5’s program, write a program reads and displays teacher salaries and names and average salary.

Requirements:

Properly document code using the CIS 161 Coding standards.

Use a 50 element integer type array for salaries.

Use 50 element char arrays for first and last names. (note: 2 dimensional arrays for each).

Initialize all variables properly.

Use separate functions to keep main() more readable. Ensure functions are properly declared.

Do not use Global variables except for the max array elements size.

Input: 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 line for the first name will be the end of the input.

Output: After all of the teacher’s names and salaries are received, produce output as below:

“Teacher 1: John Smith          Salary (per year) : $80000 ” (note the tabbed output for readability)

“Teacher 2: Jane Tarzan Salary(per year) : $81000”

etc.

After all teachers have been output as above, the following line:

“The average salary is : 80000 per year”

“The top salary is Jane Tarzan at 81000”

“The bottom salary is John Smith at 80000”

Extra Credit: Sort the output ascending by salary using the bubble sort algorithm.   Below is more information regarding bubble sort:

http://www.programmingsimplified.com/c/source-code/c-program-bubble-sort (Links to an external site.)Links to an external site.

http://www.c-sharpcorner.com/UploadFile/3d39b4/bubble-sort-in-C-Sharp/ (Links to an external site.)

Explanation / Answer

Hi Dear,

You have not mentioned about required programming language.

Please try to mention all required details.

I have implemented in C.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote