Suppose you have a two-dimensional array of double to hold the sales amounts for
ID: 3555234 • Letter: S
Question
- Suppose you have a two-dimensional array of double to hold the sales amounts for all your salespeople three years. Assume you employ 50 salespeople and this array already holds valid data.
- Write the code to declare the array.
- Write the code to count how many of these salespeople had sales over $8000 for the second year.
- Write the code to find the highest sales amount over all three years.
- Write the code to find the total sales amount for the first year.
- Write the function definition, print, that will print the contents of the array. The array will be passed as a parameter.
Explanation / Answer
#include<iostream>
using namespace std;
// Suppose you have a two-dimensional array of double to hold the sales amounts for all your salespeople three years.
// Assume you employ 50 salespeople and this array already holds valid data.
//Write the code to declare the array.
double sales[50][3];
//Write the code to count how many of these salespeople had sales over $8000 for the second year.
int count = 0;
for(int i=0; i<50; i++)
{
if(sales[i][1] > 8000)
count++;
}
cout <<"Number of salespeople had sales over $8000 are " << count << endl;
//Write the code to find the highest sales amount over all three years.
double max = sales[0][0];
for(int i=0; i<50; i++)
{
for(int j=0; j<3; j++)
{
if(sales[i][j] > max) max = sales[i][j];
}
}
cout <<"Highest sales amount over all three years is " << max << endl;
//Write the code to find the total sales amount for the first year.
double first_sum = 0;
for(int i=0; i<50; i++)
first_sum = first_sum + sales[0][0];
cout <<" total sales amount for the first year is " << fisrt_sum << endl;
//Write the function definition, print, that will print the contents of the array. The array will be passed as a parameter.
void print(double sales[50][3])
{
for(int i=0; i<50; i++)
{
for(int j=0; j<3; j++)
{
cout <<sales[i][j]<< " ";
}
cout << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.