Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.81 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<iomanip>
  4.  
  5. #define DISCOUNT1 .019
  6. #define DISCOUNT2 .026
  7. #define DISCOUNT3 .029
  8. #define DISCOUNT4 .034
  9.  
  10. #define VIDGAM 19.99
  11. #define VIDGAM_ON 4.99
  12. #define VIDGAM_INS .06
  13.  
  14. #define GENIUSPH 799.99
  15. #define GENIUSPH_ON 25.00
  16. #define GENIUSPH_CASE 24.99
  17. #define GENIUSPH_INS .11
  18.  
  19. #define HAMBURG 7.99
  20. #define HAMBURG_ON 9.00
  21. #define HAMBURG_CON 1.79
  22. #define HAMBURG_BUN 1.89
  23. #define HAMBURG_INS .03
  24.  
  25. #define FRENCHFRY 2.99
  26. #define FRENCHFRY_ON 1.00
  27. #define FRENCHFRY_INS .01
  28.  
  29.  
  30. using namespace std;
  31.  
  32.  
  33. class Package
  34. {
  35. public:
  36. Package(const char *, const char *, const char *, const char *, const char *, const int, const int, const int, const int, const int); // constructor
  37. ~Package(); // destructor reclaims memory
  38. virtual void calcCost() = 0; // pure virtual
  39. //to make abstract base class
  40. virtual void print() const;
  41.  
  42. private:
  43. char *firstName;
  44. char *lastName; // dynamically allocated string
  45. char *address;
  46. char *city;
  47. char *state;
  48. int day;
  49. int month;
  50. int year;
  51. int zip;
  52. int overnightDelivery;
  53. };
  54.  
  55.  
  56.  
  57. 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)
  58. {
  59. firstName = new char[strlen(first) + 1];
  60. strcpy_s(firstName, strlen(first) + 1, first);
  61.  
  62. lastName = new char[strlen(last) + 1];
  63. strcpy_s(lastName, strlen(last)+1, last);
  64.  
  65. address = new char[strlen(addr) + 1];
  66. strcpy_s(address, strlen(addr)+1, addr);
  67.  
  68. city = new char[strlen(cit) + 1];
  69. strcpy_s(city, strlen(cit)+1, cit);
  70.  
  71. state = new char[strlen(stat) + 1];
  72. strcpy_s(state, strlen(stat)+1, stat);
  73.  
  74. day = d;
  75. month = m;
  76. year = y;
  77. overnightDelivery = on;
  78. zip = code;
  79. }
  80.  
  81.  
  82. void Package::print() const
  83. {
  84. if (overnightDelivery == 1)
  85. {
  86. cout << "Customer: " << firstName << ' ' << lastName << "\t\t Expected Arrival Date: " << month << '-' << day + 1 << '-' << year << endl;
  87.  
  88. }
  89. else
  90. {
  91. cout << "Customer: " << firstName << ' ' << lastName << "\t\t Expected Arrival Date: " << month << '-' << day + 5 << '-' << year << endl;
  92. }
  93.  
  94.  
  95. cout << "\t\t" << address << endl;
  96. cout << "\t\t" << city << ", " << state << " " << zip << endl;
  97. }
  98.  
  99.  
  100.  
  101.  
  102. Package::~Package()
  103. {
  104. delete[] firstName;
  105. delete[] lastName;
  106. delete[] address;
  107. delete[] city;
  108. delete[] state;
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. class VideoGames : public Package
  116. {
  117. public:
  118. 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);
  119. virtual void calcCost();
  120. virtual void print() const;
  121.  
  122. private:
  123. int num;
  124. int ins_verify;
  125. int on_verify;
  126. int discount_choice;
  127. float shipping_costs;
  128. float insurance;
  129. float total_cost;
  130. float discount;
  131. float total_cost_discount;
  132. };
  133.  
  134.  
  135.  
  136. 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)
  137. : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
  138. {
  139. num = n;
  140. ins_verify = ins;
  141. on_verify = on;
  142. }
  143.  
  144.  
  145.  
  146. void VideoGames::calcCost()
  147. {
  148. shipping_costs = num * VIDGAM;
  149.  
  150. if(on_verify == 1)
  151. {
  152. total_cost = shipping_costs + VIDGAM_ON;
  153. }
  154.  
  155. else
  156. {
  157. total_cost = shipping_costs;
  158. }
  159.  
  160. if(ins_verify == 1)
  161. {
  162. insurance = (total_cost * VIDGAM_INS);
  163. total_cost += insurance;
  164. }
  165.  
  166. if(total_cost <= 300)
  167. {
  168. discount_choice = 1;
  169. discount = total_cost *DISCOUNT1;
  170. }
  171.  
  172. else if (total_cost <= 600)
  173. {
  174. discount_choice = 2;
  175. discount = total_cost *DISCOUNT2;
  176. }
  177.  
  178. else if (total_cost <= 1000)
  179. {
  180. discount_choice = 3;
  181. discount = total_cost *DISCOUNT3;
  182. }
  183.  
  184. else
  185. {
  186. discount_choice = 4;
  187. discount = total_cost *DISCOUNT4;
  188. }
  189.  
  190. total_cost_discount = total_cost - discount;
  191.  
  192.  
  193.  
  194. }
  195.  
  196.  
  197.  
  198.  
  199.  
  200. void VideoGames::print() const
  201. {
  202. Package::print(); // call the base print function
  203.  
  204. cout << num << " video games ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << VIDGAM_ON << endl;
  205. if (ins_verify == 0)
  206. {
  207. cout << "No insurance is specified" << endl;
  208. }
  209.  
  210. else
  211. {
  212. cout << "The insurance percentage is " << VIDGAM_INS * 100 << "% for an additional price of $" << insurance << endl;
  213. }
  214.  
  215. cout << "Total Cost is $" << total_cost << endl;
  216. cout << "Discount Percentage is ";
  217. switch(discount_choice)
  218. {
  219. case 1:
  220. cout << DISCOUNT1 * 100;
  221. break;
  222. case 2:
  223. cout << DISCOUNT2 * 100;
  224. break;
  225. case 3:
  226. cout << DISCOUNT3 * 100;
  227. break;
  228. case 4:
  229. cout << DISCOUNT4 * 100;
  230. break;
  231. }
  232. cout << "% for a discount of $" << discount << endl;
  233. cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
  234. }
  235.  
  236.  
  237.  
  238. class GeniusPhones : public Package
  239. {
  240. public:
  241. 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);
  242. virtual void calcCost();
  243. virtual void print() const;
  244.  
  245. private:
  246. int num;
  247. int num_cases;
  248. int ins_verify;
  249. int on_verify;
  250. int discount_choice;
  251. float shipping_costs;
  252. float cases_costs;
  253. float insurance;
  254. float total_cost;
  255. float discount;
  256. float total_cost_discount;
  257. };
  258.  
  259.  
  260.  
  261. 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)
  262. : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
  263. {
  264. num = n;
  265. ins_verify = ins;
  266. on_verify = on;
  267. num_cases = c;
  268. }
  269.  
  270.  
  271.  
  272. void GeniusPhones::calcCost()
  273. {
  274. shipping_costs = num * GENIUSPH;
  275. cases_costs = num_cases * GENIUSPH_CASE;
  276. if(on_verify == 1)
  277. {
  278. total_cost = shipping_costs + GENIUSPH_ON;
  279. }
  280.  
  281. else
  282. {
  283. total_cost = shipping_costs;
  284. }
  285. total_cost += cases_costs;
  286.  
  287. if(ins_verify == 1)
  288. {
  289. insurance = (total_cost * GENIUSPH_INS);
  290. total_cost += insurance;
  291. }
  292.  
  293. if(total_cost <= 300)
  294. {
  295. discount_choice = 1;
  296. discount = total_cost *DISCOUNT1;
  297. }
  298.  
  299. else if (total_cost <= 600)
  300. {
  301. discount_choice = 2;
  302. discount = total_cost *DISCOUNT2;
  303. }
  304.  
  305. else if (total_cost <= 1000)
  306. {
  307. discount_choice = 3;
  308. discount = total_cost *DISCOUNT3;
  309. }
  310.  
  311. else
  312. {
  313. discount_choice = 4;
  314. discount = total_cost *DISCOUNT4;
  315. }
  316.  
  317. total_cost_discount = total_cost - discount;
  318.  
  319.  
  320.  
  321. }
  322.  
  323.  
  324.  
  325.  
  326.  
  327. void GeniusPhones::print() const
  328. {
  329. Package::print(); // call the base print function
  330.  
  331. cout << num << " genius phones ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << GENIUSPH_ON << endl;
  332. if (ins_verify == 0)
  333. {
  334. cout << "No insurance is specified" << endl;
  335. }
  336.  
  337. else
  338. {
  339. cout << "The insurance percentage is " << GENIUSPH_INS * 100 << "% for an additional price of $" << insurance << endl;
  340. }
  341.  
  342. if (num_cases != 0)
  343. {
  344. cout << num_cases << " genius phone cases ordered for an additional price of $" << cases_costs << endl;
  345. }
  346.  
  347. else
  348. {
  349. cout << "No cases ordered" << endl;
  350. }
  351.  
  352. cout << "Total Cost is $" << total_cost << endl;
  353. cout << "Discount Percentage is ";
  354. switch(discount_choice)
  355. {
  356. case 1:
  357. cout << DISCOUNT1 * 100;
  358. break;
  359. case 2:
  360. cout << DISCOUNT2 * 100;
  361. break;
  362. case 3:
  363. cout << DISCOUNT3 * 100;
  364. break;
  365. case 4:
  366. cout << DISCOUNT4 * 100;
  367. break;
  368. }
  369. cout << "% for a discount of $" << discount << endl;
  370. cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
  371. }
  372.  
  373.  
  374.  
  375. class Hamburgers : public Package
  376. {
  377. public:
  378. 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);
  379. virtual void calcCost();
  380. virtual void print() const;
  381.  
  382. private:
  383. int num;
  384. int num_condiments;
  385. int num_buns;
  386. int ins_verify;
  387. int on_verify;
  388. int discount_choice;
  389. float shipping_costs;
  390. float condiments_costs;
  391. float buns_costs;
  392. float insurance;
  393. float total_cost;
  394. float discount;
  395. float total_cost_discount;
  396. };
  397.  
  398.  
  399.  
  400. 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)
  401. : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
  402. {
  403. num = n;
  404. ins_verify = ins;
  405. on_verify = on;
  406. num_condiments = c;
  407. num_buns = b;
  408. }
  409.  
  410.  
  411.  
  412. void Hamburgers::calcCost()
  413. {
  414. shipping_costs = num * HAMBURG;
  415. condiments_costs = num_condiments * HAMBURG_CON;
  416. buns_costs = num_buns * HAMBURG_BUN;
  417. if(on_verify == 1)
  418. {
  419. total_cost = shipping_costs + HAMBURG_ON;
  420. }
  421.  
  422. else
  423. {
  424. total_cost = shipping_costs;
  425. }
  426. total_cost += condiments_costs + buns_costs;
  427.  
  428. if(ins_verify == 1)
  429. {
  430. insurance = (total_cost * HAMBURG_INS);
  431. total_cost += insurance;
  432. }
  433.  
  434. if(total_cost <= 300)
  435. {
  436. discount_choice = 1;
  437. discount = total_cost *DISCOUNT1;
  438. }
  439.  
  440. else if (total_cost <= 600)
  441. {
  442. discount_choice = 2;
  443. discount = total_cost *DISCOUNT2;
  444. }
  445.  
  446. else if (total_cost <= 1000)
  447. {
  448. discount_choice = 3;
  449. discount = total_cost *DISCOUNT3;
  450. }
  451.  
  452. else
  453. {
  454. discount_choice = 4;
  455. discount = total_cost *DISCOUNT4;
  456. }
  457.  
  458. total_cost_discount = total_cost - discount;
  459.  
  460.  
  461.  
  462. }
  463.  
  464.  
  465.  
  466.  
  467.  
  468. void Hamburgers::print() const
  469. {
  470. Package::print(); // call the base print function
  471.  
  472. cout << num << " hamburgers ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << HAMBURG_ON << endl;
  473. if (ins_verify == 0)
  474. {
  475. cout << "No insurance is specified" << endl;
  476. }
  477.  
  478. else
  479. {
  480. cout << "The insurance percentage is " << HAMBURG_INS * 100 << "% for an additional price of $" << insurance << endl;
  481. }
  482.  
  483. if (num_condiments != 0)
  484. {
  485. cout << num_condiments << " condiment servings ordered for an additional price of $" << condiments_costs << endl;
  486. }
  487.  
  488. else
  489. {
  490. cout << "No condiments ordered" << endl;
  491. }
  492.  
  493. if (num_buns != 0)
  494. {
  495. cout << num_buns << " pair of buns ordered for an additional price of $" << buns_costs << endl;
  496. }
  497.  
  498. else
  499. {
  500. cout << "No buns ordered" << endl;
  501. }
  502.  
  503. cout << "Total Cost is $" << total_cost << endl;
  504. cout << "Discount Percentage is ";
  505. switch(discount_choice)
  506. {
  507. case 1:
  508. cout << DISCOUNT1 * 100;
  509. break;
  510. case 2:
  511. cout << DISCOUNT2 * 100;
  512. break;
  513. case 3:
  514. cout << DISCOUNT3 * 100;
  515. break;
  516. case 4:
  517. cout << DISCOUNT4 * 100;
  518. break;
  519. }
  520. cout << "% for a discount of $" << discount << endl;
  521. cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
  522. }
  523.  
  524.  
  525. //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.
  526. class Fries : public Package
  527. {
  528. public:
  529. 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);
  530. virtual void calcCost();
  531. virtual void print() const;
  532.  
  533. private:
  534. int num;
  535. int ins_verify;
  536. int on_verify;
  537. int discount_choice;
  538. float shipping_costs;
  539. float insurance;
  540. float total_cost;
  541. float discount;
  542. float total_cost_discount;
  543. };
  544.  
  545.  
  546.  
  547. 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)
  548. : Package(first, last, addr, cit, stat, d, m, y, code, on) // call base-class constructor
  549. {
  550. num = n;
  551. ins_verify = ins;
  552. on_verify = on;
  553. }
  554.  
  555.  
  556.  
  557. void Fries::calcCost()
  558. {
  559. shipping_costs = num * FRENCHFRY;
  560.  
  561. if(on_verify == 1)
  562. {
  563. total_cost = shipping_costs + FRENCHFRY_ON;
  564. }
  565.  
  566. else
  567. {
  568. total_cost = shipping_costs;
  569. }
  570.  
  571. if(ins_verify == 1)
  572. {
  573. insurance = (total_cost * FRENCHFRY_INS);
  574. total_cost += insurance;
  575. }
  576.  
  577. if(total_cost <= 300)
  578. {
  579. discount_choice = 1;
  580. discount = total_cost *DISCOUNT1;
  581. }
  582.  
  583. else if (total_cost <= 600)
  584. {
  585. discount_choice = 2;
  586. discount = total_cost *DISCOUNT2;
  587. }
  588.  
  589. else if (total_cost <= 1000)
  590. {
  591. discount_choice = 3;
  592. discount = total_cost *DISCOUNT3;
  593. }
  594.  
  595. else
  596. {
  597. discount_choice = 4;
  598. discount = total_cost *DISCOUNT4;
  599. }
  600.  
  601. total_cost_discount = total_cost - discount;
  602.  
  603.  
  604.  
  605. }
  606.  
  607.  
  608.  
  609.  
  610.  
  611. void Fries::print() const
  612. {
  613. Package::print(); // call the base print function
  614.  
  615. cout << num << " servings of large fries ordered: shipping cost is $" << shipping_costs << ", overnight delivery is $" << FRENCHFRY_ON << endl;
  616. if (ins_verify == 0)
  617. {
  618. cout << "No insurance is specified" << endl;
  619. }
  620.  
  621. else
  622. {
  623. cout << "The insurance percentage is " << FRENCHFRY_INS * 100 << "% for an additional price of $" << insurance << endl;
  624. }
  625.  
  626. cout << "Total Cost is $" << total_cost << endl;
  627. cout << "Discount Percentage is ";
  628. switch(discount_choice)
  629. {
  630. case 1:
  631. cout << DISCOUNT1 * 100;
  632. break;
  633. case 2:
  634. cout << DISCOUNT2 * 100;
  635. break;
  636. case 3:
  637. cout << DISCOUNT3 * 100;
  638. break;
  639. case 4:
  640. cout << DISCOUNT4 * 100;
  641. break;
  642. }
  643. cout << "% for a discount of $" << discount << endl;
  644. cout << "Total Cost after discount is $" << total_cost_discount << endl << endl;
  645. }
  646.  
  647.  
  648.  
  649. int main()
  650. {
  651. cout << fixed << showpoint << setprecision(2);
  652.  
  653.  
  654. Package* ptr;
  655.  
  656. ptr = new VideoGames("Joe", "Blow", "1234 Main Street", "Irvine", "CA", 25, 8, 2018, 92618, 1, 4, 0);
  657. ptr->calcCost();
  658. ptr->print();
  659.  
  660. ptr = new GeniusPhones("Mary", "Jones", "1234 Final Street", "Tustin", "CA", 25, 8, 2018, 92608, 1, 2, 1, 2);
  661. ptr->calcCost();
  662. ptr->print();
  663.  
  664. ptr = new Hamburgers("Bill", "Johnson", "1234 Exam Street", "Santa Ana", "CA", 25, 8, 2018, 92706, 1, 5, 1, 5, 5);
  665. ptr->calcCost();
  666. ptr->print();
  667.  
  668. ptr = new Fries("Bob", "Smith", "1234 A Street", "Cypress", "CA", 25, 8, 2018, 91700, 1, 1, 1);
  669. ptr->calcCost();
  670. ptr->print();
  671.  
  672. system("pause");
  673. return 0;
  674. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement