From d5c3e3061f27fb7808f95ff6b72d374af99ecbcf Mon Sep 17 00:00:00 2001 From: Nataliia Brown Date: Fri, 9 Feb 2024 23:47:32 -0800 Subject: with functions --- In class ex 9/In class ex 9/ReferenceExamples.cpp | 19 ++++++++++++++++++- In class ex 9/In class ex 9/ReferenceExamples.h | 4 +++- In class ex 9/In class ex 9/program.cpp | 23 ++++++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/In class ex 9/In class ex 9/ReferenceExamples.cpp b/In class ex 9/In class ex 9/ReferenceExamples.cpp index 83d0de5..c7b540b 100644 --- a/In class ex 9/In class ex 9/ReferenceExamples.cpp +++ b/In class ex 9/In class ex 9/ReferenceExamples.cpp @@ -3,4 +3,21 @@ // Class: CST 116 // Assignment: In-Class Exercise 9 -#include "ReferenceExamples.h" \ No newline at end of file +#include "ReferenceExamples.h" + +void Swap(int& x, int& y) { + int z = x; + x = y; + y = z; +} + +void Standardize_101(int& n) { + + n = n % 101; + +} + +void Square(int& x) { + + x = x * x; +} \ No newline at end of file diff --git a/In class ex 9/In class ex 9/ReferenceExamples.h b/In class ex 9/In class ex 9/ReferenceExamples.h index 119938d..eb6a598 100644 --- a/In class ex 9/In class ex 9/ReferenceExamples.h +++ b/In class ex 9/In class ex 9/ReferenceExamples.h @@ -1,9 +1,11 @@ #ifndef REFERENCE_EXAMPLES_H #define REFERENCE_EXAMPLES_H +void Swap(int& x, int& y); +void Standardize_101(int& n); - +void Square(int& x); #endif diff --git a/In class ex 9/In class ex 9/program.cpp b/In class ex 9/In class ex 9/program.cpp index 1a86318..df2691d 100644 --- a/In class ex 9/In class ex 9/program.cpp +++ b/In class ex 9/In class ex 9/program.cpp @@ -4,7 +4,28 @@ // Assignment: In-Class Exercise 9 #include +#include "ReferenceExamples.h" using std::cout; using std::cin; -using std::endl; \ No newline at end of file +using std::endl; + +int main(){ + int x = 5, y = 72; + + Swap(x, y); + + cout << "x = " << x << ", y = " << y; + + int n = 4392; + + Standardize_101(n); + + cout << "Modded n = " << n << endl; + + Square(n); + + cout << "Squared n = " << n << endl; + +} + -- cgit v1.2.3