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
A new computer workstation has been installed in a small office. the user of the workstation can print a document using a networ
ICE Princess25 [194]
The printer is setup as a local printer therefore it does not need access to internet to access the local network printer. Once the new workstation is given access to the terminal server used for the printer, it will not need to connect on the internet to print. Now, if the workstation is not able to access the internet it could be potentially due to incorrect configuration of DNS to the workstation or actual issue is within the ISP.
3 0
2 years ago
When I click on someone who asked a question and i want to see there answer it is always blurred and when I asked a question I c
yuradex [85]

Answer:

If your on pc like me use ad blocker I do that but otherwise watch the add press ok after if it dosemt work tell me I’ll try and find you it and for ad blocker you also can have a jailbreak divice and to get and blocker go to chrome extension website search up pop up ad blocker

Explanation:

7 0
3 years ago
9.10: Reverse ArrayWrite a function that accepts an int array and the array ’s size as arguments . The function should create a
AleksandrR [38]

Answer:

#include <iostream>

using namespace std;

int * reverse(int a[],int n)//function to reverse the array.

{

   int i;

   for(i=0;i<n/2;i++)

   {

       int temp=a[i];

       a[i]=a[n-i-1];

       a[n-i-1]=temp;

   }

   return a;//return pointer to the array.

}

int main() {

   int array[50],* arr,N;//declaring three variables.

   cin>>N;//taking input of size..

   if(N>50||N<0)//if size greater than 50 or less than 0 then terminating the program..

   return 0;

   for(int i=0;i<N;i++)

   {

       cin>>array[i];//prompting array elements..

   }

   arr=reverse(array,N);//function call.

   for(int i=0;i<N;i++)

   cout<<arr[i]<<endl;//printing reversed array..

   cout<<endl;

return 0;

}

Output:-

5

4 5 6 7 8

8

7

6

5

4

Explanation:

I have created a function reverse which reverses the array and returns pointer to an array.I have also considered edge cases where the function terminates if the value of the N(size) is greater than 50 or less than 0.

8 0
3 years ago
Which of these words does not describe factual data
kipiarov [429]
The correct answer is "opinion".

<span>Opinions are almost never factual which is why they are opinions. </span>
5 0
3 years ago
Read 2 more answers
What scientific principle would a plumber need to know when designing and installing plumbing a new construction
Volgvan
Diong reasearch to know what your dion
7 0
3 years ago
Other questions:
  • CAD helps professionals to _____. create a technical drawing give directions to a new location calculate the interest rate of a
    13·2 answers
  • A _____________ is a method of controlled entry into a facility and provides access to secure areas such as a research lab or da
    10·1 answer
  • Traceability of requirements is helpful in the followingexcept
    5·1 answer
  • Which of the following is not an Operating System? Select one:
    13·1 answer
  • Write a Java program to count the characters in each word in a given sentence?Examples:Input : geeks for geeksOutput :geeks-&gt;
    10·1 answer
  • How do you delete answers on Brain.ly?
    11·2 answers
  • Research for a project should be based on?
    7·2 answers
  • What are some examples and non-examples of digital security?
    6·1 answer
  • Aranjează următoarele cuvinte din documentul word Proiect, într-o scrisoare în care soliciți directorului școlii sprijin în priv
    8·1 answer
  • You have been elected to assist the school's yearbook committee and newspaper club in purchasing new computers. The current comp
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!