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
Ulleksa [173]
4 years ago
10

Write a function MaxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the function in

a program that takes two integer inputs, and outputs the largest magnitude value. Ex: If the inputs are: 5 7 the function returns: 7 Ex: If the inputs are: -8 -2 the function returns: -8 Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the absolute-value built-in math function. Your program must define and call a function: int MaxMagnitude(int userVal1, int userVal2)
Engineering
1 answer:
Svetradugi [14.3K]4 years ago
3 0

Answer:

The function requires evaluate the largest magnitude (the largest value withou sign), so we need to compare the absolute value of the two inputs number. For that we use the abs() function.

The code is as follows, with the comments after // and in italic font:

#include <iostream>   <em>//module for input/output stream objects</em>

#include <cmath>  <em>//math module </em>

using namespace std;

<em>// follows the function definition  </em>

int MaxMagnitude (int userVal1, int userVal2) {

 int Max=0;    <em>//define output variable Max</em>

 if (abs(userVal1) > abs(userVal2)) {  <em>// compare magnitude </em>

   Max = userVal1;  <em> //if Val1 is larger than val2 Max is Val1</em>

 }

 else {

   Max = userVal2;  <em>//else the max is Val 2 </em>

 }

 return Max;  <em>//the value returned for this function</em>

 }

// <em>in main we will use the defined function MaxMagnitude</em>

int main() {

  int one = 0;

 int two = 0;

 cin >> one;  //assignation of the first user input to one  

 cin >> two;   //assignation of the second user input to two  

//we call the function using as input the read values

//and write the return of the function, all at once  

  cout << MaxMagnitude(one, two) << endl;  

  return 0;

}

You might be interested in
An extruder barrel has a diameter of 4.22 inches and a length of 75 inches. The screw rotates at 65 revolutions per minute. The
Vlada [557]

Answer:

volume flow rate Q  = 53.23 in³/s

Explanation:

given data

diameter = 4.22 inches

length = 75 inches

screw rotates = 65 revolutions per minute

depth = 0.23 in

flight angle = 21.4 degrees

head pressure = 705 lb/in²

viscosity = 145 x 10^{-4} lb·sec/in²

solution

we get here volume flow rate of platstic in barrel that is express as

volume flow rate Q = volume flow rate of die - volume flow of extruder barrel   ................1

here

volume flow rate extruder barrel is

flow rate   = \frac{\pi \times 705 \times 4.22 \times 0.23\times sin21.4 }{12\times 145 \times 10^{-4}\times 75 }    

flow rate = 60.10  

and

volume flow rate of die is express as

volume flow rate = 0.5 × π² × D² × Ndc ×  sinA × cosA   .............2

put here value and w eget

volume flow rate = 0.5 × π² × 4.22² × 0.23 × 1 × sin21.4 × cos21.4

volume flow rate = 6.866

so put value in equation 1 we get

volume flow rate Q  = 60.10 - 6.866  

volume flow rate Q  = 53.23

7 0
3 years ago
Are we living in a simulation! <br> True <br> False
olchik [2.2K]
False

i would hope:):):)
4 0
3 years ago
Read 2 more answers
What is the mechanical advantage of a simple block and tackle with one rope?
NISA [10]

Answer:

A block and tackle is characterized by the use of a single continuous rope to transmit a tension force around one or more pulleys to lift or move a load. Its mechanical advantage is the number of parts of the rope that act on the load. The mechanical advantage of a tackle dictates how much easier it is to haul or lift the load.

Explanation:

Hope this helps- have a good day ^w

6 0
3 years ago
Read 2 more answers
Which of the following actions by farmers contributes to desertification?
madreJ [45]

The answer to the question should be abandoning overused farmland without replenishment. when you dont use the land, it turns very dry

4 0
3 years ago
A museum has three rooms, each with a motion sensor (m0, m1, and m2) that outputs 1 when motion is detected. At night, the only
nordsb [41]

Answer:

a) see attachment

b) A= m0m1+ m1m2+ m0m2

see attachment for K-map

c) see attachment

Explanation:

a) see attachment for truth table

b) see attachment for k-map

A= m0m1+ m1m2+ m0m2

c) see attachment for gate level circuit

4 0
3 years ago
Other questions:
  • The term motion refers to a change in position with respect to a. a specific reference b. the ground c. the center of the Earth
    14·1 answer
  • Which of the following is not true about Machine Learning?Machine Learning was inspired by the learning process of human beings.
    11·1 answer
  • What is the thermal efficiency of a gas power cycle using thermal energy reservoirs at 627°C and 60°C? The thermal efficiency is
    12·1 answer
  • Problem 5.024 A power cycle receives 1000 Btu by heat transfer from a reservoir at 1500°F and discharges energy by heat transfer
    13·1 answer
  • Given in the following v(t) signal.
    14·1 answer
  • 5. After a long period of pumping from an unconfined aquifer at a constant rate of 850 m3/day, the cone of depression reaches eq
    11·1 answer
  • What is the optimal temperature for recharging a battery?
    14·1 answer
  • 1. Static holding is when you hold the same posture for long periods of time.
    11·1 answer
  • PLEASE FIX THIS LUA SCRIPT
    12·2 answers
  • 1 . How are encoders used in the measurement of speed? Explain the encoder with a neat diagram.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!