Study results from Stroustrup's PPP3 book.
This commit is contained in:
parent
6363457d0f
commit
7a1093f982
10 changed files with 579 additions and 1 deletions
32
PPP3/ex04.cpp
Normal file
32
PPP3/ex04.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
vector<int> v = {5, 7, 9, 4, 6, 8};
|
||||
|
||||
for(unsigned int i = 0; i < v.size(); i++) {
|
||||
cout << "i=" << v[i] << "\n";
|
||||
}
|
||||
|
||||
vector<double> temps;
|
||||
double temp;
|
||||
|
||||
do {
|
||||
cin >> temp;
|
||||
temps.push_back(temp);
|
||||
} while(temp != 0);
|
||||
|
||||
for(int x : temps) {
|
||||
cout << "TEMP " << x << "\n";
|
||||
}
|
||||
|
||||
ranges::sort(temps);
|
||||
cout << "Median is" << temps[temps.size() / 2] << "\n";
|
||||
|
||||
// try a runtime error
|
||||
cout << "BANG" << temps[1000];
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue