// Ch. 10 Demo #6
// Wyo C++
// October 24, 2001 // Purpose - processes Amazon.com customers using struct variables and a function // Note that the struct definitions as well as the computeTax function could be placed // in another file such as amazon.h and the program would still work if you then // add the compiler directive #include "amazon.h"
#include <iostream.h> double computeTax(double myPrice); // compute's PA sales tax struct Basket { int books; // number of books purchased by customer int cds; // number of cd's purchased by customer int toys; // number of toys purchased by customer double totalPrice; // customer's total amount due char coupon; // customer's coupon rate }; struct Prices { double book; // price of one book double cd; // price of one cd double toy; // price of one toy double couponA; // discount rate for coupon A double couponB; // disount rate for coupon B }; int main() { Basket currentCustomer; // basket of Amazon.com customer who is browsing Basket checkoutCustomer; // basket of Amazon.com customer who is checking out Prices october; // October price schedule october.book = 1; // setting october price schedule october.cd = 10.99; october.toy = 15; october.couponA = 0.1; october.couponB = 0.5; cout << "How many books: "; // current customer is browsing the site cin >> currentCustomer.books; cout << "How many cds: "; cin >> currentCustomer.cds; cout << "How many toys: "; cin >> currentCustomer.toys; // computing current customer's total amount due currentCustomer.totalPrice = october.book * currentCustomer.books + october.cd * currentCustomer.cds + october.toy * currentCustomer.toys; cout << "Your price is " << currentCustomer.totalPrice << endl << endl; checkoutCustomer.books = 1; // assume that the checkout customer has already made checkoutCustomer.cds = 6; // these purchases checkoutCustomer.toys = 2; checkoutCustomer.coupon = 'A'; checkoutCustomer.totalPrice = checkoutCustomer.books * october.book + checkoutCustomer.cds * october.cd + checkoutCustomer.toys * october.toy; if (checkoutCustomer.coupon == 'A') { checkoutCustomer.totalPrice -= checkoutCustomer.totalPrice * october.couponA; } else if (checkoutCustomer.coupon == 'B') { checkoutCustomer.totalPrice -= checkoutCustomer.totalPrice * october.couponB; } // otherwise no coupon was used cout << "The checkoutCustomer's total amount due is: " << computeTax(checkoutCustomer.totalPrice) << endl << endl; return 0; }// end of main double computeTax(double myPrice) { return (myPrice * 1.06); }// end of computeTax