Following are some C++ code which could be used as methods inside a class or as functions
and procedures at a structure design program.
int MyLibrary::GetRandomNo() /*This method create a random no in range of 1 to 10000(change this no to get the random no in that range)
and return it.*/
{
int randomNo;
int MyLibrary::StringToInteger(string Key) /* this method converts a string to an integer. It assumed the integer is in range
of 1 to 10000. */
{
int Len;
bool KeyOk = true;
int num;
int mulby;
int intKey=0;
Len = Key.length(); // to get string length
for(int i=0; i < Len; ++i)
{ /*if any characters in the string is not a digit the whole string
is not an integer. */
if(isdigit(Key[i]) == false )
KeyOk = false; //the string is not an integer
}
if(KeyOk == true) // if the string is an integer
{
for(int j=0; j < Len; ++j) // change key from string to integer
{
num = GetInt(Key[j]); // get the equivalent integer number for
each individual character
mulby = GetFactor(Len - j); // get the number to be multiply by
intKey = intKey + (num * mulby); // in process to integer number
}
}
return intKey; // return the completed integer number
}
int MyLibrary::GetInt(char ch) // this method converts a character number to an integer.
{
return (int(ch) - int('0'));
}
Search
at TigerDirect.com:
int MyLibrary::GetFactor(int Factor) /* this method return a number for multiplication. Factor is the position of a
number in its integer number. */
{
int num;
/* Factor can not be more than 5, because GetRandomNo() method creates
a random number in the range of 1 to 10000.*/
switch (Factor)
{
case 5: num = 10000; // if a digit in string has the poistion of 5
break;
case 4: num = 1000; // if a digit in string has the poistion of 4
break;
case 3: num = 100; // if a digit in string has the poistion of 3
break;
case 2: num = 10; // if a digit in string has the poistion of 2
break;
case 1: num = 1; // if a digit in string has the poistion of 1
break;
}
return num;
}
57% OFF
28% OFF
Software Development Life Cycle
Software Development Life Cycle
The Common Reuse Principle: CClasses that aren't reused together should not be grouped together.
Free C++ Program Free C++ Code Free C++ Program Free C++ Source Code C++ Program Example C++ Program Sample
Free C++ Program Free C++ Code Free C++ Source Code Free C++ Code Free C++ Program Free C++ Download
Free C++ Source Code Free C++ Code Free C++ Program C++ Program Example C++ Program Sample C++ Program Example
C++ Program Sample Free C++ Source Code Free C++ Download C++ Program Example