feat: reorganize
This commit is contained in:
parent
6f6f46daa9
commit
619fee1ce9
3 changed files with 53 additions and 1 deletions
|
@ -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)
|
||||
|
|
51
src/chapter_1/c_1_ice_1.cpp
Normal file
51
src/chapter_1/c_1_ice_1.cpp
Normal 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 << ' ';
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue