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
Create a story that depicts the events leading up to a vehicle crash fatality, the crash itself, and the emotional aftermath on
Brilliant_brown [7]

Answer:

About 5 years ago my girlfriend and I were taking a summer camping trip in southern Alberta. I was in the passenger seat trying to find the campground on a map when she drove over the crest of a hill, was blinded by the sun drove into the ditch. It was a seriously steep ditch but we weren't going very fast so all was fine. I looked over at her and laughed before returning my attention to the map, assuming she could safely bring the vehicle back onto the road.

The next thing I knew, the SUV launched onto the pavement and she lost control and we began swerving. I remember feeling the wheels on the driver's side lift off the ground, then the impact as I was slammed into the door and glass exploded into my face. We barrel rolled and we rolled over-front for a seriously long way.

At some point during the chaos I looked over at her to make sure she was "ok", and just as I did so I watched as she was thrown into the ground through her door window and the corner of the roof just above her seat was crushed inward. The way it looked to me was that she had just been crushed between the ground and the roof of the vehicle. I passed out at that point.

When I came to I had somehow already unbuckled myself from my seat and the vehicle was on its roof. I crawled over to her seat and was in absolute shock to see that she was still in one piece. I removed her from her seat and got us out through the windshield before carrying her for about a half a kilometer down the road, still in shock and fueled entirely by adrenaline.

We were found by a driver who had gone past the wreckage and we were eventually taken to a hospital. I broke 3 ribs on my right side and dislocated my right shoulder, she was severely concussed and scraped up but otherwise mostly okay. However she was 7 weeks pregnant at the time and we found out while in hospital that her body had rejected it under the immense and sudden stress.

We are still together and have 3 amazing and beautiful children, but she still holds onto a lot of guilt surrounding the accident and the loss.

Explanation:

4 0
3 years ago
Monero is cryptocurrency that focuses on transparency of ownership. True or false
dangina [55]

Answer:

TRUE

Explanation:

4 0
2 years ago
The second stage of digestion takes place in the small intestine. <br> True Or False?
DedPeter [7]
False. The second stage of digestion happens in the stomach.
8 0
3 years ago
Which feature is used to help identify the appropriate content for particular form fields?
Alika [10]

Answer:

The correct option is;

Content controls

Explanation:

Content controls are customizable controls that can be added to forms, templates and document that enable users to identify or preview the expected data that fills a given form field

Content controls can be in the form of instructional text that give users an idea of the expected format of the content of a given form field, such that the text disappears as soon as the user starts typing in their own text.

6 0
3 years ago
A company is more likely to lose current customers if:
Agata [3.3K]

Answer:

A

Issues can lead reoccuring costomers to not want to come back, resulting in this issue.

4 0
2 years ago
Other questions:
  • Write a program that will ask the user to input a phrase (multiple word sentence), and an integer value. A static function will
    14·1 answer
  • Write a class called (d) Teacher that has just a main method. The main method should construct a GradeBook for a class with two
    7·1 answer
  • How does a layered pattern make use of abstraction and encapsulation?
    10·1 answer
  • Consider the following C++ program in which the statements are in the incorrect order. Rearrange the statements so that itprompt
    6·1 answer
  • Question 2 (5 points)
    12·1 answer
  • Manuel is working on a project in Visual Studio. He wants to keep this program showing on the entire desktop, but he also needs
    13·1 answer
  • Explain three specific &amp; major security threats to internet users. In each case, address whether or not the vulnerabilities
    15·1 answer
  • BitTorrent, a P2P protocol for file distribution, depends on a centralized resource allocation mechanism through which peers are
    8·1 answer
  • What is pollution?
    14·2 answers
  • Help me with this two questions please
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!