Guest User

Untitled

a guest
May 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //-----------------------------------------------------------------------
  2. // By: Matt White, 10-12-08, ITCS1212-001, ShipCost2.cpp
  3. // Purpose: Same as #1, with added region cost
  4. //-----------------------------------------------------------------------
  5. #include <iostream>
  6. using namespace std;
  7. double GetShipCost(double dWeight);
  8. double GetRegionCost(char cRegion);
  9.  
  10. int main(){
  11. double dWeight; char cRegion;
  12. cout << "Item Weight = "; cin >> dWeight;
  13. cout << "Item Region = "; cin >> cRegion;
  14. cout << "\n\tWeight: " << dWeight << "\n\tRegion: " << (char)toupper(cRegion) << "\n\tPrice: " << GetShipCost(dWeight) + GetRegionCost(cRegion);
  15. return 0;
  16. }
  17.  
  18.  
  19. double GetShipCost(double dWeight){
  20. double dCost = 0; // Initial Cost
  21. double dAdd = 0; // Additonal amount added to initail cost
  22. int dLimit = 0; // The limit of when add extra $$ for each pound over (used in final cost calculation)
  23.  
  24. if (dWeight<5) {dCost=3; dLimit=0; dAdd = 0;}
  25. if (dWeight>=5 && dWeight<10) {dCost=3; dLimit=5; if (dWeight>5) dAdd = .25;}
  26. if (dWeight>=10 && dWeight<15) {dCost=5.50; dLimit=10; if (dWeight>10) dAdd = .20;}
  27. if (dWeight>=15) {dCost=8.50; dLimit=15; if (dWeight>15) dAdd = .10;}
  28.  
  29. return dCost + (dAdd*(dWeight-dLimit));
  30. }
  31.  
  32. double GetRegionCost(char cRegion){
  33. double dRet;
  34. switch (toupper(cRegion)){
  35. case 'A': dRet = 1.0; break;
  36. case 'B': dRet = 1.5; break;
  37. case 'C': dRet = 2.0; break;
  38. case 'D': dRet = 2.5; break;
  39. }
  40. return dRet;
  41. }
  42.  
  43.  
  44. // ----------------
  45. // Directions:
  46. // 1. Same as #1, with added Region cost.
  47. // 2. The funtion must use switch case. (The values are self-explanatory)
  48. // ----------------
Add Comment
Please, Sign In to add comment