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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
//FUNCTIONS.CPP
//I have these included for now just in case I need them before I'm done.
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include "Functions.h"
using namespace std;
#define FILE_IN "PowerballNow.csv"
//#define FILE_OUT "will be determined by the user"
bool ReadPowerballNumbers(vector<Powerball> &vNumbers)
{
//OPEN DATA FILE "Powerball.csv"
string trash;
ifstream openFile;
Powerball numbers;
char comma;
int multiplier;
openFile.open(FILE_IN);
if (openFile.is_open())
{
//THROWING OUT THE FIRST LINE OF TEXT
getline(openFile, trash, ',');
getline(openFile, trash, ',');
getline(openFile, trash);
//LOAD DATA INTO OBJECT "numbers"
for (int i = 0; i < 648; i++)
{
getline(openFile, trash, ',');//ELIMINATING THE DATE
openFile >> numbers.number[0];
openFile >> numbers.number[1];
openFile >> numbers.number[2];
openFile >> numbers.number[3];
openFile >> numbers.number[4];
openFile >> numbers.powerball;
openFile >> comma; // ELIMINATING THE COMMA
openFile >> multiplier; // ELIMINATING THE MULTIPLIER
//PUSHING "NUMBERS" INTO VECTOR NAMED vNumbers
vNumbers.push_back(numbers);
//COUT ALL NUMBERS TO PROVE FILE WAS READ
cout << "\t" << setw(2) << numbers.number[0] << " " << setw(2)
<< numbers.number[1] << " " << setw(2) << numbers.number[2] << " "
<< setw(2) << numbers.number[3] << " " << setw(2) << numbers.number[4]
<< " " << setw(2) << numbers.powerball << endl;
}
//CLOSE FILE AFTER READING
openFile.close();
return true;
}
else
{
cout << "\n\t\tError! Could not open file." << endl;
return false;
}
}
void CountNumbers(vector<Powerball> &vNumbers, int numCount[], int pbCount[], int &num1, int &pbnum)
{
for (unsigned int i = 0; i < vNumbers.size(); i++)
{
for (int j = 0; j < 5; j++)
{
num1 = vNumbers[i].number[j];
numCount[num1]++;
}
pbnum = vNumbers[i].powerball;
pbCount[pbnum]++;
}
cout << "\n\n\tNumber Count" << endl;
for (int i = 1; i <= 69; i++)
{
cout << "\t" << setw(3) << i << "\t" << numCount[i] << endl;
}
cout << "\n\n\tPowerball Count" << endl;
for (int i = 1; i <= 26; i++)
{
cout << "\t" << setw(3) << i << "\t" << pbCount[i] << endl;
}
}
void SortNumberCounts(int numCount[], int pbCount[], int &num1, int &pbnum)
{
int i = 0, j = 0, temp;
for (i = 1; i < num1 - 1; ++i)
{
for (j = 1; j < num1; ++j)
{
if (numCount[j - 1] > numCount[j])
{
temp = numCount[j];
numCount[j] = numCount[j - 1];
numCount[j - 1] = temp;
}
}
}
cout << "\n\n\t The Five Most Frequently Drawn Numbers Are: \n\n";
for (int i = 1; i < 6; ++i)
{
cout << "\tNumber[" << i << "]" << numCount[i] << endl;
}
cout << "\n\n\t The Five Most Infrequently Drawn Numbers Are: \n\n";
for (int i = num1 - 6; i < num1; ++i)
{
cout << "\tNumber[" << i << "]" << numCount[i] << endl;
}
}
/* THIS PART WON'T WORK AT ALL: WHEN I RUN IT WITH THIS IT SAYS BUILD ERRORS, BUT THERE ARE NO ERRORS LISTED.
for (i = 1; i < pbnum - 1; ++i)
{
for (j = 1; j < pbnum; ++j)
{
if (pbCount[j - 1] > pbCount[j])
{
temp = pbCount[j];
pbCount[j] = pbCount[j - 1];
pbCount[j - 1] = temp;
}
}
}
cout << "\n\n\t The Five Most Frequently Drawn Powerball Numbers Are: \n";
for (int i = 1; i < 6; ++i)
{
cout << "Number[" << i << "]" << pbCount[i] << endl;
}
cout << "\n\n\t The Five Most Infrequently Drawn Powerball Numbers Are: \n";
for (int i = pbnum - 6; i < pbnum; ++i)
{
cout << "Number[" << i << "]" << pbCount[i] << endl;
}
} */
|