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

Assume a program contains a void function named calcNewPrice(). The function rec

ID: 664682 • Letter: A

Question

Assume a program contains a void function named calcNewPrice(). The function receives two double variables named oldPrice and newPrice. The function multiplies the contents of the oldPrice variable by 1.1, then stores the result in the newPrice variable. Which of the following can be used to call the calcNewPrice() function?

a) calcNewPrice(double oldPrice, double newPrice);

calcNewPrice(&oldPrice, newPrice);

calcNewPrice(oldPrice, &newPrice);

calcNewPrice(oldPrice, newPrice);

a) calcNewPrice(double oldPrice, double newPrice);

b)

calcNewPrice(&oldPrice, newPrice);

c)

calcNewPrice(oldPrice, &newPrice);

d)

calcNewPrice(oldPrice, newPrice);

Explanation / Answer

The corection option is C) calcNewPrice(oldPrice, &newPrice);

Explanation for correct option:
The method calcNewPrice that takes two arguments

argumet one : oldPrice , an double value that takes the copy of the variable value.
argument two :&newPrice, it takes the address of the variable.

when the method called , the oldPrice value is multiplied by 1.1 then it stores the
result in the variable , newPrice

Function calcNewPrice is may be as following method defition

void calcNewPrice(double oldPrice, double &newPrice)
{
   /*multiply the oldPrice by 1.1 and store the result in the newPrice which can be accessed outside of the method */
   newPrice=1.1*oldPrice;
}

The value in newPrice is updated in the calling function.
To get the resultant value of newPrice after multiplying the oldPrice by 1.1, newPrice is pass by reference so that the value inside the function can be accessed outside of the function.

------------------------------------------------------------------------------------------------------------------------
Explanations for incorrect options:
a)
The method calling calcNewPrice(double oldPrice, double newPrice);
is not the correct way of calling method.
Declaration of variables must be before the method calling.
Calling methods will not contains data types at the time of calling. Hence it is incorrect option.

------------------------------------------------------------------------------------------------------------------------

b)
The method calcNewPrice(&oldPrice, newPrice); is incorrect option.
Because , the first argument is pass by reference value. But after updating
the value user needs newPrice not old value. So it is incorrect option.

------------------------------------------------------------------------------------------------------------------------

d)
The method calcNewPrice(oldPrice, newPrice); is incorrect option.
Both arguments are call by value parameters. After the oldPrice is multiplied
by 1.1 and stored in the newPrice will not be effected outside of the function.
User canot access the values of newPrice outside of the function.
Hence d) is incorrect option.


Hope this helps you

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