Function with default argument value

User Generated

zzzzzaaaaa

Programming

Description

Create the CPP file Lab8A-XXXXX.cpp where XXXXX are the last 5 digits of your ID.

Write exactly two functions, a power(x,y) function and a print(text, number) function. The power(x,y) function returns an integer result that is calculated by raising a number x (integer) to a power y (integer).

it is a short lab. details in docx

Unformatted Attachment Preview

Lab A Topic: Function with default argument value. Create the CPP file Lab8A-XXXXX.cpp where XXXXX are the last 5 digits of your ID. Write exactly two functions, a power(x,y) function and a print(text, number) 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 default argument. Look at the main() code to infer what the default value should be. You can use any function in the "cmath" library in your code. The print(text, number) function is the only one that does output to the console. Write the function prototypes above main() and write the full function definitions after main(). Use this given main() code without change: // Function Prototypes go here ………... // int main() { int x = 3; 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; } // Function definitions go here ………... Program Output: 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 May I have your email address If yes, please attach in code, thank you
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

here you go. I put so...


Anonymous
Really helped me to better understand my coursework. Super recommended.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags