QuestionQuestion

1. Describe the difference between a function’s parameter that is passed by value, compared to a parameter that is passed by reference.

2. Below are two functions which attempt to set the passed in variable to PI such that variable passed from the calling function will also be set to PI. Which function will execute correctly, and why?

Method 1
void setToPi(float var) {
var = 3.14;
}

Method 2
void setToPi(float &var) {
var = 3.14;
}

3. Prototype the functions below based on the description provided (You do not need to define the function). Remember, only pass a parameter by reference if it is intended to be set within the function.

a) Swap name function which accepts two strings, name1, name2 as an input and swaps the contents of the strings inside the function.
b) A multiplication function which accepts 3 float inputs, x, y, z and returns back the result of the multiplication of x, y, and z.
c) A change function which accepts a dollar amount which calculates and returns back the equivalent value in the denominations of singles, fives, tens, and twenties.
d) A function which takes a Date object and returns back a day, month and year as integers.

4. (Upload as Source) Implement a user defined function which accepts Cartesian coordinates x, and y and returns back the equivalent coordinates in polar r and φ. This is a multiple return function and should use pass by reference. There should be no cout/cin in the user defined function.

r= √(x²+y² )
φ=tan⁻¹⁡(y/x)

5. (Upload as Source) Modify the Date class program you solved question 6 to be in multiple source files.
a) Place the class definition in a date.h header file
b) Add header guards to the header file
c) Place the member function definitions in a date.cpp file
d) Modify the main.cpp file to include the proper header files. Then call and test your Date class within the main function.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

1. Describe the difference between a function’s parameter that is passed by value, compared to a parameter that is passed by reference.
The biggest difference between a function’s parameter that is passed by value, and a parameter that is passed by reference is that we can change the value of parameter that is passed by reference and that change will be maintain when we had exited the function, turn back to function that calls this function


2. Below are two functions which attempt to set the passed in variable to PI such that variable passed from the calling function will also be set to PI. Which function will execute correctly, and why?

Method 1
void setToPi(float var) {
var = 3.14;
}

Method 2
void setToPi(float &var) {
var = 3.14;
}

Method1 won’t execute correctly. var is 3.14 when it is in block of function setToPI.
Method 2 will execute correctly, var is 3.14 even when function setToPI had ended....
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Visual Basic Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats