diff options
| author | Connor McDowell <[email protected]> | 2024-02-08 12:56:48 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-08 12:56:48 -0800 |
| commit | 8a92322cbf31ebd646ef06865a1c3d0c5038dad3 (patch) | |
| tree | 6ff71698400cd18a76a1bf4681d69cd1303ec71e | |
| parent | int main for practice and examples commented, functions moved to Reference Ex... (diff) | |
| download | in-class-exercise-9-connormcdowell275-8a92322cbf31ebd646ef06865a1c3d0c5038dad3.tar.xz in-class-exercise-9-connormcdowell275-8a92322cbf31ebd646ef06865a1c3d0c5038dad3.zip | |
| -rw-r--r-- | Inclass-9/Program.cpp | 13 | ||||
| -rw-r--r-- | Inclass-9/ReferenceExamples.cpp | 24 |
2 files changed, 30 insertions, 7 deletions
diff --git a/Inclass-9/Program.cpp b/Inclass-9/Program.cpp index 5b7fa73..014935d 100644 --- a/Inclass-9/Program.cpp +++ b/Inclass-9/Program.cpp @@ -27,7 +27,20 @@ int main() cout << newNode.data << endl;*/ + int x = 5, y = 72; + int n = 4392; + Swap(x, y); + + cout << "x = " << x << ", y = " << y << endl; + + Standardize_101(n); + + cout << "modded n = " << n << endl; + + Square(x); + + cout << "Squared x = " << x << " remember, x = the value of y now" << endl; return 0; diff --git a/Inclass-9/ReferenceExamples.cpp b/Inclass-9/ReferenceExamples.cpp index 30be619..0a89671 100644 --- a/Inclass-9/ReferenceExamples.cpp +++ b/Inclass-9/ReferenceExamples.cpp @@ -9,25 +9,39 @@ using std::endl; void Swap(int& x, int& y) { + int& swap_x = x; + int& swap_y = y; + int temp; + temp = y; + swap_y = x; + swap_x = temp; + x = swap_x; + y = swap_y; } void Standardize_101(int& n) { - + n = n % 101; - // return n %= 101; } void Square(int& x) { - + x = x * x; } + + + + + + + void basicreferences() { int variable = 15; @@ -42,23 +56,19 @@ void basicreferences() cout << address << endl; } - struct node { int data; }; - void DoublesNodeData(node node) { node.data *= 2; } - void DoublesNodeDataRef(node& node) { node.data *= 2; } - void DoublesNodeData(node* node) { node->data *= 2; |