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
|
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <chrono>
using namespace std;
class Package
{
public:
Package(const char *, const char *, const char *, const char *, const char *, const char *); //constructor
virtual float cost(bool overnight, bool insurance) = 0; //pure virtual function to make abstract base class
virtual void print() const;
float discount();
private:
char *firstName; //char data member for first name (to be entered in by user)
char *lastName;
char *address;
char *city;
char *state;
char *zip;
float *tcost;
};
Package::Package(const char *first, const char *last, const char *a, const char *c, const char *st, const char *z)
{
firstName = new char[strlen(first) + 1];
strcpy(firstName, first);
lastName = new char[strlen(last) + 1];
strcpy(lastName, last);
address = new char[strlen(a) + 1];
strcpy(address, a);
city = new char[strlen(c) + 1];
strcpy(city, c);
state = new char[strlen(st) + 1];
strcpy(state, st);
zip = new char[strlen(z) + 1];
strcpy(zip, z);
}
void Package::print() const
{
cout << "\t" << firstName << ' ' << lastName << endl;
cout << "\t" << "\t" << address << endl;
cout << "\t" << "\t" << city << ' ' << state << ' ' << zip << endl;
cout << endl;
}
class Game: public Package // Game class derived from Package class
{
public:
Game(const char *, const char *, const char *, const char *, const char *, const char *, int = 0);
float cost(bool overnight, bool insurance);
virtual void print() const;
private:
int numGames;
bool overnight;
bool insurance;
float tcost;
};
Game::Game(const char *first, const char *last, const char *a, const char *c, const char *st, const char *z, int initNumGames)
: Package(first, last, a, c, st, z)
{
numGames = initNumGames;
}
float Game::cost(bool overnight, bool insurance)
{
if (!overnight && !insurance)
return (numGames * (19.99)); //cost
else if (overnight && !insurance)
return ((numGames * (19.99)) + (4.99)); //cost + overnight
else if (!overnight && insurance)
return ((numGames * (19.99)) * (1.06)); //cost + insurance
else
return (((numGames * (19.99)) * (1.06)) + (4.99)); //cost + insurance & overnight
}
//float Package::discount()
//{
// tcost =0.0;
//
// if (cost < 200)
// tcost = cost - (cost * .019);
// return tcost;
//
// else if (cost == 200.01 to 500)
// tcost = cost - (cost * 0.024);
// return tcost;
//
// else if (cost == 500.01 to 1000)
// tcost = cost - (cost * 0.028);
// return tcost;
//
// else
// tcost = cost - (cost * 0.033);
// return tcost;
//}
void Game::print() const
{
cout << "Customer: ";
Package::print(); //call the base-class print function
chrono::system_clock::time_point now = chrono::system_clock::now();
time_t now_c = chrono::system_clock::to_time_t(now + chrono::hours(24)); //overnight shipping time clock
cout << "Overnight Shipping Expected Arrival Date: " << put_time(localtime(&now_c), "%F") << '\n';
chrono::system_clock::time_point now2 = chrono::system_clock::now();
time_t now2_c = chrono::system_clock::to_time_t(now2 + chrono::hours(72)); //standard shipping time clock
cout << "Standard Shipping Expected Arrival Date: " << put_time(localtime(&now2_c), "%F") << '\n';
}
int main()
{
bool overnight;
bool insurance;
Game g("David", "Chalian", "1527 New Quill Street", "Bumblefuck", "CA", "92604", 4);
g.print();
cout << endl;
cout << "Would you like overnight shipping added? [Y/N]";
cin >> overnight;
if (bool overnight = "Y")
return true;
else
return false;
cout << "Would you like insurance? [Y/N]";
cin >> insurance;
if (bool insurance = "Y")
return true;
else
return false;
cout << "Cost without overnight shipping and insurance: $" << g.cost(overnight, insurance) << endl;
}
|