Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- #include <bits/stdc++.h>
- using namespace std;;
- int SIZE;
- struct Record {
- int min;
- int max;
- int mode;
- int freq = 0;
- float mean;
- int total;
- };
- Record player;
- void setMinMax(int touchYear[]) {
- player.min = touchYear[0];
- player.max = touchYear[0];
- for (int x = 0; x < SIZE; x++) {
- if (touchYear[x] < player.min) {
- player.min = touchYear[x];
- }
- if (touchYear[x] > player.max) {
- player.max = touchYear[x];
- }
- }
- cout << "Player Min:\t" << player.min <<endl;
- cout << "Player Max:\t" << player.max <<endl;
- }
- void setMode(int touchYear[]) {
- int freq = 1;
- int mode = touchYear[0];
- sort(touchYear, touchYear + SIZE);
- for(int y = 0; y < SIZE; y++) {
- if(freq > player.freq){
- player.freq = freq;
- player.mode = touchYear[y];
- }
- if(touchYear[y + 1] == touchYear[y]) {
- freq++;
- }
- else {
- freq = 1;
- }
- }
- cout << "Player Mode:\t" << player.mode << endl;
- cout << "Player Freq:\t" << player.freq << endl;
- }
- void setTotal(int touchYear[]) {
- for(int x = 0; x < SIZE; x++) {
- player.total += touchYear[x];
- }
- player.mean = (float)player.total/(float)SIZE;
- cout << "Player Mean:\t" << player.mean << endl;
- cout << "Player Total:\t" << player.total << endl;
- }
- int main() {
- cout << "How many years of data do you need to enter?" << endl;
- cin >> SIZE;
- int tdRec[SIZE];
- int count = 0;
- while(count < SIZE) {
- cout << "Please enter in touchdown count for year " << count + 1 << ":\t";
- cin >> tdRec[count];
- cout << endl;
- count++;
- } //Collects Touchdown Data from User
- cout << "Your Touchdown list: ";
- for (int m = 0; m < SIZE; m++) {
- cout << tdRec[m] << " ";
- } //Prints Touchdown list
- cout <<"\n------------------------------------------------" << endl;
- setMinMax(tdRec);
- setMode(tdRec);
- setTotal(tdRec);
- return 0;
- }
- /*
- input
- clear
- gcc version 4.6.3
- How many years of data do you need to enter?
- 6
- Please enter in touchdown count for year 1: 5
- Please enter in touchdown count for year 2: 5
- Please enter in touchdown count for year 3: 5
- Please enter in touchdown count for year 4: 7
- Please enter in touchdown count for year 5: 8
- Please enter in touchdown count for year 6: 9
- Your Touchdown list: 5 5 5 7 8 9
- ------------------------------------------------
- Player Min: 5
- Player Max: 9
- Player Mode: 5
- Player Freq: 3
- Player Mean: 6.5
- Player Total: 39
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement