C
carl bloc
Have this much done but need help with this bit of code:
allow user to modify existing draw data. I think I need a counter to
give week numbers so the user can select a week number rather than a
date.
I need to view data for a selected week given the week number or date.
need some controls on not allowing the ball number to go >49 or <0 and
no duplicates.
the date needs some work on so the user can only enter numbers not
letters.
any help would be great.
/**********************************************************************************************
*
* Carl's Assignment
*
*
*
* Here is a list of tasks to consider
* ___________________________________
*
* * Change the Display Routine to display the complete list of
* 52 Records simultaniously.
* You'll need to alter the count
*
* * Alter the Comments, and add extra ones
*
* * Write a Routine to edit an existing Record
*
* * Write a Routine that checks that the Ball Values entered are
within Range ( 1 - 49 )
*
* * Write a Routine that checks that no duplicate Ball Values are
entered
* (run this check after every entry)
*
* * THE BIG ONE - Write a Routine that checks the Date is valid
*
* * Think about what will happen when the Array is full & you put in
an additional Entry
*
*
***********************************************************************************************/
#include <iostream.h>
#include <math.h>
#include <process.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
// Function prototypes
void GetInput();
void DisplayValues();
void ChoiceDefault();
void AnyKey();
//Global variables (declared outside main() - so visable (i.e.
accessable) to whole program functions and all!
char datearray[53][10]; // 2-Dimensional array 52 rows, 9 columns.
int balls[53][36];
void main()
{
char date[10];
int choice=0, x=0, y=0;
int insertionPoint=0;
int i =0, j = 0, k = 0;
//initialise global 'datearray' as a string of asterixes and 'balls'
array with 0's
for(j=0; j<53; j++)
{
for(i=0; i<8; i++)
{
if (i == 8)
{
datearray[j] = '\0';//terminate string with null character
}
else
{
datearray[j] = '*';// initialise datarray with asterix
characters
}
for (int k=0;k<8;k++)
balls[k] = 0;
}
}
// open Date.txt file to get data from
ifstream inClientFile("Date.txt", ios::in); // open file for input
if(!inClientFile) // handle "could not open file" error
{
cerr << "File could not be opened" << endl;
exit(1);
}
// read data (date & two numbers) from Date.txt file
i=0; // must reset "i" to zero
while (inClientFile >> date)// read (next) "line" from file
{
for (k=0;k<7;k++)
inClientFile>>balls[k];
for(j=0; j<9; j++)
{
datearray[j] = date[j]; // copy date from 'date' tempory
variable into datearray
}
i++;
}
insertionPoint = i;//remember where to insert next new data
while (true)
{
// Clear screen
system("cls");
//Print Menu choices on screen
cout << "\n\n\t\tMENU:\n\n"<< "\t1 - Enter New Date\n"<< "\t2 - Print
out contents of global array on screen\n" << "\t999 - to exit";
//Get user's choice
cout << "\n\nEnter your choice : ";
cin >> choice;
//if 999 entered the jump out of while loop to finish
if (choice == 999) break;
//act on users menu choice
switch (choice)
{
case 1:
GetInput();
break;
case 2:
DisplayValues();
break;
default:
ChoiceDefault();
break;
}
}
system("cls");
/*
This section was of no use, as it was just repeating the display
before exiting the program
//Write contents of global array to screen
// output contents of date array to file
for(j=0; j<10; j++)
{
for(k=0; k<9; k++)
{
cout << datearray[j][k];
}
cout << "\t" << balls[j][0] << "\t" << balls[j][2];
cout << "\n";
}
*/
//Write data from arrays out to Lottery file
ofstream outClientFile("Date.txt", ios:
ut); // open file for output
if(!outClientFile) // handle error if file cannot be opened
{
cerr << "File could not be opened" << endl;
exit(1);
}
// exiting program, so output contents of datearray and balls to
Date.txt file
for(i=0; i<52; i++)
{
outClientFile << datearray;
for (j=0;j<7;j++)
outClientFile << " " << balls[j];
outClientFile << endl;
}
}
// Function Definitions
void GetInput()
{
int inspoint;
int ball1int = 0;
int ball2int = 0;
int ball3int = 0;
int ball4int = 0;
int ball5int = 0;
int ball6int = 0;
int ball7int = 0;
int j;
char date[10];
system("cls");
cout << "\nEnter new date (dd/mm/yy) :";
cin >> date;
cout << "\nEnter First Lottery Number :";
cin >> ball1int;
cout << "\nEnter Second Lottery Number :";
cin >> ball2int;
cout << "\nEnter Third Lottery Number :";
cin >> ball3int;
cout << "\nEnter Fouth Lottery Number :";
cin >> ball4int;
cout << "\nEnter Fifth Lottery Number :";
cin >> ball5int;
cout << "\nEnter Sixth Lottery Number :";
cin >> ball6int;
cout << "\nEnter Bouns Ball :";
cin >> ball7int;
// Find insertion point
for(j=0; j<10; j++)
{
if (datearray[j][0] == '*')
{
inspoint = j;
cout << "inspoint = " << inspoint << endl;
break;
}
}
//Insert new date into datearray and new numbers into balls, global
arrays.
for(j=0; j<10; j++)
{
datearray[inspoint][j] = date[j];
}
balls[inspoint][0] = ball1int;
balls[inspoint][1] = ball2int;
balls[inspoint][2] = ball3int;
balls[inspoint][3] = ball4int;
balls[inspoint][4] = ball5int;
balls[inspoint][5] = ball6int;
balls[inspoint][6] = ball7int;
}
void DisplayValues()
{
int j, k;
//Write contents of global arrays (datearray and balls) to screen
for(j=0; j<10; j++)
{
for(k=0; k<10; k++)
{
cout << datearray[j][k];
}
for(k=0; k<7; k++)
{
cout << "\t" << balls[j][k];
}
cout << "\n";
}
}
void ChoiceDefault()
{
system("cls");
cout <<"\n\n\n\n\tYou entered a number not on menu Menu ";
cout << "\n\n\n\nPress return for Main Menu" << endl;
getchar();
}
void AnyKey()
{
char ch;
cout << "\n\nPress any Key to Continue" << endl;
ch=getch();
cout << endl;
}
allow user to modify existing draw data. I think I need a counter to
give week numbers so the user can select a week number rather than a
date.
I need to view data for a selected week given the week number or date.
need some controls on not allowing the ball number to go >49 or <0 and
no duplicates.
the date needs some work on so the user can only enter numbers not
letters.
any help would be great.
/**********************************************************************************************
*
* Carl's Assignment
*
*
*
* Here is a list of tasks to consider
* ___________________________________
*
* * Change the Display Routine to display the complete list of
* 52 Records simultaniously.
* You'll need to alter the count
*
* * Alter the Comments, and add extra ones
*
* * Write a Routine to edit an existing Record
*
* * Write a Routine that checks that the Ball Values entered are
within Range ( 1 - 49 )
*
* * Write a Routine that checks that no duplicate Ball Values are
entered
* (run this check after every entry)
*
* * THE BIG ONE - Write a Routine that checks the Date is valid
*
* * Think about what will happen when the Array is full & you put in
an additional Entry
*
*
***********************************************************************************************/
#include <iostream.h>
#include <math.h>
#include <process.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
// Function prototypes
void GetInput();
void DisplayValues();
void ChoiceDefault();
void AnyKey();
//Global variables (declared outside main() - so visable (i.e.
accessable) to whole program functions and all!
char datearray[53][10]; // 2-Dimensional array 52 rows, 9 columns.
int balls[53][36];
void main()
{
char date[10];
int choice=0, x=0, y=0;
int insertionPoint=0;
int i =0, j = 0, k = 0;
//initialise global 'datearray' as a string of asterixes and 'balls'
array with 0's
for(j=0; j<53; j++)
{
for(i=0; i<8; i++)
{
if (i == 8)
{
datearray[j] = '\0';//terminate string with null character
}
else
{
datearray[j] = '*';// initialise datarray with asterix
characters
}
for (int k=0;k<8;k++)
balls[k] = 0;
}
}
// open Date.txt file to get data from
ifstream inClientFile("Date.txt", ios::in); // open file for input
if(!inClientFile) // handle "could not open file" error
{
cerr << "File could not be opened" << endl;
exit(1);
}
// read data (date & two numbers) from Date.txt file
i=0; // must reset "i" to zero
while (inClientFile >> date)// read (next) "line" from file
{
for (k=0;k<7;k++)
inClientFile>>balls[k];
for(j=0; j<9; j++)
{
datearray[j] = date[j]; // copy date from 'date' tempory
variable into datearray
}
i++;
}
insertionPoint = i;//remember where to insert next new data
while (true)
{
// Clear screen
system("cls");
//Print Menu choices on screen
cout << "\n\n\t\tMENU:\n\n"<< "\t1 - Enter New Date\n"<< "\t2 - Print
out contents of global array on screen\n" << "\t999 - to exit";
//Get user's choice
cout << "\n\nEnter your choice : ";
cin >> choice;
//if 999 entered the jump out of while loop to finish
if (choice == 999) break;
//act on users menu choice
switch (choice)
{
case 1:
GetInput();
break;
case 2:
DisplayValues();
break;
default:
ChoiceDefault();
break;
}
}
system("cls");
/*
This section was of no use, as it was just repeating the display
before exiting the program
//Write contents of global array to screen
// output contents of date array to file
for(j=0; j<10; j++)
{
for(k=0; k<9; k++)
{
cout << datearray[j][k];
}
cout << "\t" << balls[j][0] << "\t" << balls[j][2];
cout << "\n";
}
*/
//Write data from arrays out to Lottery file
ofstream outClientFile("Date.txt", ios:
if(!outClientFile) // handle error if file cannot be opened
{
cerr << "File could not be opened" << endl;
exit(1);
}
// exiting program, so output contents of datearray and balls to
Date.txt file
for(i=0; i<52; i++)
{
outClientFile << datearray;
for (j=0;j<7;j++)
outClientFile << " " << balls[j];
outClientFile << endl;
}
}
// Function Definitions
void GetInput()
{
int inspoint;
int ball1int = 0;
int ball2int = 0;
int ball3int = 0;
int ball4int = 0;
int ball5int = 0;
int ball6int = 0;
int ball7int = 0;
int j;
char date[10];
system("cls");
cout << "\nEnter new date (dd/mm/yy) :";
cin >> date;
cout << "\nEnter First Lottery Number :";
cin >> ball1int;
cout << "\nEnter Second Lottery Number :";
cin >> ball2int;
cout << "\nEnter Third Lottery Number :";
cin >> ball3int;
cout << "\nEnter Fouth Lottery Number :";
cin >> ball4int;
cout << "\nEnter Fifth Lottery Number :";
cin >> ball5int;
cout << "\nEnter Sixth Lottery Number :";
cin >> ball6int;
cout << "\nEnter Bouns Ball :";
cin >> ball7int;
// Find insertion point
for(j=0; j<10; j++)
{
if (datearray[j][0] == '*')
{
inspoint = j;
cout << "inspoint = " << inspoint << endl;
break;
}
}
//Insert new date into datearray and new numbers into balls, global
arrays.
for(j=0; j<10; j++)
{
datearray[inspoint][j] = date[j];
}
balls[inspoint][0] = ball1int;
balls[inspoint][1] = ball2int;
balls[inspoint][2] = ball3int;
balls[inspoint][3] = ball4int;
balls[inspoint][4] = ball5int;
balls[inspoint][5] = ball6int;
balls[inspoint][6] = ball7int;
}
void DisplayValues()
{
int j, k;
//Write contents of global arrays (datearray and balls) to screen
for(j=0; j<10; j++)
{
for(k=0; k<10; k++)
{
cout << datearray[j][k];
}
for(k=0; k<7; k++)
{
cout << "\t" << balls[j][k];
}
cout << "\n";
}
}
void ChoiceDefault()
{
system("cls");
cout <<"\n\n\n\n\tYou entered a number not on menu Menu ";
cout << "\n\n\n\nPress return for Main Menu" << endl;
getchar();
}
void AnyKey()
{
char ch;
cout << "\n\nPress any Key to Continue" << endl;
ch=getch();
cout << endl;
}