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: 3713672 • Letter: U

Question

Using Lab Assignment 5’s program, write a program reads and displays teacher salaries and names and average salary.   In addition display the teachers with the top and bottom salaries.

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

#include <stdio.h>

#include <limits.h>

const unsigned int SIZE = 50;

const unsigned int NAMESIZE = 100;

int findTopSalary(int a[]){

int max = INT_MIN;

int i, l=0;

for(i=0;i<SIZE; i++)

if(a[i]>max)

{l=i; max = a[i];}

return l; //return index of top element

}

int findBottomSalary(int a[]){

int min = INT_MAX;

int i, l=0;

for(i=0; i<SIZE; i++)

if(a[i]<min)

{l=i; min = a[i];}

return l; //return index of bottom element

}

int findAverage(int a[]){

long sum =0;

int i;

for(i=0; i<SIZE; i++)

sum += a[i];

int avg = sum/SIZE;

return avg;

}

void readInput(int a[], char b[][NAMESIZE]){

int i;

for(i=0; i<SIZE; i++){

scanf("%s %s %d",&b[i][0], &b[i][50], &a[i]);

}

}

void outputAll(int a[], char b[][NAMESIZE]){

int i=0;

for(i=0; i<SIZE; i++){

printf("Teacher %d: %s %s Salary(per year): $%d ",i+1, b[i], &b[i][50], a[i]);

}

}

int main()

{

int salaries[SIZE];

char names[SIZE][100];

readInput(salaries, names);

outputAll(salaries, names);

int average;

average = findAverage(salaries);

printf("The average Salary is: %d ",average);

int top, bottom;

top = findTopSalary(salaries);

printf("The top salary is %s %s at %d ",names[top], &names[top][50], salaries[top]);

bottom = findBottomSalary(salaries);

printf("The bottom salary is %s %s at %d ",names[bottom], &names[bottom][50], salaries[bottom]);

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