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
Nataly_w [17]
3 years ago
8

You are responsible for a rail convoy of goods consisting of several boxcars. You start the train and after a few minutes you re

alize that some boxcars are overloaded and weigh too heavily on the rails while others are dangerously light. So you decide to stop the train and spread the weight more evenly so that all the boxcars have exactly the same weight (without changing the total weight). For that you write a program which helps you in the distribution of the weight.
Your program should first read the number of cars to be weighed (integer) followed by the weights of the cars (doubles). Then your program should calculate and display how much weight to add or subtract from each car such that every car has the same weight. The total weight of all of the cars should not change. These additions and subtractions of weights should be displayed with one decimal place. You may assume that there are no more than 50 boxcars.
Example 1
In this example, there are 5 boxcars with different weights summing to 110.0. The ouput shows that we are modifying all the boxcars so that they each carry a weight of 22.0 (which makes a total of 110.0 for the entire train). So we remove 18.0 for the first boxcar, we add 10.0 for the second, we add 2.0 for the third, etc.
Input
5
40.0
12.0
20.0
5. 33.
0
Output
- 18.0
10.0
2.0
17.0
-11.0
Computers and Technology
1 answer:
maks197457 [2]3 years ago
4 0

Answer:

The program in C++ is as follows:

#include <iostream>

#include <iomanip>

using namespace std;

int main(){

   int cars;

   cin>>cars;

   double weights[cars];

   double total = 0;

   for(int i = 0; i<cars;i++){

       cin>>weights[i];

       total+=weights[i];    }

   double avg = total/cars;

   for(int i = 0; i<cars;i++){

       cout<<fixed<<setprecision(1)<<avg-weights[i]<<endl;    }

   return 0;

}

Explanation:

This declares the number of cars as integers

   int cars;

This gets input for the number of cars

   cin>>cars;

This declares the weight of the cars as an array of double datatype

   double weights[cars];

This initializes the total weights to 0

   double total = 0;

This iterates through the number of cars

   for(int i = 0; i<cars;i++){

This gets input for each weight

       cin>>weights[i];

This adds up the total weight

       total+=weights[i];    }

This calculates the average weights

   double avg = total/cars;

This iterates through the number of cars

   for(int i = 0; i<cars;i++){

This prints how much weight to be added or subtracted

       cout<<fixed<<setprecision(1)<<avg-weights[i]<<endl;    }

You might be interested in
Arman takes a picture with his smartphone which he subsequently posts online. Beatrice finds the picture online and posts a copy
KatRina [158]

Answer:C

Explanation:

5 0
3 years ago
If a football player had to use the restroom during a play what do they do?
Artyom0805 [142]
Usually they wait for halftime
4 0
3 years ago
How does the PC support page of About.com make it quick and easy for users to identify and fix errors?
Simora [160]

Answer:

It offers advice on how to repair and maintain your computer.

Explanation:

About.com does not exist anymore sadly. However, it is available with a new name dot dash. And the PC support option is available under livewire. And here you can get advice on how to repair and maintain your computer. And that was the theme behind the About.com. And it has nothing to do with the links to useful tech support websites and forums, or it does not advertise the software which protects you from third-party threats. And it does not as well detail the list of error messages and the symptoms. And hence the correct option is as mentioned in the Answer section.

6 0
4 years ago
List of all the storage devices that you use for storing your school projects and assignments then state the reason you chose th
Dmitry [639]

Answer:

I use my oldest computer to store my information

Explanation:

I use my old computer to store things because it does not function properly such as taking a slow time loading or shutting down completely so I use it to store my data.

6 0
4 years ago
Read 2 more answers
What's the best option if you cant show your power point presentation at all?
Harrizon [31]
My dog ate my power point?
6 0
3 years ago
Read 2 more answers
Other questions:
  • Reasons for the growth of decision-making systems include:
    13·1 answer
  • A group of students want to create an educational online game for computer laboratory in their school which type of network will
    6·1 answer
  • Sadie helman runs a web site for amateur snowboarders. she likes to post videos and music related to snowboarding on her site as
    12·1 answer
  • Problem # 1 [End of chapter problem] The following character encoding is used in a data link protocol: A: 01100111 B: 11110011 F
    14·1 answer
  • Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. End with a n
    10·1 answer
  • Of all excavation hazards, _______ poses the greatest risk
    8·1 answer
  • This is the term popularly used to describe fixing errors in a computer program.
    9·2 answers
  • Finish the program to compute how many gallons of paint are needed to cover the given square feet of walls. Assume 1 gallon can
    9·1 answer
  • $
    15·2 answers
  • All character entities end with _____ to signal the browser that everything in between is an entity representing a symbol.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!