Question

Use a two-dimensional array to solve the following problem. A company has four salespeople (0 to...

Use a two-dimensional array to solve the following problem. A company has four salespeople (0 to 3) who sell five different products (0 to 4). Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains the following:

a) The salesperson number

b) The product number

c) The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available in the input file “data.txt” as shown below. Write a program that will read all this information for last month’s sales (one salesperson’s data at a time) from the input file “data.txt” and summarize the total sales by salesperson and by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, write the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product in an output file “result.txt”. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by each salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

OUTPUT SCREENSHOT:

COPY CODE:

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;


//the below function finds the number of digits in floor(x)
int findDigitsBeforeDecimal(double x){
int z = floor(x);
int i = 0;
while(z>0){
i +=1;
z = z/10;
}
return(i);
}

// print empty spaces n times
void printSpaces(int n){
for(int i=0;i<n;i++){
cout << " ";
}
}

int main(){
int i,j,n;
int a,b;
double c;
double sales[4][5];
for(i=0;i<4;i++){
for(j=0;j<5;j++){
sales[i][j] = 0.0;
}
}
cout << "Enter the salesperson, product and total sales " << endl;
cout << "Enter -1 for the salesperson to end input " << endl;
cin >> a ;
while(a!=-1){
cin >> b;
cin >> c;
sales[a][b] += c;
cin >> a;
}
cout << "The total sales for each salesperson are displayed at the the end of each row, "<< endl;
cout << "and the total sales for each product are displayed at the bottom of each column. " << endl;

n = 15;
for(i=0;i<5;i++){
printSpaces(n);
cout << i;
}
cout << endl;
double sum = 0.0;
int dig;
for(i=0;i<4;i++){
cout << i;
sum = 0.0;
for(j=0;j<5;j++){
//find the number of digits before decimal in sales[i][j]
//set width according to that
dig = findDigitsBeforeDecimal(sales[i][j]);
if(j==0){
if(dig==0){
printSpaces(n-dig-4);
}else{
printSpaces(n-dig-3);
}
}else{
if(dig == 0){
printSpaces(n-dig-3);
}else{
printSpaces(n+1-dig-3);
}
}
printf("%.2f",sales[i][j]);
sum += sales[i][j];
}
//print the cumulative row sum
dig = findDigitsBeforeDecimal(sum);
if(dig == 0){
printSpaces(n-dig-3);
}else{
printSpaces(n+1-dig-3);
}
printf("%.2f",sum);
cout << endl;
}
//print the column sum
for(j=0;j<5;j++){
sum = 0.0;
for(i=0;i<4;i++){
sum += sales[i][j];
}
dig = findDigitsBeforeDecimal(sum);
if(dig == 0){
printSpaces(n-dig-3);
}else{
printSpaces(n+1-dig-3);
}
printf("%.2f",sum);
}
cout << endl;


return(0);
}

Add a comment
Know the answer?
Add Answer to:
Use a two-dimensional array to solve the following problem. A company has four salespeople (0 to...
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
  • Use a two-dimensional array to solve the following problem. A company has four salespeople (1 to...

    Use a two-dimensional array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains the following a) The salesperson number b) The product number c) The total dollar value of that product sold that day Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that...

  • ho, then print the message "Next flight leaves in 3 hours." 6.22 Total Sales) Use a...

    ho, then print the message "Next flight leaves in 3 hours." 6.22 Total Sales) Use a two-dimensional array to solve the following problem. A company has four salespeople (I to 4) who sell five diferent products (I to 5). Once a day, each salesperson pases in a slip for each different type of product sold. Each slip contains: a) b) c) The salesperson numbor The product number The total dollar value of that product sold that day Thus, each salesperson...

  • C++ Background information: A company has four salespeople who sell five different products. Once a day,...

    C++ Background information: A company has four salespeople who sell five different products. Once a day, each salesperson passes in a slip for each different type of product sold. First on the line is the salesperson name, second is the product number, and third is the sales volume for this product by this salesperson in dollars. For example, the line Tara 2 200.00 means that salesperson Tara reported sales of volume $200.00 for product number 2. Data: Eric 1 200000.00...

  • Assignment3 - Protected View - Saved to this PC ejembi jeremy X File Home Insert DesignLayout Ref...

    please can i get the answer for the 3rd question Assignment3 - Protected View - Saved to this PC ejembi jeremy X File Home Insert DesignLayout References MailingsReview View Help Tell me what you want to do PROTECTED VIEW Be careful-files from the intermet can contain vinuses. Unless you ned to edi, it's safer to stay in Protected View Enable Editing Write a program that will read all this information for last month's sales and summarize the total sales by...

  • 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...

  • C# Use a one-dimensional array to solve the following problem: A company pays its salespeople on...

    C# Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000, or a total of $650. Write an application (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges...

  • Sales Data Analysis A company has multiple salespeople. Every month, they go on road trips to sel...

    Sales Data Analysis A company has multiple salespeople. Every month, they go on road trips to sell the company's product. At the end of each month, the total sales for each sales person, together with that salesperson's ID and the month, is recorded in a file. At the end of each year, the manager of the company wants to see an Annual Sales Report in the format illustrated in the sample execution below. Your report should look substantially similar to...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • The Livewright Medical Supplies Company has a total of 12 salespeople it wants to assign to three regions—the South, the East, and the Midwest. A salesperson in the South earns $600 in...

    The Livewright Medical Supplies Company has a total of 12 salespeople it wants to assign to three regions—the South, the East, and the Midwest. A salesperson in the South earns $600 in profit per month for the company, a salesperson in the East earns $540, and a salesperson in the Midwest earns $375. The southern region can have a maximum assignment of 5 salespeople. The company has a total of $16,500 per month available for expenses for all 12 salespeople....

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

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