feat: reorganize

This commit is contained in:
Youwen Wu 2025-01-09 13:41:45 -08:00
parent 6f6f46daa9
commit 619fee1ce9
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
3 changed files with 53 additions and 1 deletions

View file

@ -5,4 +5,5 @@ project(
default_options: ['warning_level=3', 'cpp_std=c++23'], 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)

View file

@ -0,0 +1,51 @@
#include <iostream>
#include <vector>
using namespace std;
void display(const vector<int> &);
// Put function prototype (declaration) here
int indexOfMin(vector<int> vec);
int main() {
vector<int> 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<int> 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<int> &v) {
for (auto val : v) {
cout << val << ' ';
}
}