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().

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education