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
Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90)
yanalaym [24]

Answer:

The solution in python.

Output:

   print("0 is not a valid interstate highway number")

Explanation:

h = int(input("enter highway number: ")) #take highway number

if(h>=1 and h<=99): #for primary highway

   if(h%2==0):

       print("I-%d is primary, going east/west" %h) #for even highway number

   else:

       print("I-%d is primary, going north/south" %h) #for odd highway number

elif(h>=100 and h<=999): #for auxiliary highway

   aux=str(h) #convert into string for fetch the rightmost number

   l=len(aux) #find the length

   val = aux[l-2]+aux[l-1] #assign value of rightmost two number

   h = int(val) #convert into integer

   if(h%2==0):

       print("I-"+aux+" is auxiliary,"+"serving I-%d, going east/west" %h)

   else:

       print("I-"+aux+" is auxiliary,"+"serving I-%d, going north/south" %h)

elif(h==0):#for 0 highway number

   print("0 is not a valid interstate highway number")

else:

   pass

7 0
3 years ago
What is 1 of the rules for naming variables?
vova2212 [387]

Answer:

<h3>Rules for Naming Variables</h3><h3>The first character must be a letter or an underscore (_). You can't use a number as the first character. The rest of the variable name can include any letter, any number, or the underscore. You can't use any other characters, including spaces, symbols, and punctuation marks.</h3>

<em><u>#</u></em><em><u>M</u></em><em><u>a</u></em><em><u>r</u></em><em><u>k</u></em><em><u>a</u></em><em><u>s</u></em><em><u>b</u></em><em><u>r</u></em><em><u>a</u></em><em><u>i</u></em><em><u>n</u></em><em><u>l</u></em><em><u>e</u></em><em><u>s</u></em><em><u>s</u></em><em><u>p</u></em><em><u>l</u></em><em><u>e</u></em><em><u>a</u></em><em><u>s</u></em><em><u>e</u></em><em><u>✅</u></em>

3 0
3 years ago
Give two examples of situations or applications where electrical circuits are used.
Pavlova-9 [17]

Answer:

lamps, electric motors

Explanation:

5 0
3 years ago
The ________ phase in a project involves documenting lessons learned from the project, so that the experience is useful to other
pentagon [3]

Answer:

C. Closing

Explanation:

Closing phase is the process of concluding all activities for a project, phase, or contract.  The key benefits of this are the project or phase information is archived, the planned work is completed, and organisational team resources are released to pursue new endeavours.  This process is performed once or at predefined points in the project.

The activities necessary for the administrative closure of the project or phase include:

Actions necessary to satisfy completion or exit criteria for the closing phase of a project are :

  • Ensuring that all documents are up-to-date and that all issues are resolved;
  • Confirming the delivery and formal acceptance of project by the client;
  • Ensuring that all costs are charged to the project;
  • Closing project accounts;
6 0
3 years ago
What is the main advantage of a bitmap image?
frosja888 [35]
The answer is d. Hope this helps
4 0
3 years ago
Other questions:
  • As you are planning your informative speech on the prevalence of Internet memes in pop culture and you wonder if your audience w
    14·1 answer
  • Which file is used to determine which tty devices the root user is allowed to log in to?
    8·1 answer
  • So for my Game Design class I have a quiz coming up...I was wondering if someone could answer some of these practice questions,
    7·2 answers
  • Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the int variable
    6·1 answer
  • Which of the following examines the organizational resource of information and regulates its definitions, uses, value, and distr
    9·1 answer
  • 2. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The object
    14·1 answer
  • What are the services offered by web-based email?​
    12·1 answer
  • Need answer ASAP. I’ll mark brainliest if correct
    7·1 answer
  • How do i automate survey monkey results to my email
    11·1 answer
  • You are asked to analyze events in a firewall log that occurred six months ago. when you analyze the log file, you notice events
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!