Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //struct QB TD counter.
- #include <iostream>
- //#include <vector>
- using namespace std;
- struct ModeStruct
- {
- int mode;
- int modeFreq;
- };
- struct Playerdata
- {
- int touchDowns;
- //int total;
- };
- ModeStruct GetMode(Playerdata daArray[], int iSize);
- /*void printStruct(Playerdata info)
- {
- cout << info.playerName << "\t" << info.touchDowns << "\t " << endl;
- }
- */
- int main()
- {
- string playerName;
- int years;
- //vector <Playerdata> touchDowns;
- double total = 0;
- double average = 0;
- int highest = 0;
- int lowest;
- cout << "Enter a QB name: " << endl;
- getline(cin, playerName);
- cout << playerName;
- cout << "How many years for Touch Down Totals: " << endl;
- cin >> years;
- Playerdata tds_ea_year[years];
- for (int val = 0; val < years; val++)
- {
- cout << "Enter the total TD's for year #" << (val + 1) << ": " << endl;
- cin >> tds_ea_year[val].touchDowns;
- lowest = tds_ea_year[0].touchDowns;
- total += tds_ea_year[val].touchDowns;
- if (tds_ea_year[val].touchDowns > highest) highest = tds_ea_year[val].touchDowns;
- if (tds_ea_year[val].touchDowns < lowest) lowest = tds_ea_year[val].touchDowns;
- }
- cout << "Here's the contents of the array: " << endl;
- for (int val = 0; val < years; val++)
- {
- cout << "year #: " << (val + 1) << "\t"<< tds_ea_year[val].touchDowns << endl;
- }
- average = total / years;
- ModeStruct finalMode;
- finalMode = GetMode(tds_ea_year, years);
- cout << "The Total is: " << total << endl;
- cout << "The mean is: " <<average << endl;
- if (finalMode.modeFreq < 1)
- cout << "No mode..." << endl;
- else
- cout << "The mode is: " << finalMode.mode << " and the frequency is: " << finalMode.modeFreq << endl;
- cout << "The Maximum value is: " << highest << endl;
- cout << "The Minimum value is: " << lowest << endl;
- // printStruct(tdsPerYear);
- }
- ModeStruct GetMode(Playerdata daArray[], int iSize) {
- // Allocate an int array of the same size to hold the
- // repetition count
- ModeStruct currentMode;
- int frequency;
- int* ipRepetition = new int[iSize];
- for (int i = 0; i < iSize; ++i) {
- ipRepetition[i] = 0;
- int j = 0;
- bool bFound = false;
- while ((j < i) && (daArray[i].touchDowns != daArray[j].touchDowns)) {
- if (daArray[i].touchDowns != daArray[j].touchDowns) {
- ++j;
- }
- }
- ++(ipRepetition[j]);
- }
- int iMaxRepeat = 0;
- for (int i = 1; i < iSize; ++i) {
- if (ipRepetition[i] > ipRepetition[iMaxRepeat]) {
- iMaxRepeat = i;
- frequency++;
- }
- }
- currentMode.modeFreq = ipRepetition[iMaxRepeat];
- currentMode.mode = daArray[iMaxRepeat].touchDowns;
- delete [] ipRepetition;
- return currentMode;
- }
- /*
- gcc version 4.6.3
- Enter a QB name:
- Dave
- DaveHow many years for Touch Down Totals:
- 15
- Enter the total TD's for year #1:
- 22
- Enter the total TD's for year #2:
- 23
- Enter the total TD's for year #3:
- 22
- Enter the total TD's for year #4:
- 25
- Enter the total TD's for year #5:
- 26
- Enter the total TD's for year #6:
- 27
- Enter the total TD's for year #7:
- 26
- Enter the total TD's for year #8:
- 19
- Enter the total TD's for year #9:
- 18
- Enter the total TD's for year #10:
- 17
- Enter the total TD's for year #11:
- 16
- Enter the total TD's for year #12:
- 22
- Enter the total TD's for year #13:
- 22
- Enter the total TD's for year #14:
- 22
- Enter the total TD's for year #15:
- 22
- Here's the contents of the array:
- year #: 1 22
- year #: 2 23
- year #: 3 22
- year #: 4 25
- year #: 5 26
- year #: 6 27
- year #: 7 26
- year #: 8 19
- year #: 9 18
- year #: 10 17
- year #: 11 16
- year #: 12 22
- year #: 13 22
- year #: 14 22
- year #: 15 22
- The Total is: 329
- The mean is: 21.9333
- The mode is: 22 and the frequency is: 6
- The Maximum value is: 27
- The Minimum value is: 22
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement