ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 28 Apr 2017 My Price 11.00

COMPUTER GENERATES INPUTS

I don't understand what I am doing wrong but here is what my problem is so far I need it to look like this but I can't seem to figure out how to get it that way. I can't seem to know how to figure out how to get my project working like this below.

/*----------COMPUTER GENERATES INPUTS
Enter seed value for random number generator: 7750
    item #  quantity     price      cost

      3613         8      4.40     35.20
      8655         2      6.22     12.44  *
      4361         4      7.69     30.76
      7460         7      1.91     13.37  *
      5124         5      5.67     28.35
      1967         2      5.37     10.74
      1722         5      7.53     37.65
      1396         3      8.45     25.35
      1555         8      6.76     54.08  *
      7401         7      2.65     18.55
      4125         4      9.06     36.24  *
      2800         5      4.22     21.10  *


Purchase:   323.83
Tax:         13.53
Amount:     337.36

12 kinds of different items purchased

* indicates item was not taxable
Press any key to continue
*/

/*-----------KEYBOARD INPUTS
How many different items to purchase? 2
Enter item number: 1234
How many of item number  1234 were purchased?: 3
Enter price for item  1234 : 1.7
Is item number  1234 taxable ( y or n) : y
    item #  quantity     price      cost

      1234         3      1.70      5.10
Enter item number: 1235
How many of item number  1235 were purchased?: 3
Enter price for item  1235 : 1.9
Is item number  1235 taxable ( y or n) : n
    item #  quantity     price      cost

      1235         3      1.90      5.70  *


Purchase:    10.80
Tax:          0.37
Amount:      11.17

2 kinds of different items purchased

* indicates item was not taxable
Press any key to continue
*/

 

 

#include
#include
#include
#include <fstream>
<cstdlib>
<iomanip>
<iostream> using namespace::std;
const bool KEYBOARD = false;
const double TAX_RATE = 0.0725;
ofstream Out("con");
int
getNumberOfSales(void);
int
getItemNumber(void);
double
getPrice(int itemNumber);
bool isTaxable(int itemNumber);
int
getQuantity(int itemNumber);
double
getCost(int itemNumber, int count, double price);
double getTax(double sales);
void printLine(ostream & w, int iNumber, int qty, double price, double cost,
bool taxable);
void printTotal(ostream & w, int loopCount, double grandTotal, double taxDue);
void headings(ostream & w);
void startRandom(void);
void prepareOutput(ostream & w);
int main() {
//-- Declarations
int
differentItems,
iNumber,
qty;
double
price,
cost,
taxableTotal,
nonTaxableTotal,
taxDue,
grandTotal;
bool taxable; //-- Initializations
nonTaxableTotal = 0;
taxableTotal = 0;
prepareOutput(Out);
if (!KEYBOARD) startRandom();
differentItems = getNumberOfSales();
// Make table of items purchased
headings(Out);
for (int i = 0; i<differentItems; i++) {
iNumber = getItemNumber();
qty = getQuantity(iNumber);
price = getPrice(iNumber);
cost = getCost(iNumber, qty, price);
taxable = isTaxable(iNumber); } printLine(Out, iNumber, qty, price, cost, taxable);
if (taxable)
taxableTotal += cost;
else
nonTaxableTotal += cost; taxDue = getTax(taxableTotal);
grandTotal = nonTaxableTotal + taxableTotal;
printTotal(Out, differentItems, grandTotal, taxDue);
return 0;
}
// -- Function Implementation
void prepareOutput(ostream & w) {
w << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);
}
void startRandom(void) {
int seed;
cout << "Enter seed value for random number generator: ";
cin >> seed;
srand(seed);
}
int getItemNumber(void) {
int num;
if (KEYBOARD) {
cout << "Enter item number: ";
cin >> num;
}
else
num = rand() % 9000 + 1000;
return num;
}
double getPrice(int num) {
double price;
if (KEYBOARD) {
cout << "Enter price for item " << num << " : ";
cin >> price;
}
else
price = double(rand() % 1000 + 10) / 100;
return price;
}
bool isTaxable(int itemNumber) {
char q;
if (KEYBOARD) {
cout << "Is item \"" << itemNumber << "\" taxable(y/n): ";
cin >> q;
if (q == 'y' || q == 'Y')
return true;
else
return false;
}
else
if (itemNumber % 5 == 0)
return false;
else
return true;
}
int getQuantity(int num) {
int quantity;
if (KEYBOARD) {
cout << "Enter the quantity of item " << num << ": ";
cin >> quantity; }
else
quantity = rand() % 8 + 1;
return quantity;
}
int getNumberOfSales(void) {
int sales;
if (KEYBOARD) {
cout << "Enter the number of sales: ";
cin >> sales;
}
else
sales = rand() % 15 + 1;
return sales;
}
double getCost(int itemNumber, int count, double price) {
double cost;
cost = count * price;
if (KEYBOARD) {
cout << "Enter the cost(" << cost << ") of " << itemNumber << ": ";
cin >> cost;
}
return cost;
}
double getTax(double sales) {
return (sales * TAX_RATE);
}
void headings(ostream & w) {
w << setw(7) << "Item #"
<< setw(10) << "Quantity"
<< setw(10) << "Price"
<< setw(10) << "Cost"
<< setw(6) << "Taxed"
<< endl;
}
void printLine(ostream & w, int iNumber, int qty, double price, double cost,
bool taxable) {
w << setw(7) << iNumber
<< setw(10) << qty
<< setw(10) << price
<< setw(10) << cost;
if (taxable)
w << setw(5) << "*\n";
else
w << endl;
} void printTotal(ostream & w, int loopCount, double grandTotal, double taxDue) {
w << loopCount << " kinds of items purchased.\n\n"
<< "Purchase:
" << setw(8) << grandTotal << endl
<< "Tax:
" << setw(8) << taxDue << endl
<< "Final Total: " << setw(8) << (grandTotal + taxDue) << endl <<
endl;
}
/* --- Monitor Output ------------------------------------- * * * first test run (random) * * *
----------------------------------Enter seed value for random number generator: 7750
Item # Quantity
Price
Cost Taxed
3613
8
4.40
35.20
*
8655
2
6.22
12.44
4361
4
7.69
30.76
*
7460
7
1.91
13.37
5124
5
5.67
28.35
*
1967
2
5.37
10.74
*
1722
5
7.53
37.65
*
1396
3
8.45
25.35
*
1555
8
6.76
54.08
7401
7
2.65
18.55
*
4125
4
9.06
36.24
2800
5
4.22
21.10
12 kinds of items purchased.
Purchase:
Tax:
Final Total: 323.83
13.53
337.36 Press any key to continue
*/

Answers

(11)
Status NEW Posted 28 Apr 2017 07:04 AM My Price 11.00

-----------

Attachments

file 1493364852-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)