Question

In: Computer Science

please use text only! Instructions Consider the provided C++ code in the main.cpp file: The function...

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:

  • 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.

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

Solutions

Expert Solution

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;
   }

}


Related Solutions

TEXT ONLY PLEASE ( PLEASE NO PDF OR WRITING) C++ CODE Instructions In a right triangle,...
TEXT ONLY PLEASE ( PLEASE NO PDF OR WRITING) C++ CODE Instructions In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle. If the triangle is a right triangle, output It is...
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Instructions Write a program that implements...
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Instructions Write a program that implements the algorithm given in Example 1 - 3 (Chapter 1), which determines the monthly wages of a salesperson. The instructions for Example 1 - 3have been posted below for your convenience. Example 1 - 3 Every salesperson has a base salary. The salesperson also receives a bonus at the end of each month, based on the following criteria: If the salesperson has been with...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language A Game store sells many types of gaming consoles. The console brands are Xbox, Nintendo, PlayStation. A console can have either 16 or 8 gigabytes of memory. Use can choose the shipping method as either Regular (Cost it $5) or Expedite (Cost is $10) The price list is given as follows: Memory size/Brand Xbox Nintendo PlayStation 16 gigabytes 499.99 469.99 409.99 8 gigabytes 419.99...
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
HW_6b - Read and write a text file. Include the following in the main.cpp file. Add...
HW_6b - Read and write a text file. Include the following in the main.cpp file. Add code so that the numbers that are read from the data.txt file are written to an output           file named:   results.txt After the numbers are written to the file, the following message should be displayed:    The data has been written to the file. Open the results.txt file and verify that the file was written successfully. Please make the code based on C++,...
Translate the C function code below to the MIPS True Assembler Language code (machine instructions only)....
Translate the C function code below to the MIPS True Assembler Language code (machine instructions only). The function code should follow the conventions for MIPS function calls including passing parameters and returning results. Your function code must be written with the minimum number of machine instructions to be executed and without any use of MIPS pseudo-instructions. Myfunction(unsigned int a, unsigned int b, unsigned int c) { int i=0; while (a > c) { a /= b; i++; } return i;...
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Summary Samantha and Vikas are looking...
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Summary Samantha and Vikas are looking to buy a house in a new development. After looking at various models, the three models they like are colonial, split-entry, and single-story. The builder gave them the base price and the finished area in square feet of the three models. They want to know the model(s) with the least price per square foot. Instructions Write a program that accepts as input the base...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list functionality. The functions header file is also given. Complete the functions of the header file linked_list.h below. ========================================================= // listmain.cpp #include "Linked_List.h" int main(int argc, char **argv) {      float           f;      Linked_List *theList;      cout << "Simple List Demonstration\n";      cout << "(List implemented as an Array - Do...
C language only please and please make a simple code Write a function that will find...
C language only please and please make a simple code Write a function that will find whether there exist two integers that sum to the target integer. The function is to “return” three values.First, return “1” if the integers were found,return “-1” if your search was not successful.If you find two integers which add up to the target value, you should return their respective index position inside the array. Suggested prototype:int TwoSumFunction(int arr[], int size, int target, int*index1, int* index2);Inside...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT