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]
3 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]3 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
In Florida the fine for going over 5 mph in a school zone results in a fine of how much
VMariaS [17]

Answer:

1 to 9 mph over the limit: $50 (no warnings issued) 10 to 14 mph over: $200. 15 to 19 mph over: $300

Explanation:

6 0
3 years ago
Read 2 more answers
The reading on a mercury manometer at 70(°F) (open to the atmosphere at one end) is 25. 62(in). The local acceleration of gravit
Ilya [14]

The absolute pressure in psia being measured is; 27.228 psia

<h3>What is the absolute Pressure?</h3>

Formula for absolute Pressure is;

Absolute pressure = Atmospheric pressure + Gauge pressure

P_{abs} = P_{atm} + P_g

We are given;

P_atm = 29.86 (in Hg) = 14.666 psia

Density of mercury at 70 °F; ρ = 13.543 g/cm³

Mercury Manometer reading; h = 25.62 in

Acceleration due to gravity; g = 32.243 ft/s²

Gauge pressure of the mercury = ρgh = 13.543 * 25.62 * 32.243

When we multiply and covert to psia gives; P_g = 12.562 psia

Thus;

P_abs = 14.666 + 12.562

P_abs = 27.228 psia

Read more about Absolute Pressure at; brainly.com/question/17200230

7 0
2 years ago
Hello, how are you? ​
Kisachek [45]

Answer:

Hello, I'm good. Thank you for asking

8 0
2 years ago
Read 2 more answers
대한민국의 주권은 국민에게 있고. 예비비의 지출은 차기국회의 승인을 얻어야 한다, 대통령은 국가의 안위에 관계되는 중대한 교전상태에 있어서 국가를 보위하기 위하여 긴급한 조치가 필요하고 국회의 집회가 불가능한 때에 한하여 법률의
mote1985 [20]

qué qué qué qué qué qué qué

8 0
3 years ago
Exercise 5.46 computes the standard deviation of numbers. This exercise uses a different but equivalent formula to compute the s
ruslelena [56]

Answer:

// This program is written in Java Programming Language

// Comments are used for explanatory purpose

// Program starts here

import java.util.Scanner;

public class STDeviation {

// Declare and Initialise size of Numbers to be 10

int Numsize = 10;

public static void main(String args [] ) {

Scanner scnr = new Scanner(System.in);

// Declare digits as double

double[] digits = new double[Numsize];

System.out.print("Enter " + Numsize + " digits: ");

// Input digits using iteration

for (int i = 0; i < digits.length; i++)

{

digits[i] = scnr.nextDouble();

}

// Calculate and Print Mean/Average

System.out.print("Average: " + mean(digits)+'\n');

// Calculate and Print Standard Deviation

System.out.println("Standard Deviation: " + deviation(digits));

}

// Standard Deviation Module

public static double deviation(double[] x) {

double mean = mean(x);

// Declare and Initialise deviation to 0

double deviation = 0;

// Calculate deviation

for (int i = 0; i < x.length; i++) {

deviation += Math.pow(x[i] - mean, 2);

}

// Calculate length

int len = x.length - 1;

return Math.sqrt(deviation / len);

}

// Mean Module

public static double mean(double[] x) {

// Declare and Initialise total to 0

double total = 0;

// Calculate total

for (int i = 0; i < x.length; i++) {

total += x[i];

}

// Calculate length

int len = x.length;

// Mean = total/length

return total / len;

}

}

4 0
3 years ago
Other questions:
  • Consider the following fragment of code in an authentication program:
    9·1 answer
  • Assume we have already defined a variable of type String called password with the following line of code: password' can have any
    10·1 answer
  • Baleykdoyle ANSWRER THISSSS NOWWWW FAST
    5·2 answers
  • 3. Write down the total thermal resistance for a double-pipe heat exchanger. Show how to convert from total resistance to an ove
    12·2 answers
  • Which factor is typically not a requisite feature of setting a career goal?
    15·1 answer
  • Complete swap_bits function which swaps bits at odd and even positions of an integer (32 bits). In other words, every even posit
    15·1 answer
  • The volume of a right circular cone of radius r and height h is V = 1 3 πr 2h (a) (i) Find a formula for the instantaneous rate
    8·1 answer
  • An electron is traveling with initial kinetic energy K in a uniform electric field. The electron comes to rest momentarily after
    12·1 answer
  • Henry is given a task to divide a segment into six equal parts, using a triangle and a compass. How many arcs would he need to c
    10·1 answer
  • When adding two 8 bit binary numbers, which of the following statements is true?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!