It’s my new project in C++.
About Cyber Chat:
Cyber Chat is an Artificial Intelligence chatter-bot that interacts with the user in simple English language and can simulate a conversation. It has a repository or knowledge-base of patterns, which are matched with the input to give the best possible reply. More generally, the technique which is used in the knowledge-base to represent the Cyber Chat knowledge is known as “Case Base Reasoning” or CBR.
It has a large database consisting of 22 files.
- Download Link
- Sample Chat-log
Please don’t ask me how this code works!
#include <iostream>
using namespace std;
void hanoi(int n, char source, char intermediate, char destination) {
if (n > 0) {
hanoi(n - 1, source, destination, intermediate);
cout << " - Moving disk " << n << " from " << source << " to " << destination << endl;
hanoi(n - 1, intermediate, source, destination);
}
}
int main() {
int n;
cout << "Enter the no. of disks: "; cin >> n;
hanoi(n, 'A', 'B', 'C');
return 0;
}

Functions:
checkRoots()
calculateRoots()
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int checkRoots(double A, double B, double C) {
int D = pow(B, 2) - 4 * A * C;
if (D > 0) {
return 0;
}
else {
return D;
}
}
void calculateRoots(double A, double B, double C) {
double x1, x2;
x1 = (- B + sqrt(pow(B, 2) - 4 * A * C)) / (2 * A);
x2 = (- B - sqrt(pow(B, 2) - 4 * A * C)) / (2 * A);
if (x1 != x2) {
cout << "1. X = " << setprecision(5) << x1 << endl;
cout << "2. X = " << setprecision(5) << x2 << endl;
}
else {
cout << "X = " << setprecision(5) << x1 << endl;
}
}
int main() {
double A, B, C;
cout << "Quadratic Equation Solver" << endl << endl;
cout << "A = "; cin >> A;
cout << "B = "; cin >> B;
cout << "C = "; cin >> C;
int result = checkRoots(A, B, C);
cout << endl;
if (result == 0) {
calculateRoots(A, B, C);
}
else {
cout << "Complex Roots" << endl;
cout << "[Discriminant = " << result << "]" << endl;
}
return 0;
}
If you need to do a certain task on all files or folders in a directory, the following code does the job. The following function recursively calls itself for all contained subfolders and prints all the files found. Note that this code will only run on Windows operating system as it uses Win32 API’s, namely FindFirstFile, FindNextFile and FindClose.
GetAllFiles() is called with the path of the base folder from where you want to start the enumeration.
Example Usage: GetAllFiles(“D:”);
Required Headers: <string> and <windows.h>
void GetAllFiles( string sPath )
{
WIN32_FIND_DATA FindFileData;
string sTmpPath = sPath;
sTmpPath += "\\*.*";
HANDLE hFind = FindFirstFile( sTmpPath.c_str(), &FindFileData );
if ( hFind == INVALID_HANDLE_VALUE )
return;
else {
do {
if ( ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) {
// if directory:
if ( strcmp(".", FindFileData.cFileName ) && strcmp("..", FindFileData.cFileName) ) {
sTmpPath = sPath;
sTmpPath += "\\";
sTmpPath += FindFileData.cFileName;
GetAllFiles( sTmpPath.c_str() );
}
}
else // if file:
{
sTmpPath = sPath;
sTmpPath += "\\";
sTmpPath += FindFileData.cFileName;
cout << sTmpPath << endl;
}
} while ( FindNextFile( hFind, &FindFileData) != 0 );
FindClose( hFind );
}
return;
}
Awhile ago, I was working on to create a bit array in order to compactly store individual boolean values. So that a typical 1 byte could be used to store an array of 8 boolean values (since each boolean value requires only one bit in order to be represented, i.e 0 or 1). This is a much better strategy, since on the other hand if we use simple array for storing 8 boolean values, it would take 8 bytes in memory instead of just one.
I created a class for this purpose which implemented this functionality and provided a clean interface to the user for using that array. However, I came to know later that such type of optimization is already done internally by the vector<bool> standard library, so it’s not particularly useful to code it ourselves.
I coded two functions for the purpose of setting individual bits ON or OFF in a byte. These functions perform the basic ON and OFF bit-wise operations and checking the status of a bit. So I thought it would be useful to share them with others too.
Functions for setting a particular bit ON or OFF in a byte:
Below is the code for the functions. This will give you some idea of how bit-wise operations can be used in C++ to perform some meaningful operation.
These functions do not return any values.
void setBitOn(unsigned int &value, int num) {
const int SHIFT = num;
const unsigned int MASK = 1 << SHIFT;
value = value | MASK;
}
void setBitOff(unsigned int &value, int num) {
const int SHIFT = num;
const unsigned int MASK = 1 << SHIFT;
value = value & (~MASK);
}
Function to check if a particular bit is ON or OFF:
bool checkBit(unsigned int value, int num) {
const int SHIFT = num;
const unsigned int MASK = 1 << SHIFT;
return ((value | MASK) == value ? true : false);
}
Parameters defined:
In these functions, int num parameter is the offset of the bit which is to be reset. Thus num = 0 would be the right-most bit in the byte.
While, value is an unsigned int on which the operation is to be performed.
Example usage of the functions:
int main() {
unsigned int x = 244;
setBitOn(x, 0); // set right-most bit to 1
for (int i = 7; i >=0; i--) {
cout << checkBit(x, i) ;
}
cout << endl;
return 0;
}
Output of the above code would be: 11110101. Note that the binary of 244 is 11110100.
That’s all. I hope you learnt something from my code.
Happy coding, 
Hassan