forked from orazaro/accelerated
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-02-quartiles.cpp
More file actions
53 lines (43 loc) · 1.17 KB
/
03-02-quartiles.cpp
File metadata and controls
53 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <iomanip>
#include <ios>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
cout << "Enter all your homework grades, \n"
"followed by end-of-file: ";
double x;
vector<double> homework;
// invariant: homework contains all the homework grades read so far
while( cin >> x ) {
homework.push_back(x);
}
typedef vector<double>::size_type vec_sz;
vec_sz size = homework.size();
if(size == 0) {
cout << endl << "You must enter your grades. "
"Please try again." << endl;
return 1;
}
sort(homework.begin(), homework.end());
int i2 = (int) ( size / 2 );
int i1 = (int) ( (0 + i2) / 2 );
int i3 = (int) ( (i2 + size) / 2);
cout << "Quartiles:" << endl;
for(int i = 0; i < i1; i++)
cout << homework[i] << ' ';
cout << endl;
for(int i = i1; i < i2; i++)
cout << homework[i] << ' ';
cout << endl;
for(int i = i2; i < i3; i++)
cout << homework[i] << ' ';
cout << endl;
for(int i = i3; i < (int)size; i++)
cout << homework[i] << ' ';
cout << endl;
return 0;
}