Question
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 Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use 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.
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.zip
Purchase Solution
$40.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,807+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,696+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,468+ sessions)
2 hours avg response

Similar Homework Solutions