.Lab Target o Understand the way of defining and using arrays a) Be able to use
ID: 3875600 • Letter: #
Question
.Lab Target o Understand the way of defining and using arrays a) Be able to use functions that use arrays as a Understand the sorting algorithm Tools Operation System Windows XP Programming Language: C++ Textbook Starting out with C+Early Objects a Tasks (After finish the following tasks, hand in Lab all source code, and snapshot of running Reports, results) (1) Annual Salary Write a program that asks user to input her/his month salaries and store them in an array. After you entered all salaries (12 month), the program displays all the month salary on the screen as well as the month average, annual sum, max and min on the screen. Your program output should be like the following hat is yeur salary of Ronth 27 20 hat is your salary of Honth 47 hat is yeur salary of Ronth S 8 hat is your alary of Month 6? 23 hat is yeur salary of Honth 7? 14 hat is yeur salary of Honth 87 45 hat is yeer salary of Ronth 976 hat is year salary of Honth 18T 76 hat is year salary of Honth 117 34 hat is yr salary of Honth 12T 24 alary of ith is 18 alary of 2th is 2 alary of 3th is 38 alary of 4th 78 alaryof St.h 9@ alary of th is 23 alary of 7th is 14 alary of 8th is 45 alary of 9th is 65 alaryof 18th 76 alary of 11th is 34 alary ef 12th is 24 otally yw eaned S8ithis year ur aerage salary s 41-75 (2) Function with array parameters Write a function that finds the max, min and average values of an array. Your function should use the following function header void ArrayOperate(float x, int n, float &max;, float &min;, float &average;) (3) Bubble sorting Based on the array you have created in task (1), complete the program by implementing bubble sort the month salary in descending order.Explanation / Answer
#include<iostream.h>
#include<string.h>
#include<conio.h>
float total=0;
void ArrayOperate(float x[],int n,float &max,float &min,float &average)
{
min=x[0];
max=x[0];
for(int i=0;i<n;i++)
{
if(min>x[i])
min=x[i];
if(max<x[i])
max=x[i];
}
average=total/n;
cout<<" Your average salary is "<<average;
cout<<" Your max month saalary is "<<max;
cout<<" Your minimal month salary is "<<min;
}
void main()
{
clrscr();
float s[12],max=0,min=0,average=0,temp;
for(int i=0;i<12;i++)
{
cout<<" What is your salalry of month "<<i+1<<" ? ";
cin>>s[i];
}
for(i=0;i<12;i++)
{
cout<<" Salary of "<<i+1<<"th is "<<s[i];
total+=s[i];
}
cout<<" Totally you earned "<<total<<" this year ";
ArrayOperate(s,12,max,min,average);
for(i=0;i<11;i++)
{
for(int j=0;j<12-i-1;j++)
{
if(s[j]<s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
cout<<" Salaries after sorting : ";
for(i=0;i<12;i++)
{
cout<<" "<<s[i];
}
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.