Skip to content
Snippets Groups Projects
Commit 1dd3d966 authored by Colbry, Dirk's avatar Colbry, Dirk
Browse files

Merge branch 'JVBranch' into 'main'

Adding Pointers

See merge request !5
parents 5a14d361 781f7e77
No related branches found
No related tags found
1 merge request!5Adding Pointers
%% Cell type:code id:fc73d74c tags:
``` python
##ANSWER##
#Install answercheck in current director
from urllib.request import urlretrieve
urlretrieve('https://raw.githubusercontent.com/colbrydi/jupytercheck/master/answercheck.py', filename='answercheck.py')
##ANSWER##
```
%% Output
('answercheck.py', <http.client.HTTPMessage at 0x7f646df0f820>)
%% Cell type:markdown id:3c2a4f39 tags:
# Pointers
Understanding Pointers and their purpose
%% Cell type:markdown id:2b78245b tags:
Pointer Dog:
![Types of Pointer Dog Breeds - Image found in the Google Images from AZ Animals](https://a-z-animals.com/media/2021/10/Types-of-Pointer-Dogs-header.jpg)
%% Cell type:markdown id:71e867d9 tags:
## Description
Pointers are variables whose value is an address, which is in another location in memory. Thus it is possible to refer to another variable in memory by that other variables memory address and also manipulate memory.
%% Cell type:markdown id:4ee3c1f1 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:07524fd7 tags:
&#9989; **<span style="color:red">Question:</span>** What is the correct way to create a pointer so that it points to a string variable named drink in the following code:
string drink = "Coke";
1. string* ptr = &drink;
2. string ptr = drink;
3. string& ptr = drink*;
%% Cell type:markdown id:f1da5683 tags:
&#9989; **<span style="color:red">Question:</span>** For the code below, which of the following is the best way to read the code:
int w = 99;
int* x = &w;
int* y = x;
1. Pointer x and Pointer y point to the same address.
2. Pointer x points to the value "99 "and Pointer y points to the the address of w.
3. Pointer x and Pointer y point to the same value.
%% Cell type:markdown id:7e232e3c tags:
&#9989; **<span style="color:red">Question:</span>** For the code below, which of the following is true:
int w = 99;
int* x = &w;
int* y = x;
1. x and y have the same name.
2. x and y have the same address.
3. x and y have the same value.
%% Cell type:markdown id:0843ee02 tags:
## TODO: DIRK will work on a list of list with pointers
%% Cell type:markdown id:6527d414 tags:
## TODO: Reword the second question
%% Cell type:markdown id:81760d5f tags:
&#9989; **<span style="color:red">Optional Question:</span>** Example Question:
1. AN2 1.
2. ANS 2.
3. ANS 3.
%% Cell type:markdown id:5d237ca9 tags:
## Training Materials
%% Cell type:markdown id:21f9b14e tags:
Introduction to Pointers in C++ in 6 minutes (https://youtu.be/fBlM7pR2r_Q)
%% Cell type:markdown id:68f2cbdb tags:
Pointer Material with exercises (https://www.w3schools.com/cpp/cpp_pointers.asp)
%% Cell type:markdown id:dd1da075 tags:
Pointer Material (https://www.programiz.com/cpp-programming/pointers)
%% Cell type:code id:deeec8f7 tags:
``` python
from IPython.display import YouTubeVideo
YouTubeVideo("fBlM7pR2r_Q",width="100%", height=360, cc_load_policy=True)
```
%% Output
<IPython.lib.display.YouTubeVideo at 0x7f646ce74370>
%% Cell type:markdown id:44b461a0 tags:
---
Written by <<YOUR NAME HERE>>, Michigan State University
As part of the Data Science Bridge Project
<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>.
%% Cell type:code id:fc73d74c tags:
``` python
##ANSWER##
#Install answercheck in current director
from urllib.request import urlretrieve
urlretrieve('https://raw.githubusercontent.com/colbrydi/jupytercheck/master/answercheck.py', filename='answercheck.py')
##ANSWER##
```
%% Output
('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:
![Captain America Meme - Image found in Google Images from Know Your Meme](https://i.kym-cdn.com/entries/icons/mobile/000/017/204/CaptainAmerica1_zps8c295f96.jpg)
%% 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:
&#9989; **<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:
&#9989; **<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)
References Materials (https://www.w3schools.com/cpp/cpp_references.asp)
References Material (https://www.tutorialspoint.com/cplusplus/cpp_references.htm)
%% Cell type:code id:9cc2b34a tags:
``` python
from answercheck import checkanswer
checkanswer.vector(x,'2cab95d1b144d663bad1ce5c51020ae0')
```
%% Output
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 <<YOUR NAME HERE>>, Michigan State University
As part of the Data Science Bridge Project
<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>.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment