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
Which domain suffixes do businesses that sell products and services commonly use?
sineoko [7]
I’m having a hard time understanding your question
8 0
4 years ago
Read 2 more answers
select all examples of proper keyboarding technique. rest your fingers gently on the home row or home keys. slouch in your chair
padilas [110]

Rest your fingers gently on the home row or home keys.

Rest your palms on the keyboard.

Relax your fingers.

All the above are proper keyboard techniques apart from slouch in your chair. It is always recommended to sit up straight with your feet positioned on the floor for balance. Do not cross. Center your body to the H key and have your elbows at sides and bent about 90 degrees. Use correct fingering and deploy touch typing. These and many others will help develop optimal speed and accuracy and help prevent the development of stress injury.

6 0
3 years ago
Read 2 more answers
When you use a while loop to compute the product of several values, you should initialize the variables holding the product to _
Allushta [10]

Answer:

b.1

Explanation:

When we are using while loop to compute the product of several values we need to initialize the value holding the product to 1 because when we multiply something with 1 it will give the same number.

If we initialize it with 0 the product will come out to be 0 because  anything multiplied by 0 is 0.

we cannot initialize it with NULL because it is not a pointer.

We need to initialize the number since it contains garbage values so it will give product with that value.

3 0
3 years ago
Which of the following statements correctly instantiate the Rectangle object myRectangle? (i) myRectangle Rectangle = new Rectan
madreJ [45]

Answer:

The answer is "option iii"  .

Explanation:

In the given question it is defined that a class "Rectangle" is defined in the class a parameter constructor is created that accepts two parameters. In this question, we create an instance of the class. In object creation first, we define class name then object name and use new keyword in the Instance of class and pass parameters.

  • In option i), An object name is used first and then class name. It is not correct.
  • In option ii), In instance creation of the class, we do not use class keyword that's why it is wrong.

5 0
4 years ago
Read 2 more answers
The Review feature automatically adjusts to select the edited information.<br> true of false
NNADVOKAT [17]
True I hope this helps
8 0
3 years ago
Read 2 more answers
Other questions:
  • If the value of the expression,
    13·1 answer
  • And computers are the most commonly seen microcomputers.
    10·1 answer
  • Create a view named ItemOrder view. It consists of the TaskID, description, price, order number, order date, and quoted price fo
    8·1 answer
  • Write a C++ program that reads from the standard input and counts the number of times each word is seen. A word is a number of n
    9·1 answer
  • python Write a program that will take a file named Celsius.dat that contains a list of temperatures in Celsius (one per line), a
    9·1 answer
  • Consider the following class declaration.
    6·1 answer
  • Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN Java.
    11·1 answer
  • What a promblem Hypothesis<br>​
    8·2 answers
  • Drag the tiles to the correct boxes to complete the pairs.
    15·2 answers
  • A gui allows you to interact with objects on the screen such as icons and buttons true or false
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!