Write an application to calculate retail sales I need help with this program and
ID: 673087 • Letter: W
Question
Write an application to calculate retail sales
I need help with this program and I already set up all of my source files. i.e. (header files, and my main.cpp) but I need assistance with my implementation file. This is an assignment and I'm slightly confused how I should set up my arrays for my code.
My problem comes with setting up int ProductNumber[], int ProductQuantity and double RetailValue[]. I'm not sure how I should initialize these.
Specifications
An online retailer sells five products whose retail prices are as follows:
Product 1, $2.98
Product 2, $4.50
Product 3, $3.98
Product 4, $4.49
Product 5, $6.87
Write an application that reads (from the keyboard) a series of pairs of numbers as follows:
product number
quantity sold
Run your program from a simple menu with the following options
Enter products sold
Display total retail value
Exit
Your program should
allow for entry of multiple products without returning to the main menu (use a sentinel-controlled loop
calculate and display the total retail value of all products sold
use an array for each of the following
product prices
product quantity
product total
Implementation File
#include "RetailSales.h"
#include
using namespace std;
RetailSales::RetailSales()
{
}
void RetailSales::enterProducts()
{
int productNumber[] =
int ProductQuantity[] =
double RetailValue[] =
}
void RetailSales::displayTotalValue()
{
}
Header File
------------------------
/*
* CSIS1600
* A04a Retail Sales
* class RetailSales header file
*/
#ifndef RETAILSALES_H
#define RETAILSALES_H
class RetailSales
{
public:
RetailSales();
void enterProducts();
void displayTotalValue();
private:
double productPrice[6];
double productTotal[6];
int productQuantity[6];
double totalRetailValue;
};
#endif // RETAILSALES_H
Explanation / Answer
The Main file is:
#include "RetailSales.h"
#include <iostream>
using namespace std;
RetailSales::RetailSales()
{
for(int i = 0; i < 5; i++)
{
productNumber[i] = 0;
if(i == 0)
productPrice[i] = 2.98;
else if(i == 1)
productPrice[i] = 4.50;
else if(i == 2)
productPrice[i] = 3.98;
else if(i == 3)
productPrice[i] = 4.49;
else if(i == 4)
productPrice[i] = 6.87;
productTotal[i] = 0;
productQuantity[i] = 0;
totalRetailValue = 0;
}
}
void RetailSales::enterProducts(int pNo, int qty)
{
productNumber[pNo-1] = pNo;
productQuantity[pNo-1] += qty;
productTotal[pNo-1] += productPrice[pNo-1] * qty;
totalRetailValue += productPrice[pNo-1] * qty;
}
void RetailSales::displayTotalValue()
{
for(int i = 0; i < 5; i++)
{
cout<<"Product "<<productNumber[i]<<" is of quantity "<<productQuantity[i]<<" and its total value is "<<productTotal[i]<<endl;
}
cout<<"Total retail value of all products sold is: "<<totalRetailValue<<endl;
}
int main()
{
int pNo, qty, ch;
float retailPrice;
RetailSales lot;
while(1)
{
cout<<"1. Enter products sold."<<endl;
cout<<"2. Display total retail value."<<endl;
cout<<"3. Exit."<<endl;
cout<<"Enter your choice: ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter product number: ";
cin>>pNo;
cout<<"Enter quantity sold: ";
cin>>qty;
lot.enterProducts(pNo,qty);
break;
case 2:
lot.displayTotalValue();
break;
case 3:
exit(1);
default:
cout<<"Invalid menu choice..."<<endl;
}
}
}
And the header file is:
/*
* CSIS1600
* A04a Retail Sales
* class RetailSales header file
*/
#ifndef RETAILSALES_H
#define RETAILSALES_H
class RetailSales
{
public:
RetailSales();
void enterProducts(int a, int b);
void displayTotalValue();
private:
int productNumber[5];
double productPrice[5];
double productTotal[5];
int productQuantity[5];
double totalRetailValue;
};
#endif /* RETAILSALES_H */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.