Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<iomanip>
- #define DISCOUNT1 .019
- #define DISCOUNT2 .026
- #define DISCOUNT3 .029
- #define DISCOUNT4 .034
- #define VIDGAM 19.99
- #define VIDGAM_ON 4.99
- #define VIDGAM_INS .06
- #define GENIUSPH 799.99
- #define GENIUSPH_ON 25.00
- #define GENIUSPH_CASE 24.99
- #define GENIUSPH_INS .11
- #define HAMBURG 7.99
- #define HAMBURG_ON 9.00
- #define HAMBURG_CON 1.79
- #define HAMBURG_BUN 1.89
- #define HAMBURG_INS .03
- #define FRENCHFRY 2.99
- #define FRENCHFRY_ON 1.00
- #define FRENCHFRY_INS .01
- using namespace std;
- class Package
- {
- public:
- Package(const char *, const char *, const char *, const char *, const char *, const int, const int, const int, const int, const int); // constructor
- ~Package(); // destructor reclaims memory
- virtual void calcCost() = 0; // pure virtual
- //to make abstract base class
- virtual void print() const;
- private:
- char *firstName;
- char *lastName; // dynamically allocated string
- char *address;
- char *city;
- char *state;
- int day;
- int month;
- int year;
- int zip;
- int overnightDelivery;
- };
- Package::Package(const char *first, const char *last, const char *addr, const char *cit, const char *stat, const int d, const int m, const int y, const int code, const int on)
- {
- firstName = new char[strlen(first) + 1];
- strcpy_s(firstName, strlen(first) + 1, first);
- lastName = new char[strlen(last) + 1];
- strcpy_s(lastName, strlen(last)+1, last);
- address = new char[strlen(addr) + 1];
- strcpy_s(address, strlen(addr)+1, addr);
- city = new char[strlen(cit) + 1];
- strcpy_s(city, strlen(cit)+1, cit);
- state = new char[strlen(stat) + 1];
- strcpy_s(state, strlen(stat)+1, stat);
- day = d;
- month = m;
- year = y;
- overnightDelivery = on;
- zip = code;
- }
- void Package::print() const
- {
- if (overnightDelivery == 1)
- {
- cout << "Customer: " << firstName << ' ' << lastName << "\t\t Expected Arrival Date: " << month << '-' << day + 1 << '-' << year << endl;
- }
- else
- {
- cout << "Customer: " << firstName << ' ' << lastName << "\t\t Expected Arrival Date: " << month << '-' << day + 5 << '-' << year << endl;
- }
- cout << "\t\t" << address << endl;
- cout << "\t\t" << city << ", " << state << " " << zip << endl;
- }
- Package::~Package()
- {
- delete[] firstName;
- delete[] lastName;
- delete[] address;
- delete[] city;
- delete[] state;
- }
- class VideoGames : public Package
- {
- public:
- VideoGames(const char *, const char *, const char *, const char *, const char *, const int, const int, const int, const int, const int, int = 0, int = 0);
- virtual void calcCost();
- virtual void print() const;
- private:
- int num;
- int ins_verify;
- int on_verify;
- int discount_choice;
- float shipping_costs;
- float insurance;
- float total_cost;
- float discount;
- float total_cost_discount;
- };
- VideoGames::VideoGames(const char *first, const char *last, const char *addr, const char *cit, const char *stat, const int d, const int m, const int y, const int code, const int on, int n, int ins)
- : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
- {
- num = n;
- ins_verify = ins;
- on_verify = on;
- }
- void VideoGames::calcCost()
- {
- shipping_costs = num * VIDGAM;
- if(on_verify == 1)
- {
- total_cost = shipping_costs + VIDGAM_ON;
- }
- else
- {
- total_cost = shipping_costs;
- }
- if(ins_verify == 1)
- {
- insurance = (total_cost * VIDGAM_INS);
- total_cost += insurance;
- }
- if(total_cost <= 300)
- {
- discount_choice = 1;
- discount = total_cost *DISCOUNT1;
- }
- else if (total_cost <= 600)
- {
- discount_choice = 2;
- discount = total_cost *DISCOUNT2;
- }
- else if (total_cost <= 1000)
- {
- discount_choice = 3;
- discount = total_cost *DISCOUNT3;
- }
- else
- {
- discount_choice = 4;
- discount = total_cost *DISCOUNT4;
- }
- total_cost_discount = total_cost - discount;
- }
- void VideoGames::print() const
- {
- Package::print(); // call the base print function
- cout << num << " video games ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << VIDGAM_ON << endl;
- if (ins_verify == 0)
- {
- cout << "No insurance is specified" << endl;
- }
- else
- {
- cout << "The insurance percentage is " << VIDGAM_INS * 100 << "% for an additional price of $" << insurance << endl;
- }
- cout << "Total Cost is $" << total_cost << endl;
- cout << "Discount Percentage is ";
- switch(discount_choice)
- {
- case 1:
- cout << DISCOUNT1 * 100;
- break;
- case 2:
- cout << DISCOUNT2 * 100;
- break;
- case 3:
- cout << DISCOUNT3 * 100;
- break;
- case 4:
- cout << DISCOUNT4 * 100;
- break;
- }
- cout << "% for a discount of $" << discount << endl;
- cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
- }
- class GeniusPhones : public Package
- {
- public:
- GeniusPhones(const char *, const char *, const char *, const char *, const char *, const int, const int, const int, const int, const int, int = 0, int = 0, int = 0);
- virtual void calcCost();
- virtual void print() const;
- private:
- int num;
- int num_cases;
- int ins_verify;
- int on_verify;
- int discount_choice;
- float shipping_costs;
- float cases_costs;
- float insurance;
- float total_cost;
- float discount;
- float total_cost_discount;
- };
- GeniusPhones::GeniusPhones(const char *first, const char *last, const char *addr, const char *cit, const char *stat, const int d, const int m, const int y, const int code, const int on, int n, int ins, int c)
- : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
- {
- num = n;
- ins_verify = ins;
- on_verify = on;
- num_cases = c;
- }
- void GeniusPhones::calcCost()
- {
- shipping_costs = num * GENIUSPH;
- cases_costs = num_cases * GENIUSPH_CASE;
- if(on_verify == 1)
- {
- total_cost = shipping_costs + GENIUSPH_ON;
- }
- else
- {
- total_cost = shipping_costs;
- }
- total_cost += cases_costs;
- if(ins_verify == 1)
- {
- insurance = (total_cost * GENIUSPH_INS);
- total_cost += insurance;
- }
- if(total_cost <= 300)
- {
- discount_choice = 1;
- discount = total_cost *DISCOUNT1;
- }
- else if (total_cost <= 600)
- {
- discount_choice = 2;
- discount = total_cost *DISCOUNT2;
- }
- else if (total_cost <= 1000)
- {
- discount_choice = 3;
- discount = total_cost *DISCOUNT3;
- }
- else
- {
- discount_choice = 4;
- discount = total_cost *DISCOUNT4;
- }
- total_cost_discount = total_cost - discount;
- }
- void GeniusPhones::print() const
- {
- Package::print(); // call the base print function
- cout << num << " genius phones ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << GENIUSPH_ON << endl;
- if (ins_verify == 0)
- {
- cout << "No insurance is specified" << endl;
- }
- else
- {
- cout << "The insurance percentage is " << GENIUSPH_INS * 100 << "% for an additional price of $" << insurance << endl;
- }
- if (num_cases != 0)
- {
- cout << num_cases << " genius phone cases ordered for an additional price of $" << cases_costs << endl;
- }
- else
- {
- cout << "No cases ordered" << endl;
- }
- cout << "Total Cost is $" << total_cost << endl;
- cout << "Discount Percentage is ";
- switch(discount_choice)
- {
- case 1:
- cout << DISCOUNT1 * 100;
- break;
- case 2:
- cout << DISCOUNT2 * 100;
- break;
- case 3:
- cout << DISCOUNT3 * 100;
- break;
- case 4:
- cout << DISCOUNT4 * 100;
- break;
- }
- cout << "% for a discount of $" << discount << endl;
- cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
- }
- class Hamburgers : public Package
- {
- public:
- Hamburgers(const char *, const char *, const char *, const char *, const char *, const int, const int, const int, const int, const int, int = 0, int = 0, int = 0, int = 0);
- virtual void calcCost();
- virtual void print() const;
- private:
- int num;
- int num_condiments;
- int num_buns;
- int ins_verify;
- int on_verify;
- int discount_choice;
- float shipping_costs;
- float condiments_costs;
- float buns_costs;
- float insurance;
- float total_cost;
- float discount;
- float total_cost_discount;
- };
- Hamburgers::Hamburgers(const char *first, const char *last, const char *addr, const char *cit, const char *stat, const int d, const int m, const int y, const int code, const int on, int n, int ins, int c, int b)
- : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
- {
- num = n;
- ins_verify = ins;
- on_verify = on;
- num_condiments = c;
- num_buns = b;
- }
- void Hamburgers::calcCost()
- {
- shipping_costs = num * HAMBURG;
- condiments_costs = num_condiments * HAMBURG_CON;
- buns_costs = num_buns * HAMBURG_BUN;
- if(on_verify == 1)
- {
- total_cost = shipping_costs + HAMBURG_ON;
- }
- else
- {
- total_cost = shipping_costs;
- }
- total_cost += condiments_costs + buns_costs;
- if(ins_verify == 1)
- {
- insurance = (total_cost * HAMBURG_INS);
- total_cost += insurance;
- }
- if(total_cost <= 300)
- {
- discount_choice = 1;
- discount = total_cost *DISCOUNT1;
- }
- else if (total_cost <= 600)
- {
- discount_choice = 2;
- discount = total_cost *DISCOUNT2;
- }
- else if (total_cost <= 1000)
- {
- discount_choice = 3;
- discount = total_cost *DISCOUNT3;
- }
- else
- {
- discount_choice = 4;
- discount = total_cost *DISCOUNT4;
- }
- total_cost_discount = total_cost - discount;
- }
- void Hamburgers::print() const
- {
- Package::print(); // call the base print function
- cout << num << " hamburgers ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << HAMBURG_ON << endl;
- if (ins_verify == 0)
- {
- cout << "No insurance is specified" << endl;
- }
- else
- {
- cout << "The insurance percentage is " << HAMBURG_INS * 100 << "% for an additional price of $" << insurance << endl;
- }
- if (num_condiments != 0)
- {
- cout << num_condiments << " condiment servings ordered for an additional price of $" << condiments_costs << endl;
- }
- else
- {
- cout << "No condiments ordered" << endl;
- }
- if (num_buns != 0)
- {
- cout << num_buns << " pair of buns ordered for an additional price of $" << buns_costs << endl;
- }
- else
- {
- cout << "No buns ordered" << endl;
- }
- cout << "Total Cost is $" << total_cost << endl;
- cout << "Discount Percentage is ";
- switch(discount_choice)
- {
- case 1:
- cout << DISCOUNT1 * 100;
- break;
- case 2:
- cout << DISCOUNT2 * 100;
- break;
- case 3:
- cout << DISCOUNT3 * 100;
- break;
- case 4:
- cout << DISCOUNT4 * 100;
- break;
- }
- cout << "% for a discount of $" << discount << endl;
- cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
- }
- //French Fries: Cost is number of servings of fries * $2.99 per serving. For optional overnight delivery, add $1.00. Optional insurance is 1% of the cost.
- class Fries : public Package
- {
- public:
- Fries(const char *, const char *, const char *, const char *, const char *, const int, const int, const int, const int, const int, int = 0, int = 0);
- virtual void calcCost();
- virtual void print() const;
- private:
- int num;
- int ins_verify;
- int on_verify;
- int discount_choice;
- float shipping_costs;
- float insurance;
- float total_cost;
- float discount;
- float total_cost_discount;
- };
- Fries::Fries(const char *first, const char *last, const char *addr, const char *cit, const char *stat, const int d, const int m, const int y, const int code, const int on, int n, int ins)
- : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
- {
- num = n;
- ins_verify = ins;
- on_verify = on;
- }
- void Fries::calcCost()
- {
- shipping_costs = num * FRENCHFRY;
- if(on_verify == 1)
- {
- total_cost = shipping_costs + FRENCHFRY_ON;
- }
- else
- {
- total_cost = shipping_costs;
- }
- if(ins_verify == 1)
- {
- insurance = (total_cost * FRENCHFRY_INS);
- total_cost += insurance;
- }
- if(total_cost <= 300)
- {
- discount_choice = 1;
- discount = total_cost *DISCOUNT1;
- }
- else if (total_cost <= 600)
- {
- discount_choice = 2;
- discount = total_cost *DISCOUNT2;
- }
- else if (total_cost <= 1000)
- {
- discount_choice = 3;
- discount = total_cost *DISCOUNT3;
- }
- else
- {
- discount_choice = 4;
- discount = total_cost *DISCOUNT4;
- }
- total_cost_discount = total_cost - discount;
- }
- void Fries::print() const
- {
- Package::print(); // call the base print function
- cout << num << " servings of large fries ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << FRENCHFRY_ON << endl;
- if (ins_verify == 0)
- {
- cout << "No insurance is specified" << endl;
- }
- else
- {
- cout << "The insurance percentage is " << FRENCHFRY_INS * 100 << "% for an additional price of $" << insurance << endl;
- }
- cout << "Total Cost is $" << total_cost << endl;
- cout << "Discount Percentage is ";
- switch(discount_choice)
- {
- case 1:
- cout << DISCOUNT1 * 100;
- break;
- case 2:
- cout << DISCOUNT2 * 100;
- break;
- case 3:
- cout << DISCOUNT3 * 100;
- break;
- case 4:
- cout << DISCOUNT4 * 100;
- break;
- }
- cout << "% for a discount of $" << discount << endl;
- cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
- }
- int main()
- {
- cout << fixed << showpoint << setprecision(2);
- Package* ptr;
- ptr = new VideoGames("Joe", "Blow", "1234 Main Street", "Irvine", "CA", 25, 8, 2018, 92618, 1, 4, 0);
- ptr->calcCost();
- ptr->print();
- ptr = new GeniusPhones("Mary", "Jones", "1234 Final Street", "Tustin", "CA", 25, 8, 2018, 92608, 1, 2, 1, 2);
- ptr->calcCost();
- ptr->print();
- ptr = new Hamburgers("Bill", "Johnson", "1234 Exam Street", "Santa Ana", "CA", 25, 8, 2018, 92706, 1, 5, 1, 5, 5);
- ptr->calcCost();
- ptr->print();
- ptr = new Fries("Bob", "Smith", "1234 A Street", "Cypress", "CA", 25, 8, 2018, 91700, 1, 1, 1);
- ptr->calcCost();
- ptr->print();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement