-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.cpp
More file actions
43 lines (38 loc) · 1.1 KB
/
Copy pathsort.cpp
File metadata and controls
43 lines (38 loc) · 1.1 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
//
// Created by Bob Liu on 2020/09/17.
//
#include <iostream>
#include <random>
#include <bits/stdc++.h>
#include "sort.hpp"
using namespace std;
int showEntries() {
int entryNumber = 0;
string entry;
ifstream entries("Reading.txt");
while (std::getline(entries, entry)) {
++entryNumber;
}
cout << "The numbers of entry in this file: " << entryNumber << "\n";
return entryNumber;
}
void sorting() {
string entry;
ifstream entries("Reading.txt");
double toSort[showEntries()];
int x = 0;
int entryNumber;
double sum{0};
double yetSort{0};
while (entries >> entryNumber >> yetSort) {
toSort[x] = yetSort;
sum += yetSort;
x++;
}
int numberOfElements = sizeof(toSort) / sizeof(toSort[0]);
sort(toSort, toSort+numberOfElements);
cout << "The highest reading is " << toSort[numberOfElements - 1] << "\n"
<< "The median reading is " << toSort[numberOfElements /2] << "\n"
<< "The lowest reading is " << toSort[0] << "\n"
<< "The average reading is " << setprecision(5) << sum/numberOfElements << endl;
}