fork download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. //Material class
  6. class Material
  7. {
  8. public:
  9. Material(float);
  10. virtual float calcValue() const = 0;
  11. protected:
  12. float unit;
  13. };
  14. Material::Material(float value)
  15. :unit(value)
  16. {}
  17. float Material:: calcValue() const
  18. {
  19. return unit;
  20. }
  21.  
  22. class Weight:public Material
  23. {
  24. public:
  25. Weight(float);
  26. float calcValue() const;
  27. };
  28.  
  29. Weight::Weight(float value)
  30. :Material(value){}
  31.  
  32. float Weight::calcValue() const
  33. {
  34.  
  35. float val,del,total,baseCharge=100.0;
  36. if(unit>1000)
  37. {
  38. val=unit/1000;
  39. del=baseCharge+val*10;
  40. }
  41. total=unit*.50+del;
  42. return total;
  43. }
  44.  
  45. class Volume:public Material
  46. {
  47. public:
  48. Volume(float);
  49. float calcValue() const;
  50. };
  51.  
  52. Volume::Volume(float value):Material(value)
  53. {
  54. }
  55.  
  56. float Volume::calcValue() const
  57. {
  58. return unit * .75;
  59. }
  60.  
  61. class Quantity:public Material
  62. {
  63. public:
  64. Quantity(float);
  65. float calcValue() const;
  66. };
  67.  
  68. Quantity::Quantity(float value)
  69. :Material(value){}
  70.  
  71. float Quantity::calcValue() const
  72. {
  73. if (unit >= 1 && unit <= 10)
  74. {
  75. return unit * 3.00;
  76. }
  77.  
  78. if (unit >= 11 && unit <= 50)
  79. {
  80. return unit * 2.50;
  81. }
  82.  
  83. if (unit >= 51)
  84. {
  85. return unit * 2.00;
  86. }
  87. }
  88.  
  89. void printTotal(ostream &os, Material &val)
  90. {
  91. os<<"total: "<<val.calcValue()<<endl;
  92.  
  93. }
  94.  
  95. int main(void)
  96. {
  97. Weight w1(2345.00);
  98. Volume v1(6550.00);
  99. Quantity q1(343);
  100.  
  101. cout<<"Cost of item with weight of 2345 lbs: ";
  102. printTotal(cout, w1);
  103. cout<<endl;
  104. cout<<"Cost of item with volume of 6550 cubic ft: ";
  105. printTotal(cout, v1);
  106. cout<<endl;
  107. cout<<"Cost of item with quantity of 343: ";
  108. printTotal(cout, q1);
  109. cout<<endl;
  110. system("PAUSE");
  111. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:87:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
prog.cpp:110:5: error: use of undeclared identifier 'system'
    system("PAUSE");
    ^
1 warning and 1 error generated.
stdout
Standard output is empty