Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <algorithm>
- using namespace std;
- const int VECTOR_LENGTH = 10;
- int min(vector<int> x){
- sort(x.begin(), x.end());
- return x[0];
- }
- int max(vector<int> x){
- sort(x.begin(), x.end());
- return x[x.size() - 1];
- }
- int mode(vector<int> x){
- map<int, int> modemap;
- for(unsigned int i = 0; i < x.size(); i++){
- if(modemap.count(x[i]) == 0)
- modemap.insert(pair<int, int>(x[i], 1));
- else modemap.find(x[i])->second++;
- }
- int number = 0;
- int count = 0;
- for(pair<int, int> p : modemap){
- if(p.second > count){
- count = p.second;
- number = p.first;
- }
- }
- return number;
- }
- int main(){
- vector<int> x;
- for(int i = 0; i < VECTOR_LENGTH; i++ ){
- cout << "Please enter an integer" << endl;
- int point;
- cin >> point;
- x.push_back(point);
- }
- cout << "The min of the vector is " << min(x) << endl;
- cout << "The max of the vector is " << max(x) << endl;
- cout << "The mode of the vector " << mode(x) << endl;
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement