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]
2 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]2 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
Write a program that reads numbers from the user until a blank line is entered. Your
ddd [48]

Answer:

nums = []

while True:

   in = input()

   if in:

       nums.append(in)

   else:

       break

if nums:

   avg = sum(nums) / len(nums)

   for i in range(len(nums)):

       if nums[i] == avg:

           print(f"index: {i+1}")

           print(nums[i])

else:

   print(-1)  # if there aren't any values in nums

Explanation:

Assuming that you are coding in Python 3x. The last 'else' statement is an edge case that you might want to consider, I don't know what you want to put there, but I'm just going to leave it as -1.

5 0
2 years ago
Convert 4.5 strides to girth
n200080 [17]

There are 0.5 strides in one girth
so 4.5 strides will be equal to 9 girth
hope it helps
3 0
3 years ago
When is a wired connection preferred to a wireless connection by an end-user device?
harkovskaia [24]

Answer:

Option (b) When the end-user device will run an application that requires a dedicated connection to the network

Explanation:

  • Option (b) is the correct option.
  • When the user device requires a highly dedicated network environment to itself to run a web application that requires large download and upload speeds, bandwidth requirements then it prefers a wired connection than a wireless connection.
  • If the wireless signal is within the reach, then it advisable to go for a wireless connection than a wired connection. A wired connection requires other hardware equipments like a internet connection cable etc. which is not required in case of wireless connection. So, option (a) is wrong option.
  • WLAN NIC is a wireless interface network controller that connects to a wireless radio based network than a wired network.So, option (c) is wrong option.
  • Delay torrent network is designed to operate where continuous network connectivity is not available like extreme terrestrial spaces, space communications, inter planetary communications etc.So, option (d) is wrong option.
6 0
2 years ago
What is the name of the fifth Sims 3 expansion pack
olga2289 [7]
2 were released as part 5 for the Sims 3 Expansion Pack Series. These two packs were the Pets Expansion and the Master Suite pack which added buyable and ownable pets and hotels.
8 0
2 years ago
I WILL STAR YOU AND THANKS YOU!!!!!!!!!!!!!!!!
lord [1]
The answer seems to be polymerization.
 
8 0
3 years ago
Other questions:
  • Which social media marketing concept engages visitors, getting them to revisit your website and tying them to offline events for
    7·2 answers
  • A(n) ____________________ defines the number and type of daemons that are loaded into memory and executed by the kernel on a par
    12·1 answer
  • Why do so many people think the revision stage is the hardest
    13·2 answers
  • Trish has bought a new computer that she plans to start working on after a week. Since Trish has not used computers in the past,
    10·1 answer
  • What is the most common example of a magnetic storage medium in a personal computer
    5·1 answer
  • Good business ethics is a good marketing strategy. Discuss
    13·1 answer
  • Which task can a company perform with intranets
    8·1 answer
  • Will give brainliest
    10·1 answer
  • What happens if a computer lags too much?
    14·2 answers
  • How to change the microsoft word pages to black background
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!