In: Computer Science
Please use original C++ code for this. This is for visual studio.
Program 5: Shipping Calculator
The Speedy Shipping Company will ship packages based on how much they weigh and how far they are being sent. They will only ship small packages up to 10 pounds. You have been tasked with writing a program that will help Speedy Shipping determine how much to charge per delivery.
The charges are based on each 500 miles shipped. Shipping charges are not pro-rated; i.e., 600 miles is the same charge as 900 miles; i.e., 600 miles is counted as 2 segments of 500 miles.
Here is the table they gave you:
Package Weight Rate per 500 miles shipped
2 pounds or less $1.50
More than 2 but not more than 6 $3.70
More than 6 but not more than 10 $5.35
Test Case 1:
Input Data:
Weight: 1.5 pounds
Miles: 200 miles (This is one 500-mile segment.)
Expected result:
To ship a 1.5 pound package 200 miles, your shipping charge is $1.50.
Test Case 2:
Input Data:
Weight: 5.6 pounds
Miles: 1200 miles (This is three 500-mile segments.)
Expected result:
To ship a 5.6 pound package 1200 miles, your shipping charge is $11.10.
Test Case 3:
Weight: 1.0 pounds
Miles: 2500 miles (This is five 500-mile segments.)
Expected result:
To ship a 1.0 pound package 2500 miles, your shipping charge is $7.50.
Test Case 4:
Weight: 8.5 pounds
Miles: 12345 miles (This is twenty-five 500-mile segments.)
Expected result:
To ship a 8.5 pound package 12345 miles, your shipping charge is $133.75.
Test Case 5:
Weight: 12.8 pounds
Miles: 345 miles
Expected result:
Sorry, we only ship packages of 10 pounds or less.
Hints: This program does not need any loops. The program will calculate one shipping charge and stop. Your test cases should test the various possibilities, and the limits of the program.
BIG Helpful Hint: You can use integer division. For example: 1200 / 500 = 2
Send email if you are stuck, or if there is something in this assignment that you are confused about.
Rubric:
Well-formatted code (indentation, use of whitespace, comments) |
10% |
Good variable names (proper case, meaningful identifiers) |
10% |
Good prompts (accurate, easy-to-use user interface) |
10% |
Calculations are correct |
40% |
Well-formatted output |
10% |
Screenshots showing your program running on your computer |
20% |
#include<iostream>
#include<iomanip>
#include <cmath>
using namespace std;
int main() {
// declare variables
double weightOfPackage, shippingCost = 0;
int distanceInMiles, segments;
// read weight
cout << "Input weight of the package: ";
cin >> weightOfPackage;
// read distance
cout << "Input distance for the shipping in miles: ";
cin >> distanceInMiles;
// determine the segments
segments = ceil(distanceInMiles / 500.0);
// fix the decimal precision to 2
cout << fixed << setprecision(2);
// if weight is less than 2 pounds
if (weightOfPackage <= 2){
// calculate cost
shippingCost = 1.5 * segments;
// display result
cout << "To ship a " << weightOfPackage << " pound package " << distanceInMiles << " miles, your shipping charge is $" << shippingCost << endl;
}
// if weight is between 2-6
else if (weightOfPackage > 2 && weightOfPackage <= 6){
// calculate cost
shippingCost = 3.7 * segments;
// display result
cout << "To ship a " << weightOfPackage << " pound package " << distanceInMiles << " miles, your shipping charge is $" << shippingCost <<endl;
}
// if weight is between 6-10
else if (weightOfPackage > 6 && weightOfPackage <= 10) {
// calculate cost
shippingCost = 5.25 * segments;
// display result
cout << "To ship a " << weightOfPackage << " pound package " << distanceInMiles << " miles, your shipping charge is $" << shippingCost << endl;
}
// if weight is greater than 10
else {
cout << "Sorry, we only ship packages of 10 pounds or less." << endl;
}
return 0;
}
FOR HELP PLEASE COMMENT.
THANK YOU