In: Computer Science
please use text only!
Instructions
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:
Provided code
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void func1();
void func2(/*formal parameters*/);
int main()
{
int num1, num2;
double num3;
int choice;
cout << fixed << showpoint <<
setprecision(2);
do
{
func1();
cin >> choice;
cout << endl;
if (choice == 1)
{
func2(num1, num2, num3);
cout << num1 << ", " << num2 << ", "
<< num3 << endl;
}
}
while (choice != 99);
return 0;
}
void func1()
{
cout << "To run the program, enter 1." << endl;
cout << "To exit the pogram, enter 99." << endl;
cout << "Enter 1 or 99: ";
}
void func2(/*formal parameters*/)
{
//Write the body of func2.
}
TEST CASES
Input
1 2 9 99
Output
81
TEST CASE 2
Input
1 5 8 99
Output
32768
Please find the code below:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void func1();
void func2(int a,int b,double &c);
int main()
{
int num1, num2;
double num3;
int choice;
cout << fixed << showpoint <<
setprecision(2);
do
{
func1();
cin >> choice;
cout << endl;
if (choice == 1)
{
cin>>num1>>num2;
func2(num1,
num2, num3);
cout <<
num1 << ", " << num2 << ", " << num3
<< endl;
}
}
while (choice != 99);
return 0;
}
void func1()
{
cout << "To run the program, enter 1." <<
endl;
cout << "To exit the pogram, enter 99." <<
endl;
cout << "Enter 1 or 99: ";
}
void func2(int a,int b,double &c)
{
if(b==0 && a!=0){
c = sqrt(abs(a));
}else if(a==0 && b!=0){
c = sqrt(abs(b));
}else if(a>=b){
c = pow(a,b);
}else if(a<b){
c = pow(b,a);
}else{
c=0;
}
}