Write exactly these 3 functions: power(x,y), print(text, number) function and the main() function. The power(x,y) function returns an integer result that is calculated by raising a number x (integer) to a power y (integer). The second argument y (exponent) of the function can not exceed 100. If the second argument exceeds 100, the function should return -1. Your power(x,y) function must be able to take either 1 or 2 integer arguments using the concept of default argument in chapter 6. Look at the main() code to deduct what the default value should be. You should call C++ pow(x,y) function in the "cmath" library in the body of your power(x,y) function to avoid doing the power calculation yourself. The print(text, number) function is the only one that does output to the console using "cout". Other functions should not use "cout". This function does not return anything. Write the 2 function prototypes above main() and write the full function definitions after main().

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

Topic: Function with default argument value covered in Chapter 6 

Write a C++

Do not use any topic not covered in lecture. There is no need for use of loop, and needs the use of only an "if/else" statement.

Write exactly these 3 functions: power(x,y), print(text, number) function and the main() function. 
The power(x,y) function returns an integer result that is calculated by raising a number x (integer) to a power y (integer). The second argument y (exponent) of the function can not exceed 100.
If the second argument exceeds 100, the function should return -1.

Your power(x,y) function must be able to take either 1 or 2 integer arguments using the concept of default argument in chapter 6. Look at the main() code to deduct what the default value should be.

You should call C++ pow(x,y) function in the "cmath" library in the body of your power(x,y) function to avoid doing the power calculation yourself.

The print(text, number) function is the only one that does output to the console using "cout". Other functions should not use "cout". This function does not return anything.

Write the 2 function prototypes above main() and write the full function definitions after main().

Use the following given main() code without any change. 
 
/* Your code description
………
*/
// Function Prototypes go  here before main
// ……….

 
// Two Function definitions go  here after main
// ……………...

Use my main code exactly AS IS.

int main()
{
    // Variable declaration
    int x = 3;

    // Driver statements
    x = power(x, 3);
    print("Value of x after step 1 is ", x);
    x = power(x, 2);
    print("Value of x after step 2 is ", x);
    x = power(x);
    print("Value of x after step 3 is ", x);
    x = power(x, 101);
    print("Value of x after step 4 is ", x);
    x = power(3, -5);
    print("Value of x after step 5 is ", x);
    x = 10;
    x = power(x);
    print("Value of x after step 6 is ", x);

    return 0;
}

Program output must look exactly like this using my given main code:

#include <iostream>
#include <cmath>
using namespace std;
int main()
int x = 3;
ха рower (x, 3);
print ("Value of x after step 1 is ", x);
x = power (x, 2);
print ("Value of x after step 2 is ", x);
X = power (x);
print ("Value of x after step 3 is ", x);
хв роwer (x, 101)%;
print("Value of x after step 4 is ", x);
х%3D рower (3, -5);
print ("Value of x after step 5 is ", x);
* 10;
x = power (x);
print("Value of x after step 6 is ", x);
vazde
return 0;
Program output must look
exactly like this using my
given main code:
Value of x after step 1 is 27
Value of x after step 2 is 729
Value of x after step 3 is 729
Value of x after step 4 is -1
Value of x after step 5 is 0
Value of x after step 6 is 10
Transcribed Image Text:#include <iostream> #include <cmath> using namespace std; int main() int x = 3; ха рower (x, 3); print ("Value of x after step 1 is ", x); x = power (x, 2); print ("Value of x after step 2 is ", x); X = power (x); print ("Value of x after step 3 is ", x); хв роwer (x, 101)%; print("Value of x after step 4 is ", x); х%3D рower (3, -5); print ("Value of x after step 5 is ", x); * 10; x = power (x); print("Value of x after step 6 is ", x); vazde return 0; Program output must look exactly like this using my given main code: Value of x after step 1 is 27 Value of x after step 2 is 729 Value of x after step 3 is 729 Value of x after step 4 is -1 Value of x after step 5 is 0 Value of x after step 6 is 10
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning