"\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "71e867d9",
"metadata": {},
"source": [
"## Description\n",
"A reference variable is an alias, that is, another name for an already existing variable. Think of a variable name as a label attached to the variable's location in memory. You can then think of a reference as a second label attached to that memory location. Therefore, you can access the contents of the variable through either the original variable name or the reference.\n"
]
},
{
"cell_type": "markdown",
"id": "89c2fa92",
"metadata": {},
"source": [
"## Learning Goals"
]
},
{
"cell_type": "markdown",
"id": "58ec20e8",
"metadata": {},
"source": [
"## Self Assessment\n",
"\n",
"Questions that test for the learning goals and allows students to evaluate if they truly understand the topics."
]
},
{
"cell_type": "markdown",
"id": "0234bfdc",
"metadata": {},
"source": [
"✅ **<span style=\"color:red\">Question:</span>** Based on the code below what will be the output of the variable meal:\n",
"\n",
" string food = \"Pizza\";\n",
" string &meal = food; \n",
"\n",
" cout << meal;\n",
"\n",
"1. \"Pizza\"\n",
"2. \"food\"\n",
"3. nothing\n",
"4. error"
]
},
{
"cell_type": "markdown",
"id": "d030f312",
"metadata": {},
"source": [
"✅ **<span style=\"color:red\">Question:</span>** Based on the code below, what should be done to change the value of the variable GPA without changing the variable directly:\n",
"\n",
" #include <iostream>\n",
" int main(){\n",
" double GPA = 3.14;\n",
" std::cout << \"My GPA is: \" << GPA;\n",
" }\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "daaf2d04",
"metadata": {},
"outputs": [],
"source": [
"#Put your answer here"
]
},
{
"cell_type": "markdown",
"id": "5d237ca9",
"metadata": {},
"source": [
"## Training Materials\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "21f9b14e",
"metadata": {},
"source": [
"Reference Variable In C++ in 6 minutes (https://youtu.be/NGKt3Xwlobg)\n",
"Written by <<YOUR NAME HERE>>, Michigan State University \n",
"As part of the Data Science Bridge Project \n",
" \n",
"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc/4.0/88x31.png\" /></a><br />This work is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\">Creative Commons Attribution-NonCommercial 4.0 International License</a>."
('answercheck.py', <http.client.HTTPMessage at 0x7fc9a8612220>)
%% Cell type:markdown id:3c2a4f39 tags:
# References
Understanding References and their purpose
%% Cell type:markdown id:2b78245b tags:
Understanding the Reference:

%% Cell type:markdown id:71e867d9 tags:
## Description
A reference variable is an alias, that is, another name for an already existing variable. Think of a variable name as a label attached to the variable's location in memory. You can then think of a reference as a second label attached to that memory location. Therefore, you can access the contents of the variable through either the original variable name or the reference.
%% Cell type:markdown id:89c2fa92 tags:
## Learning Goals
%% Cell type:markdown id:58ec20e8 tags:
## Self Assessment
Questions that test for the learning goals and allows students to evaluate if they truly understand the topics.
%% Cell type:markdown id:0234bfdc tags:
✅**<span style="color:red">Question:</span>** Based on the code below what will be the output of the variable meal:
string food = "Pizza";
string &meal = food;
cout << meal;
1. "Pizza"
2. "food"
3. nothing
4. error
%% Cell type:markdown id:d030f312 tags:
✅**<span style="color:red">Question:</span>** Based on the code below, what should be done to change the value of the variable GPA without changing the variable directly:
#include <iostream>
int main(){
double GPA = 3.14;
std::cout << "My GPA is: " << GPA;
}
%% Cell type:code id:daaf2d04 tags:
``` python
#Put your answer here
```
%% Cell type:markdown id:5d237ca9 tags:
## Training Materials
%% Cell type:markdown id:21f9b14e tags:
Reference Variable In C++ in 6 minutes (https://youtu.be/NGKt3Xwlobg)
CheckWarning: passed variable is <class 'int'> and not a numpy.matrix.
Trying to convert to a array matrix using ```A = np.matrix(A)```.
CheckWarning: passed matrix is int64 and not <class 'numpy.float64'>...
Trying to convert to float using ```A = A.astype(float)```.
Testing [[4.]]
Answer seems to be correct
%% Cell type:markdown id:44b461a0 tags:
---
Written by <<YOURNAMEHERE>>, Michigan State University
As part of the Data Science Bridge Project
<arel="license"href="http://creativecommons.org/licenses/by-nc/4.0/"><imgalt="Creative Commons License"style="border-width:0"src="https://i.creativecommons.org/l/by-nc/4.0/88x31.png"/></a><br/>This work is licensed under a <arel="license"href="http://creativecommons.org/licenses/by-nc/4.0/">Creative Commons Attribution-NonCommercial 4.0 International License</a>.