Introduction
From my experience, I have realized that experience is the best teacher. By doing something repeatedly, you can improve your skills. The way you think can be altered and changed for the better.
By thinking past the normal average person on a daily basis, your thinking process can improve towards above normal. The ability to think faster and more logically is at our fingertips.
I have made a program that test you on math problems not ususally done on a normal basis. It will test you on 5 random problems and record you stats.
In this program, I really didn't post it up to show coding techniques or anything like that. I posted this because I wanted to show how experience would always have the advantage over studying books.
But on a coding level :
My program random choice of math problems relies on time.
I've made this source/header file so that i could have a little library of my own functions.
/*tools.cpp */
/*simple tools here and there that i've made to use in other projects*/
/*just things i find that i could use later */
/*include files */
#include "tools.h"
#include "stdafx.h"
/*this function returns a randomized number between */
/*1 and 20 with relations to the systems clock (milli) */
double low_rand()
{
/*initalize rand (double)*/
double rand = 0.0;
/*_timeb struct*/
struct _timeb time;
/*fills the timeb struct with data (current time)*/
_ftime(&time);
/*change whole number into an decimal form*/
/*example: 989 to .989 */
rand = (time.millitm * ((double).001));
/*times rand by 100 */
/*example: .989 to 98.8 */
rand = (rand * 100);
/*divides rand by 5 */
/*example: 98.9 to 19.78 */
rand = (rand / 5);
/*returns rand with is a number between 1 and 20*/
return rand;
}
/*this function returns a randomized number between */
/*1 and 1000 with relations to the systems clock (milli)*/
int high_rand()
{
/*_timeb struct*/
struct _timeb time;
/*fills the timeb struct with data (current time)*/
_ftime(&time);
/*returns the time (milli) as a random number*/
return time.millitm;
}
/*retrieves the current time from the system */
void timec(_stime &stime)
{
/*struct for system time*/
SYSTEMTIME time;
/*retrieves the local time*/
GetLocalTime(& time);
/*loads the _stime struct with the current time*/
stime.hour = time.wHour;
stime.min = time.wMinute;
stime.sec = time.wSecond;
stime.milli = time.wMilliseconds;
}
/*the input is a certain time and the output is */
/*the difference between that time and the current time*/
/*implemented in a stop watch manner */
_stime timer(_stime &stime)
{
/*copy the _stime given to the function to avoid mistakes between transfer of information*/
_stime calc_time = stime;
/*struct for system time*/
SYSTEMTIME time;
/*retrieves the local time*/
GetLocalTime(& time);
/*calculate the difference between current time and time given*/
/*calculate hour*/
if(calc_time.hour >= time.wHour)
{
calc_time.hour = calc_time.hour - time.wHour;
}
else
{
calc_time.hour = time.wHour - calc_time.hour;
}
/*calculate min*/
if(calc_time.min >= time.wMinute)
{
calc_time.min = calc_time.min - time.wMinute;
}
else
{
calc_time.min = time.wMinute - calc_time.min;
}
/*calculate sec*/
if(calc_time.sec >= time.wSecond)
{
calc_time.sec = calc_time.sec - time.wSecond;
}
else
{
calc_time.sec = time.wSecond - calc_time.sec;
}
/*calculate milli*/
if(calc_time.milli >= time.wMilliseconds)
{
calc_time.milli = calc_time.milli - time.wMilliseconds;
}
else
{
calc_time.milli = time.wMilliseconds - calc_time.milli;
}
/*return the difference between the current time and the given time*/
return (calc_time);
}
/*beg to end*/
int btoe(char *filename)
{
int lines = 0;
char search[255];
if(filename != NULL)
{
ifstream ifile(filename);
do
{
ifile.getline(search, 255);
++lines;
}while(ifile.eof() == 0);
ifile.close();
}
else
{
lines = -1;
}
return lines;
}
/*beg to space*/
int btos(char *filename)
{
int lines = 0;
char search[255];
bool reached_space = false;
if(filename != NULL)
{
ifstream ifile(filename);
do
{
ifile.getline(search, 255);
++lines;
if(ifile.eof() == 1)
{
reached_space = true;
}
}while(true != reached_space);
ifile.close();
}
else
{
lines = -1;
}
return lines;
}
/*search file for a sentence*/
int sfile(char *filename, char *sentence)
{
int lines = 0;
char search[255];
bool searching = true;
if(filename != NULL)
{
ifstream ifile(filename);
do
{
ifile.getline(search, 255);
++lines;
if(ifile.eof() == 1)
{
searching = false;
lines = -1;
}
}while(false != searching);
ifile.close();
}
else
{
lines = -1;
}
return lines;
}
/*gets the actual length of a c string (array)*/
int str_length(char str[], int length)
{
int str_size = 0;
for(int x = 0; x < length; ++x)
{
if(str[x] != 0)
{
++str_size;
}
else
{
break;
}
}
return str_size;
}
//////////////////////////////////////////////////////////////
the functions in this source/header file were used to manipulate the time and to do basic work on time related functions.
the code above is probably the most important part of the whole program, because it handles the time which is somewhat widely used.
--ice911
(thanks for checking out my article)