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

write C++ program. Introduction: This assignment helps you to reinforce the topi

ID: 3849935 • Letter: W

Question

write C++ program.

Introduction: This assignment helps you to reinforce the topics discussed in the class including

a)     Problem solving process

b)    Using cin and cout objects

c)     Develop a program that involves data input, variables, and arithmetic operations.

Shipping Charges Program

The Fast Freight Shipping Company charges following rates

Weight of Packages (pounds)

Rate per 500 miles Shipped

2 => weight

$1.10

2 < weight <= 6

$2.20

6 < weight <= 10

$3.70

10 < weight <= 20

$4.80

Write a C++ program that asks for the weight of the package and the distance to be shipped. Then, compute the total charge. Charge is computed in 500 mile increments. For example, if the weight of the package is 3 pounds and distance to travel is 680 miles, then the charge will be

$2.20 * 2 = $4.40

You might need to use the ceil() method defined the cmath library for this computation. Definition of ceil() method can be found @

http://www.cplusplus.com/reference/cmath/ceil/

Also, here is an example of its usage

      int x=680;

      int y = 500;

      double range = ceil((static_cast<double>(x)/y);

      cout<<range;

Input validation:

Do not accept 0 or less for the weight of the package. If the weight of the package is 0 or less, display the message “weight should be a greater than 0”

Do not accept more than 20 for the weight of the package. If the weight of the pages more than 20, display the message “max weight should 20”

Also, do not accept the distances of less than 10 and greater than 3000 (these are the company’s min and mx shipping distances)

Weight of Packages (pounds)

Rate per 500 miles Shipped

2 => weight

$1.10

2 < weight <= 6

$2.20

6 < weight <= 10

$3.70

10 < weight <= 20

$4.80

Explanation / Answer

The program is as below

#include <iostream>

using namespace std;

int main()
{
float w,d;
double charge;
int mile;
cout <<"Please enter weight and distance"<< endl;
cin>>w;
cin>>d;

if(w<0)
{
cout<<"Weight should be greater than 0";
}

if(w>20)
{
cout<<"Max weight allowed is 20";
}

if(d< 10 || d>3000)
{
cout<<"Distance doesn't meet allowed limit";
}

if(d<=500)
{
mile = 1;
}
else if(d>500 && d<=1000)
{
mile = 2;
}
else if(d>1000 && d<=1500)
{
mile = 3;
}
else if(d>1500 && d<=2000)
{
mile = 4;
}
else if(d>2000 && d<=2500)
{
mile = 5;
}
else if(d>2500 && d<=3000)
{
mile = 6;
}   

if(w<=2)
{
charge= 1.10*mile;
}
else if(w>2 && w<=6)
{
charge= 2.20*mile;
}
else if(w>6 && w<=10)
{
charge= 3.70*mile;
}
else if(w>10 && w<=20)
{
charge = 4.80*mile;
}


cout<<"Charge is"<<charge;
return 0;
}