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
EastWind
2 months ago
5

2.31 LAB: Simple statistics Part 1 Given 4 integers, output their product and their average, using integer arithmetic. Ex: If th

e input is: 8 10 5 4 the output is: 1600 6 Note: Integer division discards the fraction. Hence the average of 8 10 5 4 is output as 6, not 6.75. Note: The test cases include four very large input values whose product results in overflow. You do not need to do anything special, but just observe that the output does not represent the correct product (in fact, four positive numbers yield a negative output; wow). Submit the above for grading. Your program will fail the last test cases (which is expected), until you complete part 2 below. Part 2 Also output the product and average, using floating-point arithmetic. Output each floating-point value with three digits after the decimal point, which can be achieved as follows: printf("%0.3lf", yourValue); Ex: If the input is 8 10 5 4, the output is: 1600 6 1600.000 6.750

Engineering
2 answers:
iogann1982 [368]2 months ago
5 0

Answer:

Explanation:

Un dato importante: la división entera elimina la parte fraccionaria. Por lo tanto, el promedio de 8, 10, 5 y 4 se presenta como 6, no 6.75.

Observación: Las pruebas incluyen cuatro valores de entrada muy grandes cuyo producto causa desbordamiento. No necesitas hacer nada especial, solo ten en cuenta que la salida no representa el producto correcto (en realidad, el resultado de cuatro números positivos es negativo; sorprendente).

Envía lo anterior para evaluación. Tu programa no pasará las últimas pruebas (eso es normal) hasta que completes la segunda parte a continuación.

Parte 2: Además, se debe calcular e imprimir el producto y promedio usando aritmética de punto flotante.

Presenta cada número de punto flotante con tres dígitos después del punto decimal, lo cual puedes hacer así: System.out.printf("%.3f", tuValor);

Ejemplo: Si la entrada es 8, 10, 5, 4, la salida sería:

import java.util.Scanner;

public class LabProgram {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int num1;

int num2;

int num3;

int num4;

num1 = scnr.nextInt();

num2 = scnr.nextInt();

num3 = scnr.nextInt();

num4 = scnr.nextInt();

double average_arith = (num1 + num2 + num3 + num4) / 4.0;

double product_arith = num1 * num2 * num3 * num4;

int result1 = (int) average_arith;

int result2 = (int) product_arith;

System.out.printf("%d %d\n", result2, result1);

System.out.printf("%.3f %.3f\n", product_arith, average_arith);

}

}

Expected output: 1600.000 6.750

choli [298]2 months ago
4 0

Answer:

Abajo se presenta el código completo con explicaciones detalladas y los resultados de salida.

Código con Explicación Parte-1:

#include <stdio.h>

int main()

{

// Se define un arreglo de cuatro enteros de tipo int para almacenar los datos ingresados por el usuario

int number[4];

// Variables de tipo int para almacenar el resultado del producto y promedio de los números

int prod, avg;

printf("Por favor, ingresa cuatro enteros: ");

// Se obtienen cuatro enteros del usuario; el especificador %d se usa para int

scanf("%d %d %d %d",&number[0],&number[1],&number[2],&number[3]);

// Se calcula el producto de los números multiplicándolos entre sí

prod = number[0] * number[1] * number[2] * number[3];

// Se calcula el promedio dividiendo la suma de los números por el total de números

avg = (number[0] + number[1] + number[2] + number[3]) / 4;

// Se imprime el producto y el promedio de los números

printf("El producto de los cuatro números es = %d\n", prod);

printf("El promedio de los cuatro números es = %d", avg);

return 0;

}

Salida Parte-1:

Por favor, ingresa cuatro enteros: 8 10 5 4

El producto de los cuatro números es = 1600

El promedio de los cuatro números es = 6

Como puedes observar, al usar el tipo int no estamos obteniendo el valor exacto del promedio.

Código con Explicación Parte-2:

#include <stdio.h>

int main()

{

// Aquí simplemente cambiamos el tipo de int a float

float number[4];

float prod, avg;

printf("Por favor, ingresa cuatro enteros: ");

// %f se utiliza para números de punto flotante

scanf("%f %f %f %f",&number[0],&number[1],&number[2],&number[3]);

prod = number[0] * number[1] * number[2] * number[3];

avg = (number[0] + number[1] + number[2] + number[3]) / 4;

// %0.3f se usa para mostrar hasta 3 dígitos decimales

printf("El producto de los cuatro números es = %0.3f\n", prod);

printf("El promedio de los cuatro números es = %0.3f", avg);

return 0;

}

Salida Parte-2:

Por favor, ingresa cuatro enteros: 8 10 5 4

El producto de los cuatro números es = 1600.000

El promedio de los cuatro números es = 6.750

Como puedes notar, al utilizar el tipo float ahora obtenemos el valor exacto del promedio.

You might be interested in
Can a 1½ " conduit, with a total area of 2.04 square inches, be filled with wires that total 0.93 square inches if the maximum f
Kisachek [356]
It is not feasible to install the wires within the conduit. Explanation: The given dimensions show that the total area is 2.04 square inches while the wires occupy 0.93 square inches. The maximum allowable fill for the conduit is 40%. To determine if placement is possible, compute the conduit’s area at 40% which equates to 0.816 square inches, less than the required area of the wires.
4 0
2 months ago
A shopaholic has to buy a pair of jeans , a pair of shoes l,a skirt and a top with budgeted dollar.Given the quantity of each pr
choli [298]

Answer:

you may be struggling to pinpoint the separation between your inquiry and my perspective

0 0
3 months ago
A 50 Hz, four pole turbo-generator rated 100 MVA, 11 kV has an inertia constant of 8.0 MJ/MVA. (a) Find the stored energy in the
Mrrafil [318]

Given Information:

Frequency = f = 60 Hz

Complex rated power = G = 100 MVA

Inertia constant = H = 8 MJ/MVA

Mechanical power = Pmech = 80 MW

Electrical power = Pelec = 50 MW

Number of poles = P = 4

No. of cycles = 10

Required Information:

(a) stored energy =?

(b) rotor acceleration =?

(c) change in torque angle =?

(c) rotor speed =?

Answer:

(a) stored energy = 800 Mj

(b) rotor acceleration = 337.46 elec deg/s²

(c) change in torque angle (in elec deg) = 6.75 elec deg

(c) change in torque angle (in rmp/s) = 28.12 rpm/s

(c) rotor speed = 1505.62 rpm

Explanation:

(a) Calculate the rotor's stored energy at synchronous speed.

The stored energy is represented as

E = G \times H

Where G stands for complex rated power and H signifies the inertia constant of the turbo-generator.

E = 100 \times 8 \\\\E = 800 \: MJ

(b) If we suddenly increase the mechanical input to 80 MW against an electrical load of 50 MW, we shall find the rotor's acceleration while ignoring mechanical and electrical losses.

The formula for rotor acceleration is given by

$ P_a = P_{mech} - P_{elec} = M \frac{d^2 \delta}{dt^2} $

Where M is defined as

$ M = \frac{E}{180 \times f} $

$ M = \frac{800}{180 \times 50} $

M = 0.0889 \: MJ \cdot s/ elec \: \: deg

$ P_a = 80 - 50 = 0.0889 \frac{d^2 \delta}{dt^2} $

$ 30 = 0.0889 \frac{d^2 \delta}{dt^2} $

$ \frac{d^2 \delta}{dt^2} = \frac{30}{0.0889} $

$ \frac{d^2 \delta}{dt^2} = 337.46 \:\: elec \: deg/s^2 $

(c) If the acceleration derived in part (b) persists over 10 cycles, we will calculate both the change in torque angle and the rotor speed in revolutions per minute at the end of this duration.

The change in torque angle is expressed as

$ \Delta \delta = \frac{1}{2} \cdot \frac{d^2 \delta}{dt^2}\cdot (t)^2 $

Where t is determined from

1 \: cycle = 1/f = 1/50 \\\\10 \: cycles = 10/50 = 0.2 \\\\t = 0.2 \: sec

Consequently,

$ \Delta \delta = \frac{1}{2} \cdot 337.46 \cdot (0.2)^2 $

$ \Delta \delta = 6.75 \: elec \: deg

The change in torque in rpm/s is provided by

$ \Delta \delta = \frac{337.46 \cdot 60}{2 \cdot 360\circ } $

$ \Delta \delta =28.12 \: \: rpm/s $

The rotor speed in rpm at the culmination of this 10-cycle period is calculated as

$ Rotor \: speed = \frac{120 \cdot f}{P} + (\Delta \delta)\cdot t $

Where P indicates the number of poles on the turbo-generator.

$ Rotor \: speed = \frac{120 \cdot 50}{4} + (28.12)\cdot 0.2 $

$ Rotor \: speed = 1500 + 5.62 $

$ Rotor \: speed = 1505.62 \:\: rpm

4 0
2 months ago
Write cout statements with stream manipulators that perform the following:
grin007 [323]

Answer:

A)cout<<setw(9)<<fixed<<setprecision(2)<<34.789;

B)cout<<setw(5)<<fixed<<setprecision(3)<<7.0;

C)cout<<fixed<<5.789E12;

D)cout<<left<<setw(7)<<67;

Explanation:

Stream Manipulators are special functions for use with the insertion (<<) and extraction (>>) operators on C++ stream objects, while the 'cout' statement outputs content to the standard output device in C++ programming.

setw: specifies the minimum width of the output field

setprecision: defines the number of decimal places for floating-point value formatting.

fixed: sets the format flag for floating-point streams.

left: left-aligns the output.

A) This statement shows the number 34.789 in a field that provides eight character spaces with two decimal precision. cout<<setw(9)<<fixed<<setprecision(2)<<34.789;

B) Here, the number 7.0 is displayed within six spaces with three decimal precision. cout<<setw(5)<<fixed<<setprecision(3)<<7.0;

C) This command prints 5.789e+12 in fixed-point format.  cout<<fixed<<5.789E12;

D) This statement left-aligns the number 67 across a field of six spaces. cout<<left<<setw(7)<<67;

7 0
2 months ago
The rate of flow of water in a pump installation is 60.6 kg/s. The intake static gage is 1.22 m below the pump centreline and re
mote1985 [299]

Answer:

The power of the pump is 23.09 kW.

Explanation:

Parameters

gravitational constant, g = 9.81 m/s^2

mass flow rate, \dot{m} = 60.6 kg/s

flow density, \rho = 1000 kg/m^3

efficiency of the pump, \eta = 0.74

output gauge pressure, p_o = 344.75 kPa

input gauge pressure, p_i = 68.95 kPa

cross-sectional area of output pipe, A_o = 0.069 m^2

cross-sectional area of input pipe, A_i = 0.093 m^2

height of discharge, z_o = 1.22 m - 0.61 m = 0.61 m (evaluated at pump’s maximum height of 1.22 m)

input height, z_i = 0 m

hydraulic power of the pump,P =? kW

Initially, the volumetric flow (Q) needs to be determined

Q = \frac{\dot{m}}{\rho}

Q = \frac{60.6 kg/s}{1000 kg/m^3}

Q = 0.0606 m^3/s

Next, compute the velocity (v) for both input and output

v_o = \frac{Q}{A_o}

v_o = \frac{0.0606 m^3/s}{0.069 m^2}

v_o = 0.88 m/s

v_i = \frac{Q}{A_i}

v_i = \frac{0.0606 m^3/s}{0.093 m^2}

v_i = 0.65 m/s

Subsequently, the total head (H) can be calculated

H = (z_o - z_i) + \frac{v_o^2 - v_i^2}{2 \, g} + \frac{p_o - p_i}{\rho \, g}

H = (0.61 m - 0 m) + \frac{{0.88 m/s}^2 - {0.65 m/s}^2}{2 \, 9.81 m/s^2} + \frac{(344.75 Pa-68.95 Pa)\times 10^3}{1000 kg/m^3 \, 9.81 m/s^2}

H = 28.74m

Finally, the computation of pump power is done as follows

P = \frac{Q \, \rho \, g \, H}{\eta}

P = \frac{0.0606 m^3/s \, 1000 kg/m^3 \, 9.81 m/s^2 \, 28.74m}{0.74}

P = 23.09 kW

6 0
2 months ago
Other questions:
  • A sign erected on uneven ground is guyed by cables EF and EG. If the force exerted by cable EF at E is 46 lb, determine the mome
    13·1 answer
  • Given num_rows and num_cols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    14·1 answer
  • Given two input integers for an arrowhead and arrow body, print a right-facing arrow. Ex: If the input is 0 1, the output is
    8·1 answer
  • All MOS devices are subject to damage from:________
    7·1 answer
  • Consider a process carried out on 1.00 mol of a monatomic ideal gas by the following two different pathways.
    13·1 answer
  • Radioactive wastes are temporarily stored in a spherical container, the center of which is buried a distance of 10 m below the e
    13·1 answer
  • NEEDS TO BE IN PYTHON:ISBN-13 is a new standard for indentifying books. It uses 13 digits d1d2d3d4d5d6d7d8d910d11d12d13 . The la
    15·1 answer
  • A cylinder with a 6.0 in. diameter and 12.0 in. length is put under a compres-sive load of 150 kips. The modulus of elasticity f
    5·1 answer
  • A 3-phase, 50 Hz, 110 KV overhead line has conductors placed in a horizontal plane 3 m apart. Conductor diameter is 2.5 cm. If t
    6·1 answer
  • An electric field is expressed in rectangular coordinates by E = 6x2ax + 6y ay +4az V/m.Find:a) VMN if point M and N are specifi
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!