1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Andre45 [30]
4 years ago
11

g Write a program that asks for the weight of a package and the distance it is to be shipped. This information should be passed

to a calculateCharge function that computes and returns the shipping charge to be displayed . The main function should loop to handle multiple packages until a weight of 0 is entered.

Computers and Technology
1 answer:
DIA [1.3K]4 years ago
7 0

Answer:

I am writing a C++ program:

#include <iostream>  //to use input output functions

#include<iomanip>  // to format the output

using namespace std;   // to identify objects like cin cout

void calculateCharge(double weight, double distance);   // function prototype

int main(){  //start of main() function body

  double w = 0.0, t = 0.0;  // w variable is for weight and t is for total

   unsigned int d = 0;   // d variable is to hold the value of distance

   calculateCharge(w, d); }  //calls calculateCharge method by passing weight and distance values to this method

void calculateCharge(double weight, double distance){  //method that takes weight and distance as parameters and compute the shipping charge

   double charge = 0.0;  //to store the value of shipping charges

   do {  // do while loop to handle multiple packages until a weight of 0 is entered

       cout << "Enter weight: " << endl;  //prompts user to enter weight

       cin >> weight;  //reads the input weight value

       if (weight == 0){  // if the value of weight is equal to 0

           break; }  // the loop breaks if value of weight is 0

       cout << "Enter distance: " << endl;  // if value of weight is not zero then the program precedes by prompting user to enter the value of distance

       cin >> distance;  //reads the input distance value

       cout << fixed << setprecision(2) << endl;  //set the precision to 2 means the sets the number of digits of an output to 2 decimal places

       if(weight <= 2)  //if the value of weight is less than or equals to 2

charge = (distance/500) * 3.10;  //compute the charge by this formula

else if(weight > 2 && weight <= 6)  //if weight is over 2 kg but not more than 6 kg

charge = (distance/500) * 4.20;  //charge is computed by multiplying value of distance to that of weight and if distance is greater than 500 then it is divided by 500 first

else if(weight > 6 && weight <= 10)  // if weight is over 6 kg but not more than 10 kg

charge = (distance/500) * 5.30;  //compute shipping charges by this formula

else  //if weight is over 10 kg

charge = (distance/500) * 6.40;   // compute shipping charge by multiplying value of distance to that of 6.40 weight value and if distance is greater than 500 then distance is divided by 500 first

cout << "Shipping charges: $" << charge << "\n";   //display the computed shipping charge

   } while (weight != 0);  //the loop continues to execute until weight 0 is entered

}              

Explanation:

The program is explained in the comments mentioned above. The program has a main() function that declares variable for weight, distance and total and then calls calculateCharge() method passing weight and dsitance in order to compute and return the shipping charge.

In calculateCharge() the user is prompted to enter the values for weight and distance. Then the based on the value of weight , the shipping charge is computed. Shipping charge is computed by multiplying the weight with distance. The distance is assumed to be 500 but if the distance entered by user exceeds 500 then the distance value is divided by 500 and then multiplied by the specified weight (according to if or else if conditions) in order to compute shipping charge. The program has a do while loop that keeps taking input from user until the user enters 0 as the value of weight.

The screenshot of the program and its output is attached.

You might be interested in
What special member function of a class is called whenever an instance of a class is created and initialized?
allochka39001 [22]
It's called a constructor function, but it's name is the same as the class' name.
6 0
3 years ago
What does no technical solution problems mean answers?
Lena [83]
Solve the problems to make every thing work perfect
4 0
3 years ago
How can you use the Address Book to address an email message? Use the drop-down menus to complete the sentences. 1. Type an emai
Delvig [45]

Answer:

1. AutoCorrect

2. Address book

Explanation:

stan bts ?

5 0
3 years ago
Read 2 more answers
What is the difference between Windows 7 and Windows 10?
Tanzania [10]
Windows 10 is new and windows 7 is old
6 0
3 years ago
How to instal and complie java in windows?
Paladinen [302]
Go to www.oracle.com , the Downloads tab, find Java, probably SE (Standard Edition) and then select the appropriate SDK (Software Development Kit).

I don't remember if you need to use an absolute (full) path to javac on Windows, but the command is something like:

javac yourProgram

yourProgram needs to be named yourProgram.java
4 0
3 years ago
Other questions:
  • Why does hamlet want to kill himself and what stops him from doing that?
    10·1 answer
  • Why process scheduling is needed in a uni-processor system?
    12·1 answer
  • A bakery sells three types of muffins whose prices are as follows: 1- blueberry muffin, $2.98 2- chocolate chip muffin, $4.50 an
    6·1 answer
  • What are the pros and cons of the internet’s ability to access information
    8·2 answers
  • The false reject rate describes the number of legitimate users who are denied access because of a failure in the biometric devic
    11·1 answer
  • In a TCP session hijacking attack, if the server is waiting for data starting from sequence number X, but we used X 100 in our a
    13·2 answers
  • MICR is an input or output devices
    5·1 answer
  • 2y/3 - y-1/6 + 7y-1/4 = 2 1/6​
    5·1 answer
  • I need the answers. i don’t get this
    11·1 answer
  • The _____ of a story describes the time and location of a story.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!