Virginia Lottery Program:
/*Adam Clark
5-16-00
This program will search through lottery data to find the most commonly
occuring numbers*/
//headers
#include <iostream.h>
#include <iomanip.h>
#include <ifstream.h>
#include <stdlib.h>
#include <conio.h>
#include <assert.h>
#include "bool.h"
#include "apstring.h"
//code for declarations
// Function : open_file
// Prompts user for the file name and opens
// input stream on the file
//
// Outputs: an input file stream
void open_file(ifstream &in_file);
//funtion: read_file
//
//this program will save the information in the file
//to an array of letters
void read_file(long lotto[ ]);
//Function: selection
//organizes an array from
//
//input array
//output lotto array
void selection(long lotto[], int order[ ]);
//function: winning_numbers
//finds out if user has ever won the lottery
//
//inputs: six integers representing lottery numbers
//outputs: what you would have won
void winning_numbers(long lotto[ ],
int user1, int user2, int user3, int user4, int user5, int user6);
int main()
{
apstring answer;
answer="y";
while(answer=="y")
{
clrscr();
//variables
long total= 0;
long lotto[45];
int order[45];
double percent = 0;
double barfactor= 0;
long biggest = 0;
double barlengh;
double denom;
int a, b, c, d, e, f,choice;
//formating
//opening
for (int k = 0; k <= 44; k++)
//finds the bargraphfactor
//output loop for total distribution
if (choice==2)
for (int k = 0; k <= 44; k++)
//finds the bargraphfactor
//output loop for total distribution
if (choice==3)
for (int k = 0; k <= 44; k++)
//finds the bargraphfactor
//output loop for total distribution
if (choice==4)
cout<< "Would you like to run this program again? [y/n]
"< //subroutine to open file
in_file_name = "a:/lotto.txt";
//file name
void read_file(long lotto[ ])
open_file(in_file); //opens
file
while (! in_file.eof()) //does loop until
the end of file
getline(in_file,s);
num1 = atoi(s.substr(10,2).c_str()); //number 1
//acumulator
}
cout<< "There where "< void selection(long lotto[], int order[ ])
for (int i = 44; i >= 1; i--)
temp = order[position];
void winning_numbers(long lotto[ ],
open_file(in_file); //opens
file
cout<<"These number occured on the following date(s): "< getline(in_file,s);
num1 = atoi(s.substr(10,2).c_str()); //number 1
//acumulator
if ((user1 == num1) || (user1 == num2) || (user1 == num3) ||
(user1 == num4)
switch (times_found)
}
cout<
for (int i = 0; i <= 44; i++)
{
lotto[i] = 0;
order[i]= (i);
}
cout<<"Adam's Great Lotto Database Program"<
cin>> choice;
cout<
{
read_file(lotto);
//biggest_to_smallest(lotto,order);
selection(lotto, order);
{
total = total + lotto[k];
if (lotto[k] > biggest)
biggest = lotto[k];
//cout<<(char)(order[k]+65)<
denom = ((double)biggest/(double)total)*100;
barfactor = (50/ denom);
cout<
{
percent = ((double)lotto[z]/(double)total) *100;
barlengh = (int)(percent * barfactor);
if (order[z]<=9)
{
cout<<(order[z])<<"
";
}
else
{
cout<<(order[z])<<"
";
}
for (int y = 1; y <= barlengh; ++y)
{
cout<<"*";
}
cout<<" "<
}
{
read_file(lotto);
//biggest_to_smallest(lotto,order);
selection(lotto, order);
{
total = total + lotto[k];
if (lotto[k] > biggest)
biggest = lotto[k];
//cout<<(char)(order[k]+65)<
denom = ((double)biggest/(double)total)*100;
barfactor = (50/ denom);
cout<
{
percent = ((double)lotto[z]/(double)total) *100;
barlengh = (int)(percent * barfactor);
if (order[z]<=9)
{
cout<<(order[z])<<"
";
}
else
{
cout<<(order[z])<<"
";
}
for (int y = 1; y <= barlengh; ++y)
{
cout<<"*";
}
cout<<" "<
}
{
read_file(lotto);
//biggest_to_smallest(lotto,order);
selection(lotto, order);
{
total = total + lotto[k];
if (lotto[k] > biggest)
biggest = lotto[k];
//cout<<(char)(order[k]+65)<
denom = ((double)biggest/(double)total)*100;
barfactor = (50/ denom);
for (int z = 1; z <=44; z++)
{
percent = ((double)lotto[z]/(double)total) *100;
barlengh = (int)(percent * barfactor);
if (order[z]<=9)
{
cout<<(order[z])<<"
";
}
else
{
cout<<(order[z])<<"
";
}
for (int y = 1; y <= barlengh; ++y)
{
cout<<"*";
}
cout<<" "<
}
{
cout<<"What are your six numbers?"<
cin>>a;
cout<<"2.)";
cin>>b;
cout<<"3.)";
cin>>c;
cout<<"4.)";
cin>>d;
cout<<"5.)";
cin>>e;
cout<<"6.)";
cin>>f;
cout<
}
}
//closing
cout<< endl<<"Thank you for using Melodious Groan
Inc!!!"<
}
void open_file(ifstream &in_file)
{
apstring in_file_name;
in_file.open(in_file_name.c_str()); //opens
file
assert(! in_file.fail());
//bug-proofing
}
{
int times_found, month, day, year, num1, num2, num3, num4, num5,
num6;
ifstream in_file;
long total=0;
apstring s;
{
times_found= 0; //initialization
month = atoi(s.substr(0,2).c_str());
//month
day = atoi(s.substr(3,2).c_str());
//day
year = atoi(s.substr(6,2).c_str());
//year
num2 = atoi(s.substr(13,2).c_str());
//number 2
num3 = atoi(s.substr(16,2).c_str());
//number 3
num4 = atoi(s.substr(19,2).c_str());
//number 4
num5 = atoi(s.substr(22,2).c_str());
//number 5
num6 = atoi(s.substr(25,2).c_str());
//number 6
++total;
lotto[num1]++;
lotto[num2]++;
lotto[num3]++;
lotto[num4]++;
lotto[num5]++;
lotto[num6]++;
}
{
int biggest = 0;
int position = 0;
int temp = 0;
{
biggest = 0;
position = 0;
for (int j = 0; j <= i; j++)
{
if (lotto[j] > biggest)
{
biggest = lotto[j];
position = j;
}
}
temp = lotto[position];
lotto[position] = lotto[i];
lotto[i]= temp;
order[position] = order[i];
order[i]= temp;
}
}
int user1, int user2, int user3, int user4, int user5, int user6)
{
int times_found, month, day, year, num1, num2, num3, num4, num5,
num6;
int winnings = 0;
int jackpot=0;
ifstream in_file;
long total=0;
apstring s;
{
times_found= 0; //initialization
month = atoi(s.substr(0,2).c_str());
//month
day = atoi(s.substr(3,2).c_str());
//day
year = atoi(s.substr(6,2).c_str());
//year
num2 = atoi(s.substr(13,2).c_str());
//number 2
num3 = atoi(s.substr(16,2).c_str());
//number 3
num4 = atoi(s.substr(19,2).c_str());
//number 4
num5 = atoi(s.substr(22,2).c_str());
//number 5
num6 = atoi(s.substr(25,2).c_str());
//number 6
++total;
lotto[num1]++;
lotto[num2]++;
lotto[num3]++;
lotto[num4]++;
lotto[num5]++;
lotto[num6]++;
|| (user1 == num5) || (user1 == num6))
{
times_found++;
}
if ((user2 == num1) || (user2 == num2) || (user2 == num3) ||
(user2 == num4)
|| (user2 == num5) || (user2 == num6))
{
times_found++;
}
if ((user3 == num1) || (user3 == num2) || (user3 == num3) ||
(user3 == num4)
|| (user3 == num5) || (user3 == num6))
{
times_found++;
}
if ((user4 == num1) || (user4 == num2) || (user4 == num3) ||
(user4 == num4)
|| (user4 == num5) || (user4 == num6))
{
times_found++;
}
if ((user5 == num1) || (user5 == num2) || (user5 == num3) ||
(user5 == num4)
|| (user5 == num5) || (user5 == num6))
{
times_found++;
}
if ((user6 == num1) || (user6 == num2) || (user6 == num3) ||
(user6 == num4)
|| (user6 == num5) || (user6 == num6))
{
times_found++;
}
{
case 3 : cout<< "You picked three numbers
on : "<< month<<"/"<
case 4 : cout<< "You picked four numbers
on : "<< month<<"/"<
case 5 : cout<< "You picked five numbers
on : "<< month<<"/"<
case 6 : cout<< "You won the lotto on
: "<< month<<"/"<
}
cout<
}