Question

In C++.

Write another program in file B2.cpp to calculate and print the total sales of each product by each salesperson. Read the salYour program should print the 2-dimensional array in a well-formatted table, showing the salespersons name in front of eachSales Slips - Notepad X 2 2 File Edit Format View Help Eric 1 200000.00 Sookie 2 200.00 Sookie 4 200.50 Bill 3 5000.00 Bill 5

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

Code is as follows:

******************************************************************************************************************************

#include <iostream>
#include<iomanip>
#include<fstream>
using namespace std;

int main()
{
double sales[4][5] = {0}; //declare and initialise to all zeroes
  
ifstream infile; //ifstream object
infile.open("SalesSlips.txt"); //opne the file
  
//variables for input from file
string name;
int product;
double amount;
  
//read every line and extract name product and amount
while(infile>>name>>product>>amount){
  
int id; //check name and assign id
if(name=="Bill"){
id = 1;
}
else if(name=="Eric"){
id = 2;
}
else if(name=="Sookie"){
id = 3;
}
else{
id = 4;
}
//take switch case and put in respective cell of the 2d array
switch(product){
case 1:
sales[id-1][0]+=amount;
break;
case 2:
sales[id-1][1]+=amount;
break;
case 3:
sales[id-1][2]+=amount;
break;
case 4:
sales[id-1][3]+=amount;
break;
case 5:
sales[id-1][4]+=amount;
break;
}
}
  
//print to the console
cout<<left<<setw(9)<<"Product #";
printf("%7d",1);
for(int i=1;i<5;i++){
printf("%10d",i+1); //every Product number
}
cout<<endl;
for(int i=0;i<4;i++){
string name;
if(i==0){
name="Bill";
}
else if(i==1){
name="Eric";
}
else if(i==2){
name="Sookie";
}
else{
name="Tara";
}
cout<<left<<setw(9)<<name; //name of the person
for(int j=0;j<5;j++){
printf("%10.2f",sales[i][j]); //sale of that person
}
cout<<endl;
}
return 0;
}

******************************************************************************************************************************

Screenshot of the code:

1 #include <iostream> 2 #include<iomanip> 3 #include<fstream> 4 using namespace std; 5 6 int main() 7.{ 8 double sales[4][5]case 4: sales[id-1][?]+=amount; break; case 5: sales[id-1][4]+=amount; break; بہا بہا 45 46 47 48 49 50 51 52 53 54 55 56 57

File screenshot :

1 Eric 1 200000.00 2 Sookie 2 200.00 3 Sookie 4 200.50 4 Bill 3 5000.00 5 Bill 5 7500.00 6 Tara 4. 350.50 7 Eric 2 200.00 8 T

Output:

Product # Bill Eric 1 0.00 200000.00 50000.00 0.00 2 0.00 200.00 400.00 400.00 3 5000.00 0.00 0.00 0.00 4 0.00 0.00 601.00 5

Add a comment
Know the answer?
Add Answer to:
In C++. Write another program in file B2.cpp to calculate and print the total sales 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
  • 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...

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

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

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

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

  • Write a program that stores the weekly (Monday thru Friday) sales totals for three salespersons. Your...

    Write a program that stores the weekly (Monday thru Friday) sales totals for three salespersons. Your program should allow the user to enter the sales amounts and print a sales report with headings, the daily totals for each salesperson (your two-dimensional array), the calculated weekly totals for each sales person and the calculated totals for the day of each salesperson. In addition, create a single-dimensional array of Strings representing the days of the week (Monday-Friday) using an initializer list. Your...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales...

    C++ Objective: Write a program to read a pre-specified file containing salespersons' names and daily sales for some number of weeks. It will create an output file with a file name you have gotten from the user that will hold a summary of sales data. Specifications: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program...

  • Create a C++ program that reads in from a file numbers.txt and stores each value of...

    Create a C++ program that reads in from a file numbers.txt and stores each value of each line into a two dimensional array ( int array [4][4] ) The array should be filled row by row from left to right. numbers.txt : 1,8,7,3 3,5,9,2 2,4,6,2 9,3,6,2

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

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