Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will allow the user to continually enter from the keyboard,

ID: 3632277 • Letter: W

Question

Write a program that will allow the user to continually enter from the keyboard, a
product number (1 thru 4), a day number (1 thru 6) and the quantity
purchased (an integer). This means that four different products are sold on
each of six days. These values will be entered many times (I could input
thirty triples of numbers or two hundred triples of numbers - product
number, day number and quantity). I might have sold 21 of product 4 on
day 3 and later sell 12 more of product 4 on day 3. It is necessary that you
accumulate the total for the product each day and not replace the previous
entry. As the data is entered, you should store in a two-dimensional array
a count of how many products of each type are sold on the day. When the user
finishes inputting values, he/she should use a sentinel selected by the
programmer (indicate this sentinel in your prompt).


Once the user has finished the input create a NEAT table with labels for the
output for the total number of each product sold on each day of the week.
Also output within the table, the total of all products sold each day and the
total number of each product that is sold for all days.

Use at least one Class (this means that you will have at least three files).


The problem I am having is figuring out how to add a class to this source code in order to meet the requirements of the program. Here is the code below.

#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;


int main()
{
int p,d,q;
int data[6][4];
for(int i=0;i<6;i++)
for(int j=0;j<4;j++)
data[i][j]=0;
char c;
for(;;)
{
cout<<"Please enter purchase info as listed below: "<<endl;
cout<<" ------------------------------------------"<<endl<<endl;
cout << " Product # (1-4), Day (1-6), Quantity Sold :"<<endl;
cout<<" ------------------------------------------"<<endl<<endl;;
cout<<"Product"<<endl;
cin>>p;
cout<<"Day"<<endl;
cin >>d;
cout<<"Quantity"<<endl;
cin >>q;

data[d][p]=data[d][p]+q;

cout <<"Enter q to stop entering data else hit any key:";
cin >>c;

if(c=='q') break;
}
cout <<"Product/Day 1 2 3 4 ";
for(int i=0;i<6;i++)
{ cout<<"Day"<<i+1<<" ";
for(int j=0;j<4;j++)
cout << data[i][j]<<" ";
cout <<" ";
}
_getch();
return 0;
}

Explanation / Answer

If you are getting all zeroes in your totals comumns, I think it's because product always equals 0 regardless of what the user inputs. You initialize it to 0, then it never changes. Why? Because you never store any user input in a variable called product in this loop: C++ Syntax (Toggle Plain Text) while ( dayNum != -1 ) { cin >> dayNum >> quantity; purchased[ dayNum ][ product ] += quantity; cin >> dayNum; } You store user input in dayNum and quantity in line 3, then in dayNum again in line 5. You never store anything in product. Thus it stays as 0. So you might as well change line 4 above to this: C++ Syntax (Toggle Plain Text) purchased[ dayNum ][ 0 ] += quantity; because it will be the same result. If that is not what you want, you need to change line 3, line 5, or both, so you store user input in product. You listed the desired output. What is your ACTUAL output for the input values you listed? Is it all zeroes?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote