77 474
Assignments Done
Successfully Done
In July 2019

Answer to Question #32370 in C++ for amal

Question #32370
Print the source code of this program plus the output of the following four executions:
• Execution 1: Input the weight as a negative number of ounces.
• Execution 2: Input the weight as 0ounces.
• Execution 3: Input the weight as 5 ounces.
• Execution 4: Input the weight as 42 ounces.

Write three independent functions for this program assignment as follows:
• One function to read the required input values.
• A second function to perform the required calculations using the input values from the first function.
• A third function to display the results of the second function.
Speedy-Pants Delivery Inc. charges by weight for delivery of packages. The delivery charge for the first pound is $3.00 and $0.50 is added onto the charge for each additional four ounces.

For example:
A package weighing more than 16 but at most 20 ounces costs $3.50 to deliver.
A package weighing more than 20 but at most 24 ounces costs $4.00 to deliver. etc.
Write a program that inputs the weight of a package in ounces, computes the charge for delivery, and displays it to the screen. NOTE: One pound equals 16 ounces.

(1) Use a double-valued function, weight_input, to prompt the user for input.
(2) Use a double-valued function, compute_delivery_charge, to compute the charge for delivery.
(3) Use a void function, display_delivery_charge, to display the delivery charge.
Expert's answer
#include <iostream>

using namespace std;

double weightInput()
double i;
cout << "Input the weight in ounces: ";
cin >> i;
while (i <= 0)
cout << "Please, input a positive value of the weight. It can not be less or equal than zero."<< endl;
cin >> i;
return i;

double computeDeliveryCharge(double weight)
double c = 3.0;
if (weight <= 16) return c;
weight -= 16;
weight /= 4;
int n = ceil(weight);
c += n * 0.5;
return c;

void displayDeliveryCharge (double charge)
cout << "Charge: " << charge << endl;

void main()
while (1)
double x = weightInput();
double y = computeDeliveryCharge(x);

cout << "
Enother package?

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions