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
|
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
// Declaring ONLY the parts of namespace we're actually using
// Function Prototype
int getProduct(string);
int getQuantity(string);
int printSummary(string products[4], int quantities[4], int product, int quantity); //passes 4 variables to the function
// customer class definition
class Customer
{
private:
string customerName, customerAddress;
public: //Public class functions
int Purchases[4];
double Costs[4];
void setName(string name) //Function to set cutomers name
{
customerName = name;
}
string getName() //function to get customers name
{
return customerName;
}
void setAddress(string address) //Function to set customers address
{
customerAddress = address;
}
string getAddress() //Function to get customers address
{
return customerAddress;
}
};
int main()
{
//declare variables
string name, address;
char anotherItem; // Changed from string to char
int product, quantity, x;
double totalValue = 0, itemValue = 0;
Customer customer1; //creates a Customer object called customer1
for (x = 0; x < 4; x++)// Zero out the arrays
{
customer1.Purchases[x] = 0;
customer1.Costs[x]=0.0;
}
//Declare arrays product and quantity
string products[4] = { "Bix 3", "Delta Rocket", "Mini B-17", "Cherokee Glider" };
int quantities[4] = { 225, 150, 275, 125 };
cout << "Please enter your name: \n\n";
getline(cin, name);
customer1.setName(name); //Calls the setName function of the Customer Class
cout << "Please enter your address: \n\n";
getline(cin, address);
customer1.setAddress(address); //Calls the setAddress function of the Customer Class
do {
cout << "Welcome " << customer1.getName() << "! to Lou's Cyber Store.'" << endl << endl;
cout << "The address was entered as: " << customer1.getAddress() << endl << endl;
cout << "Please review items for purchase from the following menu:" << endl << endl;
for (x = 0; x < 4; x++)
cout << "(" << x + 1 << ") " << products[x] << " RC Airplane ......... $" << quantities[x] << endl;
cout << endl;
//Function #1 Get the customers requested plane model
product = getProduct("Please enter the item number you would like to purchase: ");
//Function #2 get customers required quantity
quantity = getQuantity("Please enter the quantity you would like to purchase: ");
// Function # 3 Display the customers order summary
itemValue = printSummary(products, quantities, product, quantity);
totalValue += itemValue; //Running total
customer1.Purchases[product]+= quantity;
customer1.Costs[product] += itemValue;
//cout << endl << "Your final cost of your entire order is : $" << totalValue << endl;
// Not needed yet, as you'll show FINAL totalValue at end of program
cout << endl << "Would you like to order another item? (Y/N)";
cin >> anotherItem;
} while (toupper(anotherItem) != 'N'); // Check just one input
cout << customer1.getName() << ", you have finished shopping. Here are your totals" << endl;
for (x = 0; x < 4; x++)
{
if (customer1.Purchases[x] > 0)
{
cout << "You puchased " << customer1.Purchases[x] << " " << products[x] << " RC Airplanes";
cout << " at a cost of $" << customer1.Costs[x] << ".00" << endl;
}
}
cout << "Total cost for your purchases was $" << totalValue << ".00" << endl << endl;
} //Main program end
//Function section
//Function #1
int getProduct(string productPrompt)
{
int productChoice;
cout << productPrompt;
cin >> productChoice;
return productChoice-1;
}
//Function #2
int getQuantity(string quantityPrompt)
{
int quantityChoice;
cout << quantityPrompt;
cin >> quantityChoice;
return quantityChoice;
}
//Function #3
int printSummary(string products[4], int quantities[4], int product, int quantity)
{
int itemValue;
itemValue = quantity * quantities[product];
cout << endl << "Product selection was : " << products[product]<< " RC Airplane.";
cout << endl << "Quantity was: " << quantity << endl;
cout << "The total cost for this item is : $" << itemValue << endl;
return itemValue;
}
|