diff options
| author | Connor McDowell <[email protected]> | 2024-02-24 15:03:59 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-24 15:03:59 -0800 |
| commit | aba41bb9090e06e4f4df1e64307400026c3831a3 (patch) | |
| tree | 6f077e697c61ebda0e01dabfdd5cbc3081c628c7 | |
| parent | screenshots taken to be added to lab, fibonacci array created (diff) | |
| download | lab-01-connormcdowell275-aba41bb9090e06e4f4df1e64307400026c3831a3.tar.xz lab-01-connormcdowell275-aba41bb9090e06e4f4df1e64307400026c3831a3.zip | |
adding fibonacci functions. added cArray, stdArray and myVector
| -rw-r--r-- | Project1/helper.cpp | 41 | ||||
| -rw-r--r-- | Project1/helper.h | 6 | ||||
| -rw-r--r-- | Project1/program.cpp | 20 |
3 files changed, 53 insertions, 14 deletions
diff --git a/Project1/helper.cpp b/Project1/helper.cpp index a90fc36..48a04cd 100644 --- a/Project1/helper.cpp +++ b/Project1/helper.cpp @@ -47,14 +47,51 @@ void Print(const std::list<int>& myList) void Fibonacci(int(&cArray)[SIZE]) { + int y = 0; + cout << "enter the last element of the Fibonacci sequence you would like to see: "; + cin >> y; cArray[0] = 0; cArray[1] = 1; - for (int i = 2; i < SIZE; i++) + for (int i = 2; i < y; i++) { cArray[i] = cArray[i - 1] + cArray[i - 2]; } - for (int i = 0; i < SIZE; i++) + for (int i = 0; i < y; i++) { cout << cArray[i] << " "; } +} + +void Fibonacci(std::array<int, SIZE>& stdArray) +{ + int y = 0; + cout << "enter the last element of the Fibonacci sequence you would like to see: "; + cin >> y; + stdArray[0] = 0; + stdArray[1] = 1; + for (int i = 2; i < y; i++) + { + stdArray[i] = stdArray[i - 1] + stdArray[i - 2]; + } + for (int i = 0; i < y; i++) + { + cout << stdArray[i] << " "; + } +} + +void Fibonacci(std::vector<int>& myVector) +{ + int y = 0; + cout << "enter the last element of the Fibonacci sequence you would like to see: "; + cin >> y; + myVector[0] = 0; + myVector[1] = 1; + for (int i = 2; i < y; i++) + { + myVector[i] = myVector[i - 1] + myVector[i - 2]; + } + for (int i = 0; i < y; i++) + { + cout << myVector[i] << " "; + } }
\ No newline at end of file diff --git a/Project1/helper.h b/Project1/helper.h index cf90d68..8813e4d 100644 --- a/Project1/helper.h +++ b/Project1/helper.h @@ -21,10 +21,10 @@ void Print(const std::list<int>& myList); void Fibonacci(int(&cArray)[SIZE]); -void Fibonacci(const std::array<int, SIZE>& stdArray); +void Fibonacci(std::array<int, SIZE>& stdArray); -void Fibonacci(const std::vector<int>& myVector); +void Fibonacci(std::vector<int>& myVector); -void Fibonacci(const std::list<int>& myList); +void Fibonacci(std::list<int>& myList); #endif HELPER diff --git a/Project1/program.cpp b/Project1/program.cpp index d854cd5..89ebc2e 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -21,11 +21,12 @@ void createArray() { int cArray[SIZE]; - for (int i = 0; i < SIZE; i++) + for (size_t i = 0; i < SIZE; i++) { cArray[i] = i; } - Print(cArray); + Fibonacci(cArray); + //Print(cArray); } void createstdArray() @@ -36,8 +37,8 @@ void createstdArray() { stdArray[i] = i; } - - Print(stdArray); + Fibonacci(stdArray); + //Print(stdArray); } void createVector() @@ -49,7 +50,8 @@ void createVector() { myVector.push_back(i); } - Print(myVector); + Fibonacci(myVector); + //Print(myVector); } void Create_list() @@ -60,16 +62,16 @@ void Create_list() { myList.push_back(i); } - Print(myList); + + //Print(myList); } int main() { //createArray(); //createstdArray(); - //createVector(); - Create_list(); - + createVector(); + //Create_list(); return 0; |