Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ I need help updating my current code to include this... Add calculations

ID: 656433 • Letter: I

Question

In C++ I need help updating my current code to include this...

Add calculations of a delivery charge for the Weight class to include: $100 base charge + $10 for every 1000 lbs or part thereof. Delivery charge will be added to the cost which I already included in my code.

ex) Weight object = 2345 lbs......delivery would be $100 + $10 + $10 + $10 = $130. So the total would be $1172.50 + $130 = $1302.50

Here is my code that needs updating:

#include
#include
using namespace std;

class Material
{
   public:
       Material(float);
       virtual float calcValue() const = 0;
   protected:
       float unit;
};

Material::Material(float value = 0.0)
   :unit(value)
{
}

float Material:: calcValue() const
{
   return unit;
}

class Weight:public Material
{
   public:
       Weight(float);
       float calcValue() const;
};

Weight::Weight(float value)
   :Material(value)
{
}

float Weight::calcValue() const
{
   return unit * .50;
}

class Volume:public Material
{
   public:
       Volume(float);
       float calcValue() const;
};

Volume::Volume(float value)
   :Material(value)
{
}

float Volume::calcValue() const
{
   return unit * .75;
}

class Quantity:public Material
{
   public:
       Quantity(float);
       float calcValue() const;
};

Quantity::Quantity(float value)
   :Material(value)
{
}

float Quantity::calcValue() const
{
   if (unit >= 1 && unit <= 10)
   {
       return unit * 3.00;
   }

   if (unit >= 11 && unit <= 50)
   {
       return unit * 2.50;
   }

   if (unit >= 51)
   {
       return unit * 2.00;
   }
}

void printTotal(ostream &os, Material &val)
{
   os< }

int main(void)
{
   Weight w1(2345.00);
   Volume v1(6550.00);
   Quantity q1(343);

   cout<<"Cost of item with weight of 2345 lbs: ";
   printTotal(cout, w1);

   cout<<"Cost of item with volume of 6550 cubic ft: ";
   printTotal(cout, v1);

   cout<<"Cost of item with quantity of 343: ";
   printTotal(cout, q1);
}

Explanation / Answer

Modified code is highlight with bold.

#include "StdAfx.h"
//Header file section
#include<iostream>
#include<string>
using namespace std;

//Material class
class Material
{
    public:
        Material(float);
        virtual float calcValue() const = 0;
    protected:
        float unit;
};

Material::Material(float value = 0.0):unit(value)
{
}

float Material:: calcValue() const
{
    return unit;
}

class Weight:public Material
{
    public:
        Weight(float);
        float calcValue() const;
};

Weight::Weight(float value):Material(value)
{


}

float Weight::calcValue() const
{

    float val,del,total,baseCharge=100.0;
if(unit>1000)
{
  val=unit/1000;
  del=baseCharge+val*10;
}
total=unit*.50+del;
return total;
}

class Volume:public Material
{
    public:
        Volume(float);
        float calcValue() const;
};

Volume::Volume(float value):Material(value)
{
}

float Volume::calcValue() const
{
    return unit * .75;
}

class Quantity:public Material
{
    public:
        Quantity(float);
        float calcValue() const;
};

Quantity::Quantity(float value):Material(value)
{
}

float Quantity::calcValue() const
{
    if (unit >= 1 && unit <= 10)
    {
        return unit * 3.00;
    }

   if (unit >= 11 && unit <= 50)
    {
        return unit * 2.50;
    }

   if (unit >= 51)
    {
        return unit * 2.00;
    }
}

void printTotal(ostream &os, Material &val)
{
os<<"total: "<<val.calcValue()<<endl;

}

int main(void)
{
    Weight w1(2345.00);
    Volume v1(6550.00);
    Quantity q1(343);

   cout<<"Cost of item with weight of 2345 lbs: ";
    printTotal(cout, w1);
cout<<endl;
   cout<<"Cost of item with volume of 6550 cubic ft: ";
    printTotal(cout, v1);
cout<<endl;
   cout<<"Cost of item with quantity of 343: ";
    printTotal(cout, q1);
cout<<endl;
system("PAUSE");
}

Output: