1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/* // A-1-1-01
Author: Andrya Newman // A-1-1-02
Date Written: December 11, 2011 // A-1-1-02
Course: CSIS 123, Internet // A-1-1-02
Program: Task 07-02, Chapter 5 // A-1-1-02
Program Description: A mail-order house, Specialty Products, sells five products. // A-1-1-02
This program prompts the user for a series of number pairs // A-1-1-02
(product number and quantity sold for that product). It uses // A-1-1-02
a sentinel-controlled "while" loop to determine when the // A-1-1-02
program should stop accepting user input and, at the // A-1-1-02
conclusion of the input phase, display the calculated results. // A-1-1-02
The program validates the product number entered, ensuring that // A-1-1-02
it is an integer value from 1 through 5, inclusive. It issues // A-1-1-02
an error message and rejects any user-entered product number // A-1-1-02
that is outside the acceptable range. When a valid product // A-1-1-02
number is entered it prompts for and accepts quantity sold // A-1-1-02
for that product. // A-1-1-02
Compiler Used: Microsoft Visual C++ 2010 Express // A-1-1-02
SourceFile Name: Task_07_02_Ch05.cpp // A-1-1-02
*/ // A-1-1-03
#include <iostream> // A-1-1-04
#include <iomanip> // A-1-1-05
#include <string> // A-1-1-06
using namespace std; // A-1-1-07
class MailOrder { // A-1-1-08
public: // A-1-1-09
void completeDailySalesReport() { // A-1-1-10
int quantitySoldByProduct[c_productCount] = {}; // A-1-3-01
const double unitPriceByProduct[] = {3.00, 4.50, 9.52, 5.00, 7.00}; // A-1-3-02
cout << "\n\n Specialty Products: Daily Sales Report"; // A-1-3-03 TODO
cout << "\n\n Program Input:"; // A-1-3-04 TODO
getSalesByProduct(quantitySoldByProduct); // A-1-3-05
cout << "\n Program Output:"; // A-1-3-06 TODO
displaySalesReport(quantitySoldByProduct, unitPriceByProduct); // A-1-3-07
} // function completeDailySalesReport // A-1-1-11
private: // A-1-1-12
const static int c_interColumnWidth = 4; // A-1-1-13
const static int c_productColumnWidth = 7; // A-1-1-14
const static int c_productCount = 5; // A-1-1-15
const static int c_quantityColumnWidth = 8; // A-1-1-16
const static int c_totalSalesColumnWidth = 11; // A-1-1-17
const static int c_unitPriceColumnWidth = 10; // A-1-1-18
void displayColumnHeadings() { // A-1-1-19
cout << "\n\n\t" << right // A-1-3-08
<< setw(getProductColumnWidth()) << "Product" // A-1-3-09
<< setw(getInterColumnWidth()) << " " // A-1-3-10
<< setw(getQuantityColumnWidth()) << "Quantity" // A-1-3-11
<< setw(getInterColumnWidth()) << " " // A-1-3-12
<< setw(getUnitPriceColumnWidth()) << "Unit Price" // A-1-3-13
<< setw(getInterColumnWidth()) << " " // A-1-3-14
<< setw(getTotalSalesColumnWidth()) << "Total Sales" // A-1-3-15
<< "\n"; // A-1-3-16
} // function displayColumnHeadings // A-1-1-20
void displayProductSales (int productNumber, int quantitySoldOfProduct, // A-1-1-21
double unitPriceOfProduct, double productSales) { // A-1-1-21
cout << "\n\t" << right // A-1-3-17
<< setw(getProductColumnWidth()) << productNumber // A-1-3-18
<< setw(getInterColumnWidth()) << " " // A-1-3-19
<< setw(getQuantityColumnWidth()) << quantitySoldOfProduct // A-1-3-20
<< setw(getInterColumnWidth()) << " " // A-1-3-21
<< fixed << showpoint << setprecision(2) // A-1-3-22
<< setw(getUnitPriceColumnWidth()) << unitPriceOfProduct // A-1-3-23
<< setw(getInterColumnWidth()) << " " // A-1-3-24
<< setw(getTotalSalesColumnWidth()) << productSales; // A-1-3-25
} // function displayProductSales // A-1-1-22
void displaySalesReport(const int quantitySoldByProduct[], // A-1-1-23
const double unitPriceByProduct[]) { // A-1-1-23
double extendedSalesThisProduct = 0.0; // A-1-3-26
double totalSalesAllProducts = 0.0; // A-1-3-27
displayColumnHeadings(); // A-1-3-28
for (int index = 0; index <= getProductCount() - 1; index++) { // A-1-3-29
extendedSalesThisProduct = quantitySoldByProduct[index] // A-1-3-30
* unitPriceByProduct[index]; // A-1-3-31
totalSalesAllProducts += extendedSalesThisProduct; // A-1-3-32
displayProductSales(index + 1, quantitySoldByProduct[index], // A-1-3-33
unitPriceByProduct[index], extendedSalesThisProduct); // A-1-3-34
|