Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Show the output of the following program: #include using namespace std; int mystery(int); int main() { int n; for (n = 1; n

1. Show the output of the following program: #include using namespace std; int mystery(int); int main()

{ int n; for (n = 1; n <= 5; n++) cout << mystery(n) << endl;

return 0;

} int mystery(int k)

{ int x, y; y = k; for (x = 1; x <= (k - 1); x++) y = y * (k - x);

return y;

}

2. Consider the following function prototypes:

int test(int, char, double, int);

double two(double, double);

char three(int, int, char, double);

Answer the following questions.

a. How many parameters does the function test have? What is the type of the function test ?

b. How many parameters does function two have? What is the type of function two?

c. How many parameters does function three have? What is the type of function three?

d. How many actual parameters are needed to call the function test?

e. What is the type of each actual parameter, and in what order should you use these parameters in a call to the function test?

f. Write a C++ statement that prints the value returned by the function test with the actual parameters 5, 5, 7.3, and 'z'.

3. Write the definition of a function that takes as input three numbers and returns the sum of the first two numbers multiplied by the third number. (Assume that the three numbers are of type double.)

4. Write the definition of a function that takes as input the three numbers. The function returns true if the first number to the power of the second number equals the third number; otherwise, it returns false. (Assume that the three numbers are of type double.)

5. What is the error in following function definitions?

a. void total(int value1, value2, value3)

{ return value1 + value2 + value3;

}

b. double average(int value1, int value2, int value3)

{ double average;

average = value1 + value2 + value3 / 3;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

1. define what goals are and identify major types of goals,

Answered: 1 week ago

Question

Answered: 1 week ago

Answered: 1 week ago