answer.
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]
1 year 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]1 year 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
4.2 Code Practice: Question 2
skad [1K]

I've included my code in the picture below. Best of luck.

5 0
2 years ago
Read 2 more answers
Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
harina [27]

Answer:

One of the strategies to avoid nested conditional is to use logical expressions such as the use of AND & operator.

One strategy is to use an  interface class with a method. That method can be created to be used for a common functionality or purpose. This is also called strategy design pattern. You can move the chunk of conditional statement to that method. Then each class can implement that interface class and use that shared method according to their own required task by creating objects of sub classes and call that common method for any such object. This is called polymorphism.

Explanation:

Nested conditionals refers to the use of if or else if statement inside another if or else if statement or you can simply say a condition inside another condition. For example:

if( condition1) {  

//executes when condition1 evaluates to true

 if(condition2) {

//executes when condition1  and condition2 evaluate to true

 }  else if(condition3) {

 //when condition1 is true and condition3 is true

} else {

 //condition1  is true but neither condition2 nor conditions3 are true

}  }

The deeply nested conditionals make the program difficult to understand or read if the nested conditionals are not indented properly. Also the debugging gets difficult when the program has a lot of nested conditionals.

So in order to avoid nested conditionals some strategies are used such as using a switch statement.

Here i will give an example of one of the strategies i have mentioned in the answer.

Using Logical Expressions:

A strategy to avoid nested conditionals is to use logical expressions with logical operators such as AND operator. The above described example of nested conditionals can be written as:

if(condition1 && condition2){  //this executes only when both condition1 and condition2 are true

} else if(condition1 && condition3) {

this executes only when both condition1 and condition3 are true

} else if(condition1 ){

//condition1  is true but neither condtion2 nor condtion3 are true  }

This can further be modified to one conditional as:

if(!condition3){

// when  condition1 and condition2 are true

}

else

// condition3 is true

Now lets take a simple example of deciding to go to school or not based on some conditions.

if (temperature< 40){

  if (busArrived=="yes")   {

      if (!sick)       {

          if (homework=="done")           {

              printf("Go to school.");

          }

      }     

  }

}

This uses nested conditionals. This can be changed to a single conditional using AND logical operator.

if ((temperature <40) && (busArrived=="yes") &&

(!sick) && (homework=="done"))

{    cout<<"Go to school."; }

6 0
2 years ago
What is the distance rn between the point of application of n⃗ and the axis of rotation? what is the distance rw between the poi
Mandarinka [93]

Complete Question.

A. Suppose that you are holding a pencil balanced on its point. If you release the pencil and it begins to fall, what will be the angular acceleration when it has an angle of 10.0 degrees from the vertical?

B. What is the distance rn between the point of application of n⃗ and the axis of rotation?

C. What is the distance rw between the point of application of w⃗ and the axis? enter your answers in meters separated by a comma?

Answer:

A. â = - 17rad/s²

B. rn = 0, meters

C. rw = 0.074, meters

Explanation:

Where;

l = length of the pencil

θ = angle between the vertical line and the pencil

â = angular acceleration.

The torque due to weight about the pivotal point is negative since it's clockwise;

t = - mg(l/2)sinØ ..... equation 1

torque with respect to angular acceleration;

t = Iâ ..... equation 2

The moment of Inertia of the pencil about one end;

I = (ml²)/3

Substituting I into equation 2;

t = [(ml²)/3]×â

Equating the equation, we have;

[(ml²)/3]×â = - mg(l/2)sinØ

â = (-3gsinØ)/2l

â = (-3*9.8*sin10°)/(2*0.15)

Angular acceleration, â = -17rad/s²

B. The normal force is acting at the normal force only, so the distance r n between the point of application of n ⃗ and the axis of rotation is zero because the axis of pencil is passing the same point of application w.

C. rn = (lcosØ)/2

rn = (0.15 * cos10°)/2

rn = (0.15 * 0.9848)/2

rn = (0.1477)/2

rn = 0.074m.

Since the gravity acts at exactly half of the length of pencil, distance r w between the point of application of w⃗ and the axis equals 0.074m.

8 0
2 years ago
Given the macro definition and global declarations shown in the image below, provide answers to the following questions:
galben [10]

Answer:

A. 243

B. True

C. 0

Explanation:

Macro instruction is a line of coding used in computer programming. The line coding results in one or more coding in computer program and sets variable for using other statements. Macros allows to reuse code. Macro has two parts beginning and end. After the execution of statement of quiz4 x, 4 the macro x will contain 243. When the macro is invoked the statement will result in an error. When the macro codes are executed the edx will contain 0. Edx serve as a macro assembler.

4 0
2 years ago
You want to implement a mechanism that automates ip configuration, including ip address, subnet mask, default gateway, and dns i
telo118 [61]
You're probably looking for DHCP (Dynamic Host Configuration Protocol).
5 0
2 years ago
Other questions:
  • Foods that are high in _________ have the least impact on slowing the body's absorption rate of alcohol.
    5·1 answer
  • Using Word, Maureen is writing an outline of a presentation she plans to give to her company. She will be showing a video during
    12·2 answers
  • On the Picture Tools Layout tab, you can preview results of the numerous styles, borders, effects, and layouts by _______ comman
    7·2 answers
  • In what year were graphical user interfaces (GUIs) pioneered? 1969 1974 1991 2001
    12·2 answers
  • 3.5 Code Practice
    11·2 answers
  • ANSI defines four events that signal the end of a transaction. Of the following events, which is defined by ANSI as being equiva
    14·1 answer
  • You have enabled IPv6 on two of your routers, but on the interfaces you have not assigned IPv6 addresses yet. You are surprised
    10·1 answer
  • Write a function that takes a string like 'one five two' and returns the corresponding integer (in this case, 152). A function j
    11·2 answers
  • Which of the following is true of how the Internet has responded to the increasing number of devices now using the network? a) T
    12·2 answers
  • A record company is using blockchain to manage the ownership of their copyrighted content. The company requires that every time
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!