From 619fee1ce9febcc35db47156aa67c9fdfbe31de6 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 9 Jan 2025 13:41:45 -0800 Subject: [PATCH] feat: reorganize --- meson.build | 3 +- src/chapter_1/c_1_ice_1.cpp | 51 ++++++++++++++++++++++ src/chapter_1/{lab_1.cpp => c_1_lab_1.cpp} | 0 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/chapter_1/c_1_ice_1.cpp rename src/chapter_1/{lab_1.cpp => c_1_lab_1.cpp} (100%) diff --git a/meson.build b/meson.build index 52407aa..16942b1 100644 --- a/meson.build +++ b/meson.build @@ -5,4 +5,5 @@ project( default_options: ['warning_level=3', 'cpp_std=c++23'], ) -lab_1 = executable('lab_1', 'src/chapter_1/lab_1.cpp', install: true) +c_1_lab_1 = executable('c_1_lab_1', 'src/chapter_1/c_1_lab_1.cpp', install: true) +c_1_ice_1 = executable('c_1_ice_1', 'src/chapter_1/c_1_ice_1.cpp', install: true) diff --git a/src/chapter_1/c_1_ice_1.cpp b/src/chapter_1/c_1_ice_1.cpp new file mode 100644 index 0000000..4d14663 --- /dev/null +++ b/src/chapter_1/c_1_ice_1.cpp @@ -0,0 +1,51 @@ +#include +#include + +using namespace std; + +void display(const vector &); + +// Put function prototype (declaration) here +int indexOfMin(vector vec); +int main() { + + vector v; + int entry; + + // Fills vector with integers >= -100 from user + cout << "Enter an integer: "; + cin >> entry; + cout << endl; + while (entry >= -100) { + v.push_back(entry); + cout << "Enter an integer: "; + cin >> entry; + cout << endl; + } + + display(v); + cout << endl; + + cout << "Smallest Value: " << v.at(indexOfMin(v)) << endl; + + return 0; +} + +// Put function implementation (body) here +int indexOfMin(vector vec) { + unsigned int min_index = 0; + + for (unsigned int i = 0; i < vec.size(); i++) { + if (vec.at(i) < vec.at(min_index)) { + min_index = i; + } + } + + return min_index; +} + +void display(const vector &v) { + for (auto val : v) { + cout << val << ' '; + } +} diff --git a/src/chapter_1/lab_1.cpp b/src/chapter_1/c_1_lab_1.cpp similarity index 100% rename from src/chapter_1/lab_1.cpp rename to src/chapter_1/c_1_lab_1.cpp