Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1-3 should be submitted in a single Microsoft Word file. Be sure to cle

ID: 3717283 • Letter: Q

Question

Question 1-3 should be submitted in a single Microsoft Word file. Be sure to clearly label your solutions.

Question 1:

Consider the following program:

#include
#include
#include

using namespace std;

int main()

{
int num1;
int num2;

cout << fixed << showpoint << setprecision(2);

cout << "Enter two integers: ";
cin >> num1 >> num2; cout << endl;

if (num1 != 0 && num2 != 0)
cout << sqrt(abs(num1 + num2) + 0.5) << endl;
else if (num1 != 0)
cout << floor(num1 + 0.5) << endl;
else if (num2 != 0)
cout << ceil(num2 + 0.5) << endl;
else
cout << 0 << endl;

return 0;
}

a. What is the output if the input is -23 8?
b. What is the output if the input is 12 32?
c. What is the output if the input is 15 0?
d. What is the output if the input is 0 -36?
e. What is the output if the input is 0 0?

Question 2:

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

Question 3:

Write C++ statements that do the following:

a.Define an enum type, birdType, with the values PEACOCK, SPARROW, CANARY, PARROT, PENGUIN, OSTRICH, EAGLE, CARDINAL, and HUMMINGBIRD.

b. Declare a variable bird of the type birdType.

c. Assign CANARY to the variable bird.

d. Advance bird to the next value in the list.

e. Decrement bird to the previous value in the list.

f. Output the value of the variable bird.

g. Input value in the variable bird.

Explanation / Answer

If you post more than 1 question, as per chegg guidelines I have to solve only first question.

Ques 1.

(a) As both the values are not equal to 0, so the if block is executed.

So,

sqrt(abs(num1 + num2) + 0.5)

sqrt(abs(-23+ 8) + 0.5)

sqrt(abs(-15) + 0.5)

sqrt(15.5)

3.94

As we had to print result upto 2 decimal places.

(b) As both the values are not equal to 0, so the if block is executed.

So,

sqrt(abs(num1 + num2) + 0.5)

sqrt(abs(12+ 32) + 0.5)

sqrt(abs(44) + 0.5)

sqrt(44.5)

6.67

As we had to print result upto 2 decimal places.

(c) As num2 is equal to 0 and num1 is not equal to 0, so the else if( num1 != 0 ) block is executed.

So,

floor(num1 + 0.5)

floor(15+ 0.5)

15.00

As we had to print result upto 2 decimal places.

(d) As num1 is equal to 0 and num2 is not equal to 0, so the else if( num2 != 0 ) block is executed.

So,

ceil(num2 + 0.5)

ceil(-36 + 0.5)

ceil(-35.5)

-35.00

As we had to print result upto 2 decimal places.

(e) As both are 0, so the else block is executed and the uutput is

0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote