cmpslib
Functions
cmpslib19.h File Reference
#include <cxxabi.h>
#include <bitset>
#include <time.h>
#include <string>
#include <string.h>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <stdarg.h>
#include <typeinfo>
#include <limits.h>
#include <limits>
#include <ios>
#include <float.h>
#include <math.h>
#include <iomanip>
#include <stdexcept>
#include <signal.h>
#include <random>
#include <algorithm>
Include dependency graph for cmpslib19.h:

Go to the source code of this file.

Functions

void Prompt (string prompt, string &val)
 use to request input from the user More...
 
template<class T >
void Prompt (string prompt, T &val)
 use to request input from the user More...
 
template<class T >
void Prompt (string prompt, T &val, T minval, T maxval)
 use to request input from the user More...
 
bool PromptYN (string prompt)
 for simple yes or no questions More...
 
void WaitHundredth (int time)
 Do nothing for a period of time. More...
 
void ClearScreen ()
 clear the screen More...
 
char * GetTime ()
 get the time More...
 
string GetDateTime ()
 The DateTime as a string. More...
 
int StringToInteger (string input)
 convert string to int More...
 
double StringToDouble (string input)
 convert string to double More...
 
string ToLowerCase (string input)
 convert string to lowercase More...
 
string ToUpperCase (string input)
 convert string to uppercase More...
 
bool StringToBool (string input)
 convert string to bool More...
 
bool VeryClose (float A, float B, float epsilon=0.0005f)
 compare two floats More...
 
template<typename T >
string NumberToString (T Number)
 convert a numveric value to string More...
 
int CreateRandomNumber (int min, int max)
 create a random number More...
 
bool IsNumber (string str)
 can this string be converted to a numeric value More...
 
bool IsInteger (string input)
 can this string be converted to an integer numeric value More...
 
bool IsDouble (string input)
 can this string be converted to an double value More...
 
string PassFail (int in)
 convert bool value into "Pass" or "Fail" More...
 
string PF (int in)
 same as PassFail same as PassFail More...
 
template<class T >
bool IsSortedAscending (T *data, unsigned int size)
 is an array sorted a function that will tell you if an array is sorted More...
 
template<class T >
bool IsSortedDescending (T *data, unsigned int size)
 is an array sorted a function that will tell you if an array is sorted More...
 
string RED (string input)
 return a string formatted to display in color More...
 
string GREEN (string input)
 return a string formatted to display in color More...
 
string YELLOW (string input)
 return a string formatted to display in color More...
 
string BLUE (string input)
 return a string formatted to display in color More...
 
string MAGENTA (string input)
 return a string formatted to display in color More...
 
string CYAN (string input)
 return a string formatted to display in color More...
 
string ChangeToRed ()
 returns a string formated to display in a color and does not reset to white More...
 
string ChangeToGreen ()
 returns a string formated to display in a color and does not reset to white More...
 
string ChangeToYellow ()
 returns a string formated to display in a color and does not reset to white More...
 
string ChangeToBlue ()
 returns a string formated to display in a color and does not reset to white More...
 
string ChangeToMagenta ()
 returns a string formated to display in a color and does not reset to white More...
 
string ChangeToCyan ()
 returns a string formated to display in a color and does not reset to white More...
 
string ChangeToWhite ()
 returns a string formated to display in a color and does not reset to white More...
 
void PositionCursor (int row, int col)
 move the cursor to the position indcated by the row and column More...
 
template<typename T >
std::string GetClassName (const T &a)
 get the class name as a string for the object More...
 

Function Documentation

◆ BLUE()

string BLUE ( string  input)
inline

return a string formatted to display in color

returns a string same as the input but with some tags added so it will display the text and change back to white

◆ ChangeToBlue()

string ChangeToBlue ( )
inline

returns a string formated to display in a color and does not reset to white

returns a string that when pushed to std::cout will change the console output color
you will probably want to set it back white at some point

◆ ChangeToCyan()

string ChangeToCyan ( )
inline

returns a string formated to display in a color and does not reset to white

returns a string that when pushed to std::cout will change the console output color
you will probably want to set it back white at some point

◆ ChangeToGreen()

string ChangeToGreen ( )
inline

returns a string formated to display in a color and does not reset to white

returns a string that when pushed to std::cout will change the console output color
you will probably want to set it back white at some point

◆ ChangeToMagenta()

string ChangeToMagenta ( )
inline

returns a string formated to display in a color and does not reset to white

returns a string that when pushed to std::cout will change the console output color
you will probably want to set it back white at some point

◆ ChangeToRed()

string ChangeToRed ( )
inline

returns a string formated to display in a color and does not reset to white

returns a string that when pushed to std::cout will change the console output color
you will probably want to set it back white at some point

◆ ChangeToWhite()

string ChangeToWhite ( )
inline

returns a string formated to display in a color and does not reset to white

returns a string that when pushed to std::cout will change the console output color
you will probably want to set it back white at some point

◆ ChangeToYellow()

string ChangeToYellow ( )
inline

returns a string formated to display in a color and does not reset to white

returns a string that when pushed to std::cout will change the console output color
you will probably want to set it back white at some point

◆ ClearScreen()

void ClearScreen ( )
inline

clear the screen

clears the screen

◆ CreateRandomNumber()

int CreateRandomNumber ( int  min,
int  max 
)
inline

create a random number

create a random number

Parameters
minminimum value to return
maxmaximum value to return

◆ CYAN()

string CYAN ( string  input)
inline

return a string formatted to display in color

returns a string same as the input but with some tags added so it will display the text and change back to white

◆ GetClassName()

template<typename T >
std::string GetClassName ( const T &  a)
inline

get the class name as a string for the object

returns a string representation of the class name of the object

Parameters
athe object that you would like to get the class name of

◆ GetDateTime()

string GetDateTime ( )
inline

The DateTime as a string.

returns the date time as string YYYY-MM-DD-HH:mm:ss year-month-day-hour:minutes:seconds

◆ GetTime()

char* GetTime ( )
inline

get the time

returns the current time as a formatted char array
The returned string has the following format:
Www Mmm dd hh:mm:ss yyyy
Where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year.
The C string is followed by a new-line character and the terminating null-character.

◆ GREEN()

string GREEN ( string  input)
inline

return a string formatted to display in color

returns a string same as the input but with some tags added so it will display the text and change back to white

◆ IsDouble()

bool IsDouble ( string  input)
inline

can this string be converted to an double value

tests to see if the string could be converted to a double value
retrurns true if so , false otherwise

◆ IsInteger()

bool IsInteger ( string  input)
inline

can this string be converted to an integer numeric value

tests to see if the string could be converted to a integer value
retrurns true if so , false otherwise

◆ IsNumber()

bool IsNumber ( string  str)
inline

can this string be converted to a numeric value

tests to see if the string could be converted to a numeric value
retrurns true if so , false otherwise

◆ IsSortedAscending()

template<class T >
bool IsSortedAscending ( T *  data,
unsigned int  size 
)
inline

is an array sorted a function that will tell you if an array is sorted

Parameters
datapointer to an array
sizethe size of the array
int array1 ={1,2,3,4,5};
int array2 ={5,4,3,2,1};
int result = IsSortedAscentding(array1,5);
// result will contain true
int result = IsSortedAscentding(array2,5);
// result will contain false

◆ IsSortedDescending()

template<class T >
bool IsSortedDescending ( T *  data,
unsigned int  size 
)
inline

is an array sorted a function that will tell you if an array is sorted

Parameters
datapointer to an array
sizethe size of the array
int array1 ={1,2,3,4,5};
int array2 ={5,4,3,2,1};
int result = IsSortedDescending(array1,5);
// result will contain false
int result = IsSortedDescending(array2,5);
// result will contain true

◆ MAGENTA()

string MAGENTA ( string  input)
inline

return a string formatted to display in color

returns a string same as the input but with some tags added so it will display the text and change back to white

◆ NumberToString()

template<typename T >
string NumberToString ( Number)
inline

convert a numveric value to string

this will try to convert a double,int or float to a string
may throw and exception if it cant do it

◆ PassFail()

string PassFail ( int  in)
inline

convert bool value into "Pass" or "Fail"

used to test some of our fuctions
simply returns a string for our tests

int x = 5;
MakeAValue2TimesWhatItWas(x);
// if our function did indeed make the value of x 2 times what it was it should contain 10 now
cout << PassFail( x == 10) << endl; // will display Pass or Fail depending on the expression x==10

◆ PF()

string PF ( int  in)
inline

same as PassFail same as PassFail

◆ PositionCursor()

void PositionCursor ( int  row,
int  col 
)
inline

move the cursor to the position indcated by the row and column

move the cursor to the position indcated by the row and column Note the offset is 1 not 0 any cout statemets after this funcion is called will start displaying at the new location

◆ Prompt() [1/3]

void Prompt ( string  prompt,
string &  val 
)
inline

use to request input from the user

displays the first parameter "text" to the console
take in input from the user and store it in the second parameter
this version is specific for string datatype
it will read in an entire line of text including spaces

Parameters
promptthe value (message) to be displayed to the user
valthe destination where the user input is stored
string name;
Prompt("what is your first name?",name);
// the user input value is now stored in name

◆ Prompt() [2/3]

template<class T >
void Prompt ( string  prompt,
T &  val 
)
inline

use to request input from the user

displays the first parameter "text" to the console
take in input from the user and store it in the second parameter
if the input does not match the datatype of the second parameter
the function will request the user enter the value again

Parameters
promptthe value (message) to be displayed to the user
val(PBR) the destination where the user input is stored
int puppies;
Prompt("How many puppies would you like?",puppies);
// the user input value is now stored in puppies
double apples;
Prompt("How many kilos of apples would you like?",apples);
// the user input value is now stored in apples

◆ Prompt() [3/3]

template<class T >
void Prompt ( string  prompt,
T &  val,
minval,
maxval 
)
inline

use to request input from the user

displays the first parameter "text" to the console
take in input from the user and store it in the second parameter
if the input does not match the datatype of the second parameter
the function will request the user enter the value again

Parameters
promptthe value (message) to be displayed to the user
val(PBR) the destination where the user input is stored
minvalminimum acceptable value
maxvalmaximum acceptable value
int puppies;
Prompt("How many puppies would you like?",puppies,0,4);
// the user input value is now stored in puppies
// the function will only complete when the user has entered a value between 0 and 4

◆ PromptYN()

bool PromptYN ( string  prompt)
inline

for simple yes or no questions

displays the first parameter "text" to the console
the function will repeat asking till the user types Y,y,N or n

Parameters
promptthe value (message) to be displayed to the user
bool result;
result = PromptYN("do you wish to play again?");

◆ RED()

string RED ( string  input)
inline

return a string formatted to display in color

returns a string same as the input but with some tags added so it will display the text and change back to white

◆ StringToBool()

bool StringToBool ( string  input)
inline

convert string to bool

true,TRUE,TruE or 1 return true false,FALSE,FaLsE or 0 return false

◆ StringToDouble()

double StringToDouble ( string  input)
inline

convert string to double

this will try to convert a string to in double may throw and exception if it cant do it

◆ StringToInteger()

int StringToInteger ( string  input)
inline

convert string to int

this will try to convert a string to in integer may throw and exception if it cant do it

◆ ToLowerCase()

string ToLowerCase ( string  input)
inline

convert string to lowercase

convert an std:string to all lowercase values

◆ ToUpperCase()

string ToUpperCase ( string  input)
inline

convert string to uppercase

convert an std:string to all uppercase values

◆ VeryClose()

bool VeryClose ( float  A,
float  B,
float  epsilon = 0.0005f 
)
inline

compare two floats

compare some floating point numbers
this should work for type double as well
it is difficult to compare for equality so this will tell us if they are within
a distance of each other the default for that value is .0005

◆ WaitHundredth()

void WaitHundredth ( int  time)
inline

Do nothing for a period of time.

used to slow the operation of programs
25 -> quarter of a second, 50 -> half a second

Parameters
timewait time will be approximatley in 100ths of a second

◆ YELLOW()

string YELLOW ( string  input)
inline

return a string formatted to display in color

returns a string same as the input but with some tags added so it will display the text and change back to white