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
rusak2 [61]
3 years ago
8

Consider the provided C++ code in the main.cpp file: The function func2 has three parameters of type int, int, and double, say a

, b, and c, respectively. Write the definition of func2 so that its action is as follows: Prompt the user to input two integers and store the numbers in a and b, respectively. If both of the numbers are nonzero: If a >= b, the value assigned to c is a to the power b, that is, aᵇ. If a < b, the value assigned to c is b to the power a, that is, bᵃ. If a is nonzero and b is zero, the value assigned to c is the square root of the absolute value of a. If b is nonzero and a is zero, the value assigned to c is the square root of the absolute value of b. Otherwise, the value assigned to c is 0. The values of a, b, and c are passed back to the calling environment. After completing the definition of the func2 and writing its function prototype, run your program.
Computers and Technology
1 answer:
TEA [102]3 years ago
3 0

Answer:

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. struct data {
  5.    int a;
  6.    int b;
  7.    double c;
  8. };
  9. data func2(){
  10.    
  11.    int a, b;
  12.    double c;
  13.    data d;
  14.    
  15.    cout<<"Input first number: ";
  16.    cin>>a;
  17.    cout<<"Input second number: ";
  18.    cin>>b;
  19.    
  20.    if(a != 0 && b != 0){
  21.        if(a >= b){
  22.            c = pow(a, b);
  23.        }else{
  24.            c = pow(b, a);
  25.        }
  26.    }
  27.    else if(a != 0 && b == 0){
  28.        c = sqrt(abs(a));
  29.    }
  30.    else if(a == 0 && b != 0){
  31.        c = sqrt(abs(b));
  32.    }
  33.    else{
  34.        c = 0;
  35.    }
  36.    
  37.    d.a = a;
  38.    d.b = b;
  39.    d.c = c;
  40.    return d;
  41. }
  42. int main()
  43. {
  44.    data d = func2();
  45.    cout<<d.a<<" "<<d.b<<" "<<d.c<<"\n";
  46.    
  47.    return 0;
  48. }

Explanation:

Since the func2 is expected to return a, b and c and therefore we create a struct data to hold the return values (Line 6 - 10);

Next, we create the func2 that will return a struct data (Line 12).

Declare three required variables, a, b and c (Line 14 -16) and prompt user to input a and b values (Line 18 - 21).

Next, create nested if else condition that fulfill all the condition requirements as stated in the question (Line 23 - 38) and calculate the value a and b and then assign the result to c accordingly. Please note, we use c++ math library methods such as pow, abs and sqrt to get value from calculation that involves power (Line 25, Line 27), absolute (Line 31, Line 34) and square root (Line 31, Line 34).

At last, set the value a, b and c to the struct d and return d as output (Line 43).

You might be interested in
After Daniel performed poorly on a test, his teacher advised him to do some self-reflection to figure out how he could get a bet
Free_Kalibri [48]

Daniel gives more and more time to self-reflection and improves the mistakes he was doing in the last exam.

<h3 /><h3>What is self-refelection?</h3>

Reflecting on oneself is similar to gazing in a mirror and reporting what you see. It is a method of evaluating your work habits, study style, and self. To think about something is the definition of reflection, given simply.

When Daniel didn't do well on an exam, his teacher suggested that he think about his performance to see how he may perform better on the upcoming test.

Examine the material he is familiar with. Consider whether he needs to change his study strategy. Request extra assistance from the instructor outside of class.

Examine the questions he didn't get right and consider why. Self-reflection is the process of assessing one's performance to identify any problem areas that require improvement.

Hence, daniel gives more and more time to self-reflection and improves the mistakes he was doing in the last exam.

To learn more about self-reflection refer;

brainly.com/question/14754364

#SPJ1

5 0
2 years ago
Why is it important to think about the programming language to use?
gogolik [260]

Answer:

"The choice of programming language determines the type of game you can make."

Explanation:

Programming language enables us to write efficient programs and develop online things based on the certain type of code.

5 0
3 years ago
Draw a flowchart or write pseudocode to represent a program's logic that allows the user to enter a value. The program multiplie
PIT_PIT [208]

Ill choose flowchart. Look picture for the answer

ask me if you have any doubts about my answer.

5 0
3 years ago
How would I collect a number from the user to use for the radius of a circle?
exis [7]

Answer:

C is the correct answer to your question

7 0
2 years ago
Which is a good example of kinetic energy
Alexandra [31]

Answer: A. Flying a paper airplane.  

5 0
3 years ago
Read 2 more answers
Other questions:
  • He would like to get rid of the graph. What will accomplish
    8·1 answer
  • When using the “reply all” option, your message will automatically be sent to ____ recipients of the original message. ​?
    7·2 answers
  • In an AND truth table.
    7·1 answer
  • What is a googleplex?
    7·1 answer
  • Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial numb
    12·1 answer
  • How do optical discs store data? select one:
    15·1 answer
  • A _________ is automatically launched by some trigger and appears in front of the active window
    12·1 answer
  • Do you have to make a account of Windows 10?
    12·1 answer
  • Write a program that prompts the user for the name of two files each containing a single line that represents a decimal integerc
    11·1 answer
  • How to create create a database in mysql using clv files
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!