Question
Write c++ program
In this assignment, you need to complete following tasks on 2D array of randomly sales figures. Assume that you are the manag
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello here is the code for the above problem. Hope it helps. If you are satisfied with the answer, do consider upvoting!

CODE:

#include<bits/stdc++.h>
using namespace std;
int main()
{
srand(time(0));
/*row index 0->shop ID 1
row index 1->shop ID 2
row index 2->shop ID 3
row index 3->shop ID 4
row index 4->shop ID 5

column index 0->morning
column index 1->afternoon
column index 2->evening
*/
int data[5][3];
//setting the sales data
for(int i=0;i<5;i++)
{
for(int j=0;j<3;j++)
{
//generates random integers between [300-1000].
int generated = rand()%701 + 300;
data[i][j] = generated;
}
}

//printing the 2-D matrix in required form.
cout<<"SALES DATA:"<<endl;
for(int i=0;i<5;i++){
for(int j=0;j<3;j++)
cout<<data[i][j]<<" ";
cout<<endl;
}
//finding the highest and lowest.
int highest = data[0][0];
int lowest = data[0][0];
for(int i=0;i<5;i++)
{
for(int j=0;j<3;j++)
{
if(data[i][j]>highest)
highest = data[i][j];
if(data[i][j]<lowest)
lowest = data[i][j];
}
}
cout<<"Highest sales amount:"<<highest<<endl;
cout<<"Lowest sales amount:"<<lowest<<endl;

//finding average for shop ID 3(row index = 2)
double total = 0;
for(int i=0;i<3;i++)
total+=data[2][i];
cout<<"Average sales by shop ID 3 = "<<total/3<<endl;

//finding highes sales in evening by which shop ID
int high_eve = data[0][2];
int index = 0;
for(int i=0;i<5;i++)
{
if(data[i][2]>high_eve)
{
high_eve = data[i][2];
index = i;
}
}
cout<<"Highest evening sales by shop ID:"<<index+1<<endl;
  
//comparing total morning and total afternoon sales.
int total_morning;
int total_afternoon;
for(int i=0;i<5;i++)
{
total_morning+=data[i][0];
total_afternoon+=data[i][1];
}
if(total_morning>total_afternoon)
cout<<"Yes, morning sales are more than afternoon sales"<<endl;
else
cout<<"No, morning sales are less than or equal to afternoon sales"<<endl;
return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write c++ program In this assignment, you need to complete following tasks on 2D array of...
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
  • Write c++ program In this assignment, you need to complete following tasks on 2D array of...

    Write c++ program In this assignment, you need to complete following tasks on 2D array of randomly sales figures. Assume that you are the manager of coffee shop chain, and oversee 5 branches. ID of branches are to 5. You already collected sales data for yesterday from each branch, in three categories: morning, afternoon, and evening. First, you need to create a 2D array (5x3) with random numbers between 300 and 1000 (including 300 and 1000), i.e., from $300 to...

  • c++ please Instructions In this assignment, you need to complete following tasks on 2D array of...

    c++ please Instructions In this assignment, you need to complete following tasks on 2D array of randomly sales figures. Assume that you are the manager of coffee shop chain, and oversee 5 branches. ID of branches are 1 to 5. You already collected sales data for yesterday from each branch, in three categories: morning, afternoon, and evening. First, you need to create a 2D array (5x3) with random numbers between 300 and 1000 (including 300 and 1000), i.e., from $300...

  • Write a Java program that does the following. a. Declare an integer 2D array with 5...

    Write a Java program that does the following. a. Declare an integer 2D array with 5 rows and 5 columns. b. Initialize the array's elements to random integers between 1 and 10 (inclusive). c. Display all the elements in the 2D array as a table of rows and columns. d. Display the row index and column index of all the even integers in the 2D array. e. Display the sum of first row's elements.

  • In C++ for 2D Array: Write a program that uses a function that manipulates a 2D...

    In C++ for 2D Array: Write a program that uses a function that manipulates a 2D array of integers as follows: 1. Fill the first row and column in the array with random bits 2. Every subsequent cell should be filled as follows: 1. If the cells that are to the left and top of it are equal, then you should store their sum in it b. Otherwise, your program should store the highest among them. Test your function using...

  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

  • Need help with this programming please this is the instruction my teacher provided Write a C++...

    Need help with this programming please this is the instruction my teacher provided Write a C++ class called "Sales" and a main( ) function that uses the class. Also, write documentation of your project. Below is a specification of the class. . INTRODUCTION A company has four salespeople (1 to 4) who sell five different products ( to 5)1. Once a day each salesperson passes in a slip for each different type of product sold. Each slip contains: The salesperson...

  • write c++ program This assignment is about array operations. You need to count a specific items...

    write c++ program This assignment is about array operations. You need to count a specific items in an array. Steps to follow are here: . Create an array with 1000 items and fill it with random numbers from the range of -100, 100 (including -100 and 100). In your program asks user to enter a number, K. Search this number and print the frequency (how many) of this K is found in the array. • Ask another number, and so...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1)....

    Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1). 1- Find how many branches had have loans over $2000.00. 2- For each branch, find the most expensive loan. Your output should include Branch Id, loan amount for the highest loan for that Branch. 3- Find how many accounts there are for each customer. The output should include customer id and number of accounts for that customer. 4- Find the total balance amount of...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

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