Question

Write a C program that deal with employees’ salaries in a company, as follows: Define an...

  1. Write a C program that deal with employees’ salaries in a company, as follows:
    1. Define an integer array named salaries of size 100
    2. Initialize all array elements with zeros
    3. Fill all array elements with random numbers within a range of 350 until 3000 (all inclusive) by using built-in-function rand() and srand()

Develop the following functions and call them from the main program:

  1. avgSalary(), a function that receives the array and its size as parameters and returns the average salary in the company
  2. printSalary(), a function that receives the array and its size as parameters and prints out all salaries in a tabular format each 10 salaries in same row.
  3. maxSalary(), a function that receives the array and its size as parameters and returns the highest salary in the company
  4. searchSalary(), a function that receives as parameters: the array and its size and the salary value to search for. The same function returns how many times this salary found in the array
  5. sortSalary(),a function that receives the array and its size as parameters and sorts the array in descending order (from highest to lowest)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
float avgSalary(int salaries[],int size){
int i,sum=0;
for(i=0;i<size;i++){
sum+=salaries[i];
}
return ((float)sum)/size;
}
void printSalary(int salaries[],int size){
int i;
for(i=0;i<size;i++){
if(i%10 == 0)
printf("\n");
printf("%d , ",salaries[i]);
}
}
int maxSalary(int salaries[],int size){
int i,max=salaries[0];
for(i=0;i<size;i++){
if(salaries[i]>max)
max=salaries[i];
}
return max;
}
int searchSalary(int salaries[],int size,int value){
int i,count=0;
for(i=0;i<size;i++){
if(salaries[i]==value)
count++;
}
return count;
}
void sortSalary(int salaries[],int size){
int i,j;
for(i=0;i<size;i++){
for(j=0;j<size-i-1;j++){
if(salaries[j]>salaries[j+1]){
int temp = salaries[j+1];
salaries[j+1] = salaries[j];
salaries[j]=temp;
}
}
}
}

int main()
{
srand(time(0)); //setting up unique seed

int salaries[100],i; //a : define array

for(i=0;i<100;i++) //b : initialize with 0
salaries[i]=0;

for(i=0;i<100;i++){ //c : fill up array using rand , srand
salaries[i] = 350 + (rand()%(3000-350+1));
}
printf("\n\n==============================Function calls====================================\n\n");
printSalary(salaries,100);
printf("\n\nAverage salary is : %f",avgSalary(salaries,100));
printf("\n\nMaximum salary is : %d",maxSalary(salaries,100));
printf("\n\nSalary of amount 360 occurs %d times",searchSalary(salaries,100,360));
sortSalary(salaries,100);
printf("\n\nSorted salary : ");
printSalary(salaries,100);


return 0;
}

#include<stdio.h> #include<stdlib.h> #include<time.h> float avgSalary(int salaries [], int size) { int i, sum=0; for(i=0;i<siint searchSalary(int salaries [], int size, int value) { int i, count=0; for(i=0;i<size; i++) { if salaries[i]==value) count+

Add a comment
Know the answer?
Add Answer to:
Write a C program that deal with employees’ salaries in a company, as follows: Define an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Hello, I need a c program called int* create_random_array(int n) that returns a random array of...

    Hello, I need a c program called int* create_random_array(int n) that returns a random array of size an. Alternatively, you can initialize a pointer to an array (called Rand) and write a function called void(create_array(int * Rand, int n) which assigns an array of size n to Rand. Note: Plese utilize rand(fi) and srand() from stdlib.h for this code

  • C++ Problems: 1. Write a program that reads in an array of user given size n and then it reads se...

    C++ Problems: 1. Write a program that reads in an array of user given size n and then it reads several increment values terminated by 0. The program calls each time a function incarray() that accepts an array A, its size S and an increment value inc and updates yje array by incrementing all its values by the passed value of inc. The program prints out the array after each update. 2. write a program that reads in a n...

  • create a file homework_part_1.c a) Implement the function initialize_array that receives two parameters: an array of...

    create a file homework_part_1.c a) Implement the function initialize_array that receives two parameters: an array of integers and the array size. Use a for loop and an if statement to put 0s in the odd positions of the array and 5s in the even positions. You must use pointers to work with the array. Hint: review pointers as parameters. b) Implement the function print_array that receives as parameters an array of integers and the array size. Use a for statements...

  • 7eatng that function Write a C++ program that does the following: Fill an array of 123...

    7eatng that function Write a C++ program that does the following: Fill an array of 123 elements using srand) and rand) with random numbers between 150 and 667. Fill an array of 123 elements with random numbers between 150 and 667. Using a loop. Fill an array of 123 elements with random numbers between 150 and 667. Using a for loop Use a void function to fill an array of 123 elements with random numbers between 150 and 667, Possible...

  • Write a program using C in Microsoft visual studios. Write a function that receives an array...

    Write a program using C in Microsoft visual studios. Write a function that receives an array of integers and the array length and prints one integer per line (Hint: Use \n for a line break). Left align all of the integers and use a field width of 10. Populate an array of 10 elements from the user and pass the array and its length to the function.

  • write program in c # to do the following : Insert 10 student scores and store...

    write program in c # to do the following : Insert 10 student scores and store them in an array Create a function that prints array elements Create a function that returns the highest mark Create a function that calculates the average score Create a function that calculates the pass rate, knowing that the pass mark is 60

  • Write a C program to do the following: 1. Write a C function named find that...

    Write a C program to do the following: 1. Write a C function named find that receives a one-dimensional array of type character named arr and its size of type integer. After that, the function must select a random index from the array. The function must find if the character stored in the randomly selected index comes before all the characters to its left alphabetically. Finally, the function prints to the screen the element if the element meets the condition...

  • Need to write a MIPS assembly program that finds the minimum and maximum and sum of...

    Need to write a MIPS assembly program that finds the minimum and maximum and sum of a stored array. It also finds the locations of the minimum and maximum. The interaction between the main program and the function is solely through the stack. The function stores $ra immediately after being called and restores $ra before returning to main. The main program reserves a static C like array (index starts from 0) of 10 elements and initializes it. The maximum should...

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT