Friday, April 2, 2010

Program to Solve "System of Linear Equations" using Matrix Class Library

//Linear.cpp
//first save Matrix.h and Matrix.cpp files

#include "iostream.h"
#include "conio.h"
#include "stdlib.h"
#include "dos.h"
#include "string.h"
#include "fstream.h"
#include "matrix.h"

class menu
{
private:
short choice;

public:
menu() {}
friend void logo();
friend void main_menu();
void help();
int get_choice();
};

void logo()
{
cout << "\n\t\t **********************************" << endl;
cout << "\t\t * ---------------------- *" << endl;
cout << "\t\t * SYSTEM OF LINEAR EQUATIONS *" << endl;
cout << "\t\t * ---------------------- *" << endl;
cout << "\t\t **********************************" << endl << endl;
};

void main_menu()
{
cout << "\t ----------------------------------\n\n";
cout << "\t\t 1. START PROGRAM\n" << endl;
cout << "\t\t 2. CALCULATE FROM FILE\n" << endl;
cout << "\t\t 3. HELP\n" << endl;
cout << "\t\t 0. Exit\n" << endl;
cout << "\t\t ----------------------------------\n\n";
cout << "\t\t\t Enter Choice (0/1/2/3) : \n";
}

void menu :: help()
{
clrscr();
cout << "\t\t***************** HELP ****************\n\n";
cout << "This program solves Linear equations of the form ax + by + cz+............mn \n";
cout << "using Cramer's Rule.Enter Coefficient and Input matrix and the program will\n";
cout << "Calculate the Results for you.";
cout << "\n\n\n\t************* How to read the matrix from file ? *************\n\n";
cout << "1. First Save the Size of the Matrix in a file (Text file).\n";
cout << "2. Save the Coefficient Matrix after some line.\n";
cout << "3. Save the Input Matrix after some line.\n";
cout << "4. Every Data must be written after a Blank Space.\n";
cout << "5. In a Program Enter Filename with Extension.\n";
cout << "6. Hit Enter.\n";
cout << "\n\n\n\n\n\n\t\t\tPress any key to continue...";
getch();
}

int menu :: get_choice()
{
gotoxy(53,20);
cin >> choice;
return choice;
}

class linear
{
private:
unsigned short un; //Private Data

public:

float *input; //Pubilc Data

//Constructors

linear() {}
linear(int a)
{
un = a;
input = new float[un];
}

//Functions

int getsize()
{ return un; }

void solve_from_program();
void solve_from_file();
friend double solve(matrix ,float[],int);
void save_to_file();
~linear()
{delete input;}
};

double solve(matrix m,float f[],int pos)
{
matrix temp;
double d,d1;
temp = m;
d = determinant(temp);
if(d == 0)
{
cout << "\nNo Solution - Delta is Zero.";
exit(0);
}

int k = 0;
for(int i = 0;i < temp.row;i++)
for(int j = 0;j < temp.col;j++)
if(j == pos)
temp.mat[i][j] = f[k++];

else
temp.mat[i][j] = m.mat[i][j];

d1 = determinant(temp);
return (d1/d);

}

//Global Variables
char *fname;
float *coefValue,*inputValue,*output;
int unknowns;

void linear :: save_to_file()
{
//Create a file
ofstream destination;
cout << "\n\n\n";
cout.width(53);
cout << "Enter Filename With Extension : ";
cin >> fname;
destination.open(fname);
if(destination.fail())
{
cout << "\nError on Creating a File.";
getch();
exit(0);
}

//Write to file
destination << "Unknowns : " << unknowns << endl << endl; //Unknowns

destination << "Coefficient Matrix" << endl << endl;
for(int i = 0;i < unknowns * unknowns;i++) //Coefficeint Matrix
{
destination << coefValue[i] << ' ';
if((i+1) % unknowns == 0)
destination << endl;
}

destination << endl << endl;
destination << "Input Matrix" << endl << endl;
for(i = 0;i < unknowns;i++) //Input Matrix
destination << inputValue[i] << ' ';

destination << endl << endl;
destination << "Output Matrix" << endl << endl;
for(i = 0;i < unknowns;i++) //Output Matrix
destination << output[i] << '\t';

if(destination.good())
{
cout << "\n\n\n\n\n";
cout.width(53);
cout << "Data Saved Successfully.\n";
cout.width(54);
cout << "Press any key to continue...";
}

//Close File
destination.close();
}

void linear :: solve_from_program()
{
clrscr();
int u,as = 65;
char var[7],varTemp[7];
cout << "How Many Unknowns ? ";
cin >> u;
unknowns = u;
linear l(u); //Dynamic Constructor initialization
double d,value;
matrix coef(u,u),temp;

coefValue = new float[u * u];
inputValue = new float[u];
output = new float[u];

cout << "\nEnter Coefficient Matrix:\n";
cin >> coef;

int k = 0;
for(int i = 0;i < u;i++)
for(int j = 0;j < u;j++)
coefValue[k++] = coef.getvalue(i,j);

cout << "\nEnter Input Matrix:\n";
for(i = 0;i < l.getsize();i++)
{
cin >> l.input[i];
inputValue[i] = l.input[i];
}

temp = coef;
cout << endl << "Output Matrix\n\n";
for(i = 0;i < l.getsize();i++)
{
itoa((i+1),varTemp,10);
strcpy(var,"X");
strcat(var,varTemp);
value = solve(temp,l.input,i);
output[i] = value;
cout << var << " = " << value << endl;
as++;
}

cout << "\n\n\n\n\n";
cout.width(47);
cout << "Press S to Save..." << endl;
cout.width(57);
cout << "Press any other key to continue...";

char choice;
choice = getch();
if(choice == 's' || choice == 'S')
{
clrscr();
linear l;
l.save_to_file();
getch();
}

}

void linear :: solve_from_file()
{
clrscr();
ifstream source;
char filename[10],temp[10],var[7],varTemp[7];
unsigned short i,j,k = 0,tmp = 0,u,as = 65;
float value,*hold;
cout << "Enter Filename With Extension (must be a Notepad File): ";
cin >> filename;
source.open(filename);
if(source.fail())
{
cout << "\n\n\n\n\n";
cout.width(50);
cout << "Unable to Open File." << endl;
cout.width(54);
cout << "Press any key to continue...";
getch();
return;
}

cout << "\nHow Many Unknowns ? ";
source >> u;
cout << u << endl;
unknowns = u;
linear l(u);
matrix coef(u,u);
hold = new float[u * u];
coefValue = new float[u * u];
inputValue = new float[u];
output = new float[u];
j = 0;
float f;
for(i = 0;i < (u * u);i++)
{
source >> f;
hold[j++] = f;
source.ignore();
}

for(i = 0;i < u;i++)
for(j = 0;j < u;j++)
{
coefValue[k] = hold[k];
coef.putvalue(i,j,hold[k++]);
}

cout << "\nCoefficient Matrix:\n";
cout << coef;
tmp = 0;
while(u != tmp)
{
source >> f;
inputValue[tmp] = f;
l.input[tmp++] = f;
source.ignore();
}

cout << "\nInput Matrix\n";
for(i = 0;i < u;i++)
cout << l.input[i] << '\t';

cout << endl << "\nOutput Matrix\n\n";
for(i = 0;i < l.getsize();i++)
{
itoa((i+1),varTemp,10);
strcpy(var,"X");
strcat(var,varTemp);
value = solve(coef,l.input,i);
output[i] = value;
cout << var << " = " << value << endl;
as++;
}

cout << "\n\n\n\n\n";
cout.width(47);
cout << "Press S to Save..." << endl;
cout.width(57);
cout << "Press any other key to continue...";

char choice;
choice = getch();
if(choice == 's' || choice == 'S')
{
clrscr();
linear l;
l.save_to_file();
getch();
}

source.close();
}

int main()
{
menu m;
linear l;
do
{
clrscr();
logo();
main_menu();
short choice = m.get_choice();
switch(choice)
{
case 0:
clrscr();
cout << "\n\n\n\n\n\n\n\n\n\n";
cout.width(56);
cout << "System of Linear Equations.\n\n";
cout.width(56);
cout << "A Project by Ankit Pokhrel.\n\n";
cout.width(57);
cout << "Thank You for Using This Program.";
delay(1200);
return EXIT_SUCCESS;

case 1:
l.solve_from_program();
break;

case 2:
l.solve_from_file();
break;

case 3:
m.help();
break;

default:
cout << "\n\t\t\tPlease select appropriate option.";
delay(1000);
break;
}

}while(1);

}

Matrix Class Library

/******** Class Matrix :: Declaration Part ********/
// Matrix.h

template
class matrix
{
public:
//Data
T **mat;
short row,col;

//Constructors
matrix ();
matrix (short,short);
matrix (matrix &);

//Input and Output Stream
friend istream & operator >> (istream &,matrix &);
friend ostream & operator << (ostream &,matrix &);

//Arithmatics Operators
matrix operator + (matrix);
matrix operator - (matrix);
matrix operator - ();
friend matrix operator * (matrix,matrix);
friend matrix operator * (T,matrix &);
friend matrix operator * (matrix &,T);
double operator / (matrix);
friend matrix operator / (matrix &,T);

//Increment and Decrement Operators
matrix operator ++ ();
matrix operator ++ (int);
matrix operator -- ();
matrix operator -- (int);

//Shorthand Operators
void operator += (matrix &);
void operator -= (matrix &);
void operator *= (T);
void operator /= (T);

//Equality Operators
int operator == (matrix);
int operator != (matrix);

//Other Calculations

friend matrix transpose(matrix);
friend double determinant(matrix);
friend float tr(matrix); //Trace of a Matrix
friend int issymmetric(matrix);
friend int isskewsymmetric(matrix);
void putvalue(short,short,T);
T getvalue(short,short);

//Destructor
virtual ~matrix();
};

//Function Definitions
//Matrix.cpp

#include "iostream.h"
#include "conio.h"
#include "stdlib.h"
#include "matrix.h"

/********** Class Matrix :: Implementation Part ***********/

enum _bool {FALSE,TRUE};

template
matrix :: matrix () {} // Default Constructor

template
matrix :: matrix (short m,short n) // Parameterized Constructor
{
row = m;
col = n;

if(row < 0 || row > 10)
{
cout << "\nError: Bad Row";
exit(0);
}

if(col < 0 || col > 10)
{
cout << "\nError: Bad Column";
exit(0);
}

mat = new T *[row];
for(int i = 0;i < row;i++)
mat[i] = new T[col];

}

template
matrix :: matrix (matrix &m) // Copy Constructor
{
row = m.row;
col = m.col;

mat = new T *[row];
for(int i = 0;i < row;i++)
mat[i] = new T[col];

for(i = 0;i < row;i++)
for(int j = 0;j < col;j++)
mat[i][j] = m.mat[i][j];

}

template
void matrix :: putvalue (short i,short j,T f)
{
mat[i][j] = f;
}

template
T matrix :: getvalue (short i,short j)
{
return mat[i][j];
}

template
istream & operator >> (istream & ain,matrix & m)
{
for(int i = 0;i < m.row;i++)
for(int j = 0;j < m.col;j++)
ain >> m.mat[i][j];
return ain;
}

template
ostream & operator << (ostream & aout ,matrix & m)
{
for(int i = 0;i < m.row;i++)
{
for(int j = 0;j < m.col;j++)
aout << m.mat[i][j] <<'\t';
aout << endl;
}

return aout;
}

template
matrix matrix :: operator + (matrix m)
{
if((row != m.row) || (col != m.col))
{
cout << "Error: Order Mismatch.";
exit(0);
}

matrix temp(row,col);
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
temp.mat[i][j] = mat[i][j] + m.mat[i][j];

return temp;
}

template
matrix matrix :: operator - (matrix m)
{
if((row != m.row) || (col != m.col))
{
cout << "Error: Order Mismatch.";
exit(0);
}

matrix temp(row,col);
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
temp.mat[i][j] = mat[i][j] - m.mat[i][j];

return temp;
}

template
matrix matrix :: operator - ()
{
matrix temp(row,col);
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
temp.mat[i][j] = -mat[i][j];

return temp;
}

template
matrix operator * (matrix n,matrix m)
{
if(n.col != m.row)
{
cout << "Error : Column of First Matrix Must be Equal to the Row of Second Matrix\n";
exit (0);
}

matrix temp(n.row,m.col);
matrix x = n;
matrix y = m;

for(int i = 0;i < n.row;i++)
for(int j = 0;j < m.col;j++)
{
temp.mat[i][j] = 0.0;

for(int k = 0;k < m.col;k++)
temp.mat[i][j] += x.mat[i][k] * y.mat[k][j];
}

return temp;
}

template
matrix operator * (T n,matrix &m)
{
matrix temp(m.row,m.col);
for(int i = 0;i < m.row;i++)
for(int j = 0;j < m.col;j++)
temp.mat[i][j] = n * m.mat[i][j];

return temp;
}

template
matrix operator * (matrix &m,T n)
{
matrix temp(m.row,m.col);
for(int i = 0;i < m.row;i++)
for(int j = 0;j < m.col;j++)
temp.mat[i][j] = m.mat[i][j] * n;

return temp;
}

template
matrix operator / (matrix &m,T n)
{
matrix temp(m.row,m.col);
for(int i = 0;i < m.row;i++)
for(int j = 0;j < m.col;j++)
temp.mat[i][j] = m.mat[i][j] / n;

return temp;
}

template
matrix matrix :: operator ++ ()
{
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
++mat[i][j];

return *this;
}

template
matrix matrix :: operator ++ (int)
{
matrix temp(row,col);
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
temp.mat[i][j] = mat[i][j];

for(i = 0;i < row;i++)
for( j = 0;j < col;j++)
mat[i][j]++;

return temp;
}

template
matrix matrix :: operator -- ()
{
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
--mat[i][j];

return *this;
}

template
matrix matrix :: operator -- (int)
{
matrix temp(row,col);
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
temp.mat[i][j] = mat[i][j];

for(i = 0;i < row;i++)
for(j = 0;j < col;j++)
mat[i][j]--;

return temp;
}

template
void matrix :: operator += (matrix &m)
{
if((row != m.row) || (col != m.col))
{
cout << "Error: Order Mismatch.";
exit(0);
}

for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
mat[i][j] += m.mat[i][j];
}

template
void matrix :: operator -= (matrix &m)
{
if((row != m.row) || (col != m.col))
{
cout << "Error: Order Mismatch.";
exit(0);
}

for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
mat[i][j] -= m.mat[i][j];

}

template
void matrix :: operator *= (T n)
{
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
mat[i][j] *= n;
}

template
void matrix :: operator /= (T n)
{
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
mat[i][j] /= n;
}

template
int matrix :: operator == (matrix m)
{
int isequal;
if((row != m.row) || (col != m.col))
isequal = FALSE;

else
{
isequal = TRUE;
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
if(mat[i][j] != m.mat[i][j])
{
isequal = FALSE;
break;
}
}

if(isequal)
return 1;
else
return 0;
}

template
int matrix :: operator != (matrix m)
{
int isequal;
if((row != m.row) || (col != m.col))
isequal = FALSE;

else
{
isequal = TRUE;
for(int i = 0;i < row;i++)
for(int j = 0;j < col;j++)
if(mat[i][j] != m.mat[i][j])
{
isequal = FALSE;
break;
}
}

if(!isequal)
return 1;
else
return 0;
}

template
matrix transpose(matrix m)
{
matrix temp(m.col,m.row);
for(int j = 0;j < m.col;j++)
for(int i = 0;i < m.row;i++)
temp.mat[j][i] = m.mat[i][j];

return temp;

}

template
float tr(matrix m) //Trace of a Matrix
{
float f = 0.0;
if(m.row != m.col)
{
cout << "\nError: Must be Square Matrix to find a Trace";
exit(0);
}

for(int i = 0;i < m.row;i++)
f += m.mat[i][i];

return f;
}

template
int issymmetric(matrix m)
{
int isequal = FALSE;
matrix temp(m.col,m.row);
temp = transpose(m);
if(m == temp)
isequal = TRUE;

if(isequal)
return 1;
else
return 0;
}

template
int isskewsymmetric(matrix m)
{
int isequal = FALSE;
matrix temp(m.col,m.row);
temp = transpose(m);
temp = -temp;
if(m == temp)
isequal = TRUE;

if(isequal)
return 1;
else
return 0;
}

template
double determinant(matrix m)
{
matrix temp;
temp = m;

int i, j, k;
double factor,result = 1.0;

for(k=0; k < temp.row-1; k++)
{
for(i=k+1; i < temp.row; i++)
{
factor = temp.mat[i][k]/temp.mat[k][k];
for(j=0; j < temp.col; j++)
temp.mat[i][j] -= factor*temp.mat[k][j];

}
}

for(i = 0;i < temp.row;i++)
result *= temp.mat[i][i];

return result;
}

template
double matrix :: operator / (matrix m)
{
double num,den,value;
num = determinant(*this);
den = determinant(m);
if(den == 0)
{
cout << "Error : Cannot Divide by Zero";
exit(0);
}

value = double(num)/den;

return value;
}


/*template
matrix :: ~matrix()
{
for(int i = 0;i < row;i++)
delete mat[i];

delete mat;
}*/

template
matrix :: ~matrix() {}

Text Encryption and Decryption (Cryptograph)

/*******************************************************
APPLICATION : Cryptograph
CODED BY : Ankit Pokhrel
COMPILED ON : Borland Turbo C++ Ver 3.0
DATE : 2009 - 12 - 17
********************************************************/

#include "iostream.h"
#include "conio.h"
#include "process.h"
#include "string.h"
#include "fstream.h"

class encrypt
{
private:
fstream source,target;
char filename[31],temp[31];

public:
encrypt()
{
strcpy(filename,"");
strcpy(temp,"");
}

int check_cndn();
void encode (void);
};

class decrypt
{
private:
fstream source,target;
char filename[31],temp[31];

public:
decrypt()
{
strcpy(filename,"");
strcpy(temp,"");
}

int check_cndn(void);
void decode (void);

};

// Class Encrypt Section

int show_menu()
{

cout << "\n\t\t **********************************" << endl;
cout << "\t\t * ---------------------- *" << endl;
cout << "\t\t * TEXT ENCRYPTION AND DECRYPTION *" << endl;
cout << "\t\t * ---------------------- *" << endl;
cout << "\t\t **********************************" << endl << endl;
cout << "\t ----------------------------------\n\n";
cout << "\t\t\t 1. ENCRYPT DATA\n" << endl;
cout << "\t\t\t 2. DECRYPT DATA\n" << endl;
cout << "\t\t\t 0. Exit\n" << endl;
cout << "\t\t ----------------------------------\n\n";
cout << "\t\t\t Enter Choice (0/1/2) : \n";

int choice;
gotoxy(51,18);
cin >> choice;

cout << endl << "\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";

return choice;

}

int encrypt :: check_cndn()
{
int i;
gotoxy(23,30);
cout << "WARNING : Enter Filename With Extension.";
gotoxy(24,32);
cout << "File Will Be Saved as FILENAME(En)";
gotoxy(15,34);
cout << "If File is Located in another Location Give Full Path to File";
gotoxy(10,22);
cout << "\t\t Enter Filename to Encode : ";
cin >> filename;
source.open(filename,ios::in);
if(source.fail())
{
cout << "\n\t\t\t\tSourcefile Doesn't Exist...";
getch();
return 0;
}

i = 0;
while(filename[i] != '.' || filename[i] == '\0')
temp[i] = filename[i++];
temp[i] = '\0';


strcat(temp,"(En)");

char tempc[6];
i = 0;
int j = 0;
while(filename[i] != '\0')
{
if(filename[i] == '.')
while(filename[i] != '\0')
tempc[j++] = filename[i++];

if(filename[i] == '\0')
--i;
else
i++;
}

tempc[j] = '\0';

strcat(temp,tempc);

target.open(temp,ios::out);
if(target.fail())
{
target.open(temp,ios::out);
if(target.fail())
{
cout << endl << "\t\t\t\tCouldn't Create File...\n";
getch();
return 0;
}
}

return 1;
}


void encrypt :: encode()
{
char ch = ' ',ctemp;
while(ch != EOF)
{
source.get(ch);
if(ch != EOF)
{
ctemp = ch + 0160;
target.put(ctemp);
}
}

source.close();
target.close();

cout << "\n\t\t\t\tData Encoded Successfully.";
getch();
}

// Class Decrypt Section

int decrypt :: check_cndn()
{
int i;
gotoxy(15,30);
cout << "WARNING : Use Files Encoded From This Program to Decode";
gotoxy(10,22);
cout << "\t\t Enter Filename to Decode : ";
cin >> filename;

source.open(filename,ios::in);
if(source.fail())
{
cout << "\n\t\t\t\tSourcefile Doesn't Exist...";
getch();
return 0;
}

i = 0;
while(filename[i] != '.' || filename[i] == '\0')
temp[i] = filename[i++];
temp[i] = '\0';


strcat(temp,"(De)");
char tempc[6];
i = 0;
int j = 0;
while(filename[i] != '\0')
{
if(filename[i] == '.')
while(filename[i] != '\0')
tempc[j++] = filename[i++];

if(filename[i] == '\0')
--i;
else
i++;
}

tempc[j] = '\0';

strcat(temp,tempc);
target.open(temp,ios::out);
if(target.fail())
{
target.open(temp,ios::out);
if(target.fail())
{
cout << endl << "\n\t\t\t\tERROR : Couldn't Create File...\n";
getch();
return 0;
}
}

return 1;
}

void decrypt :: decode()
{
char ch,ctemp;
do
{
source.get(ch);
ctemp = ch - 0160;
if(ctemp != EOF)
target.put(ctemp);

}while(ch != EOF);

source.close();
target.close();

cout << "\n\t\t\t\tData Decoded Successfully.";
getch();
}

int main()
{

int success,choice;
encrypt e;
decrypt d;

do
{
clrscr();
choice = show_menu();
if(choice == 1)
{
success = e.check_cndn();
if(success)
e.encode();
}

else if(choice == 2)
{
success = d.check_cndn();

if(success)
d.decode();
}

else if(choice == 0)
{
cout << "\t\t\tThank You For Using This Program.";
cout << "\n\n\t\t\t Press any Key to halt...";
}


else
{
cout << "\t\t\tPlease Select Apporopriate Option.\n\n";
cout << "\t\t\t Press any key to continue...";
getch();
}

}while(choice != 0);

getch();
return 0;
}

Hangman (GAME)

/*******************************************************
APPLICATION : HANGMAN (The Game)
CODED BY : Ankit Pokhrel
COMPILED ON : Borland Turbo C++ Ver 3.0
DATE : 2009 - 12 - 06
********************************************************/

#include "iostream.h"
#include "stdio.h"
#include "graphics.h"
#include "conio.h"
#include "dos.h"
#include "stdlib.h"
#include "string.h"
#include "ctype.h"

const int UP = 72;
const int DOWN = 80;
const int ENTER = 13;
const int ESC = 27;

int face()
{
int midx = getmaxx()/2;
int midy = getmaxy()/2,i,shift;

delay(1000);
for(i = 0;i <= 10;i++) { setcolor(RED); settextstyle(10,0,i); outtextxy(50,20,"HANG"); delay(90); setcolor(BLACK); settextstyle(10,0,i); outtextxy(50,20,"HANG"); } setcolor(RED); settextstyle(10,0,i); outtextxy(50,20,"HANG"); shift = 0; for(i = 0;i <= 10;i++) { setcolor(RED); settextstyle(10,0,10); outtextxy(midx - 220,shift,"MAN"); delay(5); setcolor(BLACK); settextstyle(10,0,10); outtextxy(midx - 220,shift,"MAN"); shift+=15; } setcolor(BLUE); settextstyle(10,0,10); outtextxy(100,200,"MAN"); setcolor(RED); settextstyle(10,0,10); outtextxy(50,20,"HANG"); for(i = 6;i >= 2;i--)
{
setcolor(LIGHTBLUE);
settextstyle(9,0,i);
outtextxy(midx - 100,20,"THE");
delay(90);
setcolor(BLACK);
settextstyle(9,0,i);
outtextxy(midx - 100,20,"THE");
}

setcolor(RED);
settextstyle(10,0,10);
outtextxy(50,20,"HANG");

setcolor(LIGHTBLUE);
settextstyle(9,0,i);
outtextxy(midx - 100,20,"THE");

for(i = 6;i >= 2;i--)
{
setcolor(GREEN);
settextstyle(9,0,i);
outtextxy(midx-50,20,"GAME");
delay(90);
setcolor(BLACK);
settextstyle(9,0,i);
outtextxy(midx-50,20,"GAME");
}

setcolor(GREEN);
settextstyle(9,0,i);
outtextxy(midx-50,20,"GAME");

delay(800);

setcolor(BLACK);
settextstyle(9,0,1);
outtextxy(midx - 100,20,"THE");

setcolor(BLACK);
settextstyle(9,0,1);
outtextxy(midx - 50,20,"GAME");

setcolor(LIGHTBLUE);
settextstyle(9,0,1);
outtextxy(midx - 90,10,"THE");

setcolor(GREEN);
settextstyle(9,0,1);
outtextxy(midx - 39,10,"GAME");


setcolor(BLACK);
settextstyle(10,0,10);
outtextxy(50,20,"HANG");


for(i = 10;i >= 6;i--)
{
setcolor(RED);
settextstyle(10,0,i);
outtextxy(midx - 100,20,"HANG");
delay(50);
setcolor(BLACK);
settextstyle(10,0,i);
outtextxy(midx - 100,20,"HANG");
}
setcolor(RED);
settextstyle(10,0,i);
outtextxy(midx - 100,20,"HANG");

setcolor(BLACK);
settextstyle(10,0,10);
outtextxy(100,200,"MAN");

shift = 150;
for(i = 10;i >= 6;i--)
{
setcolor(BLUE);
settextstyle(10,0,i);
outtextxy(midx - 100,shift,"MAN");
delay(50);
setcolor(BLACK);
settextstyle(10,0,i);
outtextxy(midx - 100,shift,"MAN");
shift-=15;
}
setcolor(BLUE);
settextstyle(10,0,i);
outtextxy(midx - 87,shift + 10,"MAN");

setcolor(CYAN);
setfillstyle(CLOSE_DOT_FILL,RED);
bar(5,5,midx - 105,midy - 55);
bar(midx + 70,5 ,2 * midx - 5,midy - 55);
bar(5,midy - 55,2 * midx - 5,2 * midy - 5);
rectangle(midx - 105,5,midx + 70,midy - 55);
rectangle(5,5,2 * midx - 5,2 * midy - 5);


delay(400);
setfillstyle(0,DARKGRAY);
bar3d(10,10,midx - 110,midy - 55,0,0);
setcolor(BROWN);
settextstyle(2,0,5);
outtextxy(25,15,"PROJECT SUBMITTED BY");
line(15,30,midx - 115,30);
outtextxy(20,35,"ANKIT POKHREL");
outtextxy(20,55,"BE COMPUTER");
outtextxy(20,75,"FIRST YEAR/SECOND PART");
outtextxy(20,95,"ACME ENGINEERING COLLEGE");
outtextxy(20,115,"2066, MANGSIR 20");
outtextxy(50,135,"COMPILED ON");
outtextxy(35,155,"TURBO C++ VER 3.0");

delay(400);
setcolor(CYAN);
setfillstyle(0,DARKGRAY);
bar3d(midx + 75,10 ,2 * midx - 10,midy - 55,0,0);
setcolor(BROWN);
settextstyle(2,0,5);
outtextxy(midx + 150,10,"SUBMITTED TO");
line(midx + 80,30,midx + 305,30);
outtextxy(midx + 85,40,"------------------");
outtextxy(midx + 85,60,"LECTURER,");
outtextxy(midx + 85,80,"DEPARTMENT OF COMPUTER" );
outtextxy(midx + 85,100,"ACME ENGINEERING COLLEGE");
outtextxy(midx + 85,120,"SITAPAILA, KATHMANDU");
line(midx + 80,145,midx + 305,145);

delay(300);
setcolor(CYAN);
bar3d(midx - 157,midy - 30,midx + 150,midy - 10,0,0);
setcolor(GREEN);
outtextxy(midx - 90,midy - 27,"PLEASE, SELECT OPTION");

settextstyle(10,0,2);
setcolor(CYAN);
bar3d(midx - 155,midy + 10,midx + 150,midy + 195,0,0);
setcolor(LIGHTBLUE);
outtextxy(midx - 50,midy + 15,"START");
outtextxy(midx - 120,midy + 55,"HOW TO PLAY");
outtextxy(midx - 140,midy + 95,"ABOUT HANGMAN");
outtextxy(midx - 50,midy + 135,"LEAVE");


int key = 1;
char ch;
while(1)
{
switch (key)
{
case 1:

setcolor(LIGHTBLUE);
settextstyle(10,0,2);
outtextxy(midx - 50,midy + 135,"LEAVE");
outtextxy(midx - 120,midy + 55,"HOW TO PLAY");

setcolor(GREEN);
settextstyle(10,0,2);
outtextxy(midx - 50,midy + 15,"START");
break;

case 2:

setcolor(LIGHTBLUE);
settextstyle(10,0,2);
outtextxy(midx - 50,midy + 15,"START");
outtextxy(midx - 140,midy + 95,"ABOUT HANGMAN");

setcolor(GREEN);
settextstyle(10,0,2);
outtextxy(midx - 120,midy + 55,"HOW TO PLAY");
break;

case 3:
setcolor(LIGHTBLUE);
settextstyle(10,0,2);
outtextxy(midx - 120,midy + 55,"HOW TO PLAY");
outtextxy(midx - 50,midy + 135,"LEAVE");

setcolor(GREEN);
settextstyle(10,0,2);
outtextxy(midx - 140,midy + 95,"ABOUT HANGMAN");
break;


case 4:
setcolor(LIGHTBLUE);
settextstyle(10,0,2);
outtextxy(midx - 140,midy + 95,"ABOUT HANGMAN");
outtextxy(midx - 50,midy + 15,"START");

setcolor(GREEN);
settextstyle(10,0,2);
outtextxy(midx - 50,midy + 135,"LEAVE");
break;

}

ch = getch();
if(ch == ENTER)
break;

if(ch == DOWN)
{
++key;
if(key > 4)
key = 1;
}

if(ch == UP)
{
--key;
if(key < 1) key = 4; } } return key; } void background(char *name,int q = 1,int l = 1,int c = 3) { graphdefaults(); int x = getmaxx(); int y = getmaxy(); char temp[51],ch[2]; graphdefaults(); itoa(q,ch,10); ch[1] = '\0'; strcpy(temp,"QUESTION : "); strcat(temp,ch); setcolor(BROWN); line(0,50,x,50); line(0,y-50,x,y-50); name[0] = toupper(name[0]); setcolor(GREEN); settextstyle(2,HORIZ_DIR,5); outtextxy(20,20,name); outtextxy(x/2 - 60,20,temp); strcpy(temp,"LEVEL : "); itoa(l,ch,10); ch[1] = '\0'; strcat(temp,ch); outtextxy(x - 100,20,temp); strcpy(temp,"LIFE LEFT : "); itoa(c,ch,10); ch[1] = '\0'; strcat(temp,ch); outtextxy(20,y - 30,temp); strcpy(temp,"CATAGORY : "); switch(l) { case 1: strcat(temp,"SCIENCE"); break; case 2: strcat(temp,"COUNTRY"); break; case 3: strcat(temp,"SPORTS"); break; case 4: strcat(temp,"CAPITALS"); break; case 5: strcat(temp,"HISTORY"); break; case 6: strcat(temp,"COMPUTER"); break; case 7: strcat(temp,"POLITICIANS"); break; case 8: strcat(temp,"TECHNOLOGY"); break; case 9: strcat(temp,"BOOKS"); break; case 10: strcat(temp,"MISCELLANEOUS"); break; } outtextxy(x - 200,y - 30,temp); } void rope() { int midx = getmaxx()/2; int midy = getmaxy()/2; setcolor(RED); setlinestyle(SOLID_LINE,0,2); line(midx - 36,midy - 188,midx - 36,midy - 110); } void head(int color = BROWN) { rope(); graphdefaults(); int midx = getmaxx()/2; int midy = getmaxy()/2; setcolor(color); settextstyle(0,0,3); outtextxy(midx - 48,midy - 110,"\1"); } void body(int color = BROWN) { int midx = getmaxx()/2; int midy = getmaxy()/2; setfillstyle(SOLID_FILL,color); bar(midx - 35,midy - 30,midx - 37,midy - 88); } void leg(int color = BROWN) { int midx = getmaxx()/2; int midy = getmaxy()/2; setcolor(color); setfillstyle(SOLID_FILL,color); line(midx - 40,midy - 30,midx - 30,midy - 30); bar(midx - 42,midy + 10,midx - 40 ,midy - 30); bar(midx - 32 ,midy - 30,midx - 30,midy + 10); } void hand(int color = BROWN) { int midx = getmaxx()/2; int midy = getmaxy()/2; setcolor(color); setfillstyle(SOLID_FILL,color); line(midx - 40,midy - 80,midx - 30,midy - 80); bar(midx - 42,midy - 80,midx - 40 ,midy - 40); bar(midx - 32 ,midy - 80,midx - 30,midy - 40); } void hang() { graphdefaults(); int midx = getmaxx()/2; int midy = getmaxy()/2; setcolor(RED); int shift = 0; shift = 0; for(int i = 0;i < 5;i++) { setcolor(BLACK); settextstyle(0,0,3); outtextxy(midx - 48,midy - 110 + shift,"\1"); setfillstyle(SOLID_FILL,BLACK); bar(midx - 35,midy - 30 + shift,midx - 37,midy - 88 + shift); line(midx - 40,midy - 30 + shift,midx - 30,midy - 30 + shift); bar(midx - 42,midy + 10 + shift,midx - 40 ,midy - 30 + shift); bar(midx - 32 ,midy - 30 + shift,midx - 30,midy + 10 + shift); line(midx - 40,midy - 80,midx - 30,midy - 80); bar(midx - 42,midy - 80,midx - 40 ,midy - 40); bar(midx - 32 ,midy - 80,midx - 30,midy - 40); setcolor(RED); setlinestyle(SOLID_LINE,0,2); line(midx - 36,midy - 188,midx - 36,midy - 110 + shift); shift += 10; setcolor(RED); settextstyle(0,0,3); outtextxy(midx - 48,midy - 110 + shift,"\1"); setfillstyle(SOLID_FILL,RED); bar(midx - 35,midy - 30 + shift,midx - 37,midy - 88 + shift); line(midx - 40,midy - 30 + shift,midx - 30,midy - 30 + shift); bar(midx - 42,midy + 10 + shift,midx - 40 ,midy - 30 + shift); bar(midx - 32 ,midy - 30 + shift,midx - 30,midy + 10 + shift); line(midx - 40,midy - 80 + shift,midx - 30,midy - 80 + shift); bar(midx - 42,midy - 80 + shift,midx - 40 ,midy - 40 + shift); bar(midx - 32 ,midy - 80 + shift,midx - 30,midy - 40 + shift); setcolor(RED); setlinestyle(SOLID_LINE,0,2); line(midx - 36,midy - 188,midx - 36,midy - 110 + shift); delay(100 + shift * 6); } setcolor(BLACK); settextstyle(0,0,3); outtextxy(midx - 48,midy - 110 + shift,"\1"); setfillstyle(SOLID_FILL,BLACK); bar(midx - 35,midy - 30 + shift,midx - 37,midy - 88 + shift); line(midx - 40,midy - 30 + shift,midx - 30,midy - 30 + shift); bar(midx - 42,midy + 10 + shift,midx - 40 ,midy - 30 + shift); bar(midx - 32 ,midy - 30 + shift,midx - 30,midy + 10 + shift); line(midx - 40,midy - 80 + shift,midx - 30,midy - 80 + shift); bar(midx - 42,midy - 80 + shift,midx - 40 ,midy - 40 + shift); bar(midx - 32 ,midy - 80 + shift,midx - 30,midy - 40 + shift); setcolor(RED); line(midx - 36,midy - 188,midx - 36,midy - 110 + shift); settextstyle(0,0,3); outtextxy(midx - 48,midy - 110 + shift,"\2"); setfillstyle(SOLID_FILL,RED); bar(midx - 35,midy - 30 + shift,midx - 37,midy - 88 + shift); setlinestyle(SOLID_LINE,0,3); line(midx - 39,midy - 30 + shift,midx - 33,midy - 30 + shift); line(midx - 60,midy + 10 + shift,midx - 40,midy - 30 + shift); line(midx - 32,midy - 30 + shift,midx - 10,midy + 10 + shift); line(midx - 39,midy - 80 + shift,midx - 33,midy - 80 + shift); line(midx - 40,midy - 80 + shift,midx - 60,midy - 50 + shift); line(midx - 33,midy - 80 + shift,midx - 10,midy - 50 + shift); } void right(int color) { graphdefaults(); int x = getmaxx(); int y = getmaxy(); setcolor(color); setlinestyle(SOLID_LINE,0,3); line(x/2 - 33,y - 30,x/2 - 26,y - 23); line(x/2 - 25,y - 24,x/2 - 10,y - 31); } void gameover() { int midx = getmaxx()/2; int midy = getmaxy()/2; cleardevice(); settextjustify(CENTER_TEXT,CENTER_TEXT); settextstyle(2,0,10); setcolor(RED); outtextxy(midx,midy,"GAME OVER"); setcolor(GREEN); outtextxy(midx,midy + 50,"THANKYOU FOR PLAYING."); delay(1500); closegraph(); exit(0); } void wrong(int color) { graphdefaults(); int midx = getmaxx()/2; int y = getmaxy(); setcolor(color); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,4); outtextxy(midx - 28,y - 40,"(X)"); } void about_hangman(void) { cleardevice(); setcolor(WHITE); setfillstyle(11,RED); bar3d(5,5,getmaxx() - 5,getmaxy() - 5,0,0); /* Outermost Bar */ setfillstyle(11,DARKGRAY); delay(500); bar3d(110,20,540,86,0,0); /* Internal Small Bar */ settextstyle(10,HORIZ_DIR,3); settextjustify(LEFT_TEXT,LEFT_TEXT); delay(600); outtextxy(160,67,"ABOUT HANGMAN"); delay(500); setfillstyle(9,DARKGRAY); bar3d(10,415,630,100,0,0); /* Internal Large Bar */ delay(650); settextstyle(SMALL_FONT,HORIZ_DIR,5); outtextxy(34,125," -> This Program was developed ,coded and completed as a Home");
delay(250);
outtextxy(33,140,"Project on 21th Mangsir 2066 (6th DEC 2009).");
delay(250);
outtextxy(33,155,"This Application was developed using the simple concepts of the C programming ");
delay(250);
outtextxy(33,170,"Language. General components of C language like Loops ,String,Function,File");
delay(250);
outtextxy(33,185,"C - Graphics and Conditional Statements are used in this Program.");
delay(250);

setcolor(WHITE);
settextstyle(SMALL_FONT,HORIZ_DIR,4);
outtextxy(19,209,"c");
circle(21,207,6);
circle(21,207,5);
settextstyle(SMALL_FONT,HORIZ_DIR,5);
setcolor(WHITE);
outtextxy(32,211,"Ankit Pokhrel (2066 B.S. / 2009 A.D). All Rights Reserved.");
delay(200);

setcolor(RED);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,0);
outtextxy(19,245,"W");
sound(150);
delay(180);
nosound();
outtextxy(40,245,"A");
sound(350);
delay(180);
nosound();
outtextxy(60,245,"R");
sound(150);
delay(180);
nosound();
outtextxy(80,245,"N");
sound(350);
delay(180);
nosound();
outtextxy(100,245,"I");
sound(150);
delay(180);
nosound();
outtextxy(105,245,"N");
sound(350);
delay(180);
nosound();
outtextxy(125,245,"G");
sound(150);
delay(250);
nosound();

settextstyle(SMALL_FONT,HORIZ_DIR,5);
setcolor(WHITE);
outtextxy(19,260," No part of the program can be reproduced or distributed in any form or by");
delay(250);
outtextxy(33,275,"any means,or stored in a database or retrieval system,without prior written");
delay(250);
outtextxy(33,290,"permission of the programmer. Requests for permission or further information ");
delay(250);
outtextxy(33,305,"should be adressed to Ankit Pokhrel in the address below.");
delay(250);

settextstyle(SMALL_FONT,HORIZ_DIR,6);
outtextxy(33,328,"Ankit Pokhrel");
line(33,330,153,330);

delay(300);
settextstyle(SMALL_FONT,HORIZ_DIR,5);
outtextxy(33,350,"Department of Computer.");

delay(300);
outtextxy(33,365,"Acme Engineeirng College.");

delay(300);
outtextxy(33,380,"Phone no : +977-1-9803970090");

delay(300);
outtextxy(33,395,"E-mail : ankitpokhrel@gmail.com");

delay(300);
outtextxy(33,410,"Kathmandu, NEPAL");

delay(200);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
setcolor(WHITE);
outtextxy(30,450,"Press any key to return to main menu");
getch();
}

void how_to_play (void)
{
cleardevice();
setfillstyle(11,RED);
settextstyle(10,HORIZ_DIR,4);
settextjustify(LEFT_TEXT,LEFT_TEXT);
setcolor(WHITE);
bar3d(5,5,getmaxx() - 5,getmaxy() - 5,0,0); /* Internal Large Bar */
setfillstyle(11,DARKGRAY);
delay(500);
bar3d(62,20,563,86,0,0);
setcolor(WHITE);
delay(600);
outtextxy(105,72,"HOW TO PLAY?");
delay(500);
setcolor(WHITE);
setfillstyle(9,DARKGRAY);
bar3d(10,415,630,100,0,0);
settextstyle(SMALL_FONT,HORIZ_DIR,5);
delay(650);
setcolor(WHITE);
outtextxy(14,130,"-> This is a Single Player Guessing Game Named HANGMAN.");
delay(300);
outtextxy(14,160,"-> The Game is Divided into 9 Levels.");
delay(300);
outtextxy(14,190,"-> Each Level Contains 8 Questions Except Last Level (7 Questions).");
delay(300);
outtextxy(14,220,"-> A Word with Certain Letters is Displayed on a Screen. You have to Guess The ");
outtextxy(14,235," Correct Word Letter by Letter & if all of the attempt fails The Man is Hanged.");
delay(300);
outtextxy(14,265,"-> If The Man is Hanged 3 Times You Loose.");
delay(300);
outtextxy(14,295,"-> The Catagory Provides You Hint to Guess The Correct Word.");
delay(300);
outtextxy(14,325,"-> If You Hit Wrong Letter the Color of Different Parts of The Man is Changed");
outtextxy(14,340," to RED.");
delay(300);
outtextxy(14,370,"-> You can Press \'ESC\' any time to Terminate the Program.");
delay(300);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
setcolor(WHITE);
outtextxy(55,450,"Press any key to return back...");
getch();
}

void start_game()
{
FILE *source;
char filename[] = "Words.txt",player[15] = "";
char str[31],c[2],key,temp[31];
int question = 1,level = 1,count = 1,life = 3,pass;
int midx = getmaxx()/2,midy = getmaxy()/2;
source = fopen(filename,"r");
if(source == NULL)
{
cleardevice();
cout << "ERROR : Unable to find file."; cout << "\nPress any key to halt..."; getch(); exit(0); } midx = getmaxx()/2; midy = getmaxy()/2; setcolor(CYAN); setfillstyle(WIDE_DOT_FILL,DARKGRAY); bar3d(midx - 155,midy + 10,midx + 150,midy + 195,0,0); setcolor(LIGHTBLUE); setfillstyle(0,DARKGRAY); bar3d(midx - 70,midy + 40,midx + 70,midy + 65,0,0); bar3d(midx - 70,midy + 90,midx + 70,midy + 115,0,0); setcolor(DARKGRAY); settextstyle(SMALL_FONT,HORIZ_DIR,5); outtextxy(midx - 55,midy + 45,"Write Your Name"); gotoxy(midx - 26,22); cin >> player;

int h = 0;
do
{
if(h == 9)
{
settextstyle(2,0,8);
setcolor(LIGHTBLUE);
outtextxy(midx - 100,midy + 203 ,"NEXT LEVEL");
delay(1200);
h = 0;
}

cleardevice();
count = 1;

background(player,question,level,life);
head();
body();
leg();
hand();

setfillstyle(SOLID_FILL,BLACK);
bar(0,320,2 * midx,360);
fgets(str,30,source);

++question;

if(question%9 == 0)
{
h = question;
++level;
if(level == 10)
gameover();
question = 1;
}

int n = strlen(str);
str[n-1] = '\0';
for(int i = 0;i < n-1;i++)
temp[i] = ' ';
int shift = 25;

if(n <= 9)
{
setcolor(GREEN);
settextstyle(0,0,0);
temp[0] = str[0];
c[0] = str[0];
c[1] = '\0';
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy((midx - 148),midy + 103,c);

setcolor(RED);
for(int i = 1;i < n-1;i++)
{
outtextxy((midx - 148) + shift,midy + 115,"-");
shift += 25;
}

}

else
{
setcolor(GREEN);
settextstyle(0,0,0);
temp[0] = str[0];
c[0] = str[0];
c[1] = '\0';
outtextxy((midx - 150),midy + 100,c);
c[0] = str[n - 2];
temp[n - 2] = str[n - 2];
c[1] = '\0';
outtextxy((midx - 150) + (n-2) * 25,midy + 100,c);
c[0] = str[int(n/2)];
temp[int(n/2)] = str[int(n/2)];
c[1] = '\0';
outtextxy((midx - 150) + n/2 * 25,midy + 100,c);

for(int i = 1;i < n-2;i++)
{
if(i != (int(n/2)) && str[i] != ' ')
{
setcolor(RED);
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle(0,0,0);
outtextxy((midx - 148) + shift,midy + 115,"-");
}
shift += 25;
}
}
shift = 25;
temp[n-1] = '\0';
while(1)
{

if(strcmpi(temp,str) == 0)
{
delay(600);
break;
}
key = getch();
key = toupper(key);
if(key == ESC)
{
cleardevice();
setcolor(GREEN);
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle(2,0,12);
outtextxy(midx,midy,"BYE BYE");
outtextxy(midx,midy + 33,"THANKYOU FOR PLAYING.");
delay(1000);
closegraph();
exit(0);
}

pass = 0;
for(int i = 0;i < n-1;i++)
{
if(key == str[i])
{
right(GREEN);
delay(300);
right(BLACK);
if(i != 0 && i!= n-1)
{
temp[i] = key;
c[0] = str[i];
c[1] = '\0';
setcolor(GREEN);
outtextxy((midx - 150) + shift * i,midy + 100,c);
}
++pass;
}

}

if(pass == 0)
{
wrong(RED);
delay(300);
wrong(BLACK);

if(count == 1)
leg(RED);
if(count == 2)
hand(RED);
if(count == 3)
body(RED);
if(count == 4)
{
setfillstyle(SOLID_FILL,BLACK);
bar(0,midy + 108,2 * midx,midy + 128);

static int hangc = 0;
setfillstyle(SOLID_FILL,BLACK);
bar(0,330,2 * midx,350);
hang();
--life;
++hangc;
if(hangc == 3)
{
delay(900);
gameover();
}

delay(900);
break;

}

++count;
}

}
}while(1);
}

void main()
{
clrscr();
int gd = DETECT,gm,midx,midy,option;
initgraph(&gd,&gm,"c:\\tc\\bgi");

int errorcode = graphresult();

if (errorcode != grOk) // An Error Occurred
{
cout << "Graphics error: " << grapherrormsg(errorcode);
cout << "\nPress any key to halt...";
getch();
exit(0); // Return With Error Code
}

do
{
option = face();
switch(option)
{
case 1:
start_game();
break;

case 2:
how_to_play();
cleardevice();
graphdefaults();
break;

case 3:
about_hangman();
cleardevice();
graphdefaults();
break;

case 4:
cleardevice();
setcolor(GREEN);
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle(2,0,12);
outtextxy(midx,midy,"BYE BYE");
outtextxy(midx,midy + 33,"THANKYOU FOR PLAYING.");
closegraph();
exit(0);

}
}while(option != 1);

}//END OF MAIN

// END OF PROGRAM


//Words for the Game
//Save in seperate notepad file words.txt

ENTHALPY
GENETICS
AMPLITUDE
COSMOLOGY
SUPERNOVA
DEUTERIUM
RADIOACTIVITY
HARMONIC MOTION
LITHUANIA
BELORUSSIA
TURKMENISTAN
KYRGYZSTAN
MAURITANIA
SLOVAKIA
SIERRA LEONE
CZECHOSLOVAKIA
BADMINTON
ELEPHANT POLO
WRESTLING
ARCHERY
SKATEBOARDING
ICE SKATING
BULLFIGHTING
GYMNASTICS
WARSAW
HELSINKI
KHARTOUM
NASSAU
VILNIUS
TALLIN
REYKJAVIK
NOUAKCHOTT
ADOLF HITLER
GENGHIS KHAN
OTTOMAN EMPIRE
HAN DYNASTY
COLOSSEUM
CASABLANCA
SCANDINAVIAN
CHARLEMAGNE
MICROSOFT
MICROPROCESSOR
NANOTECHNOLOGY
INTELLIGENCE
ENCRYPTION
LINUS TORVALDS
ETHICAL HACKING
MALICIOUS HACKERS
F D ROOSEVELT
WISTON CHURCHILL
MAO ZEDONG
JOSEPH STALIN
VLADIMIR LENIN
STEPHEN HARPER
JOSIP BROZ TITO
MUHAMMAD PROPHET
SUBMARINE
AUTOMOBILE
FIGHTER AIRCRAFT
TELECOMMUNICATION
NUCLEAR BOMB
DIGITAL TECHNOLOGY
MULTIMEDIA
SUPERCOMPUTER
THE ALCHEMIST
INVISIBLE MAN
THE EIGHTH DAY
THE GREAT FIRE
THE CENTAUR
THE FIXER
THE MAGIC BARREL

Calender

#include "iostream.h"
#include "conio.h"
#include "dos.h"

class calander
{
public:
step1 (int);
void month_name(int);
int no_days(int,int);
int leap(int);
};

int calander :: step1 (int y)
{
int x=y%7;
x+=(y-1)/4;
x-=(y-1)/100;
x+=(y-1)/400;
x=x%7;
if(x==0)
x=7;
if(leap(y))
x+=7;
return x;
}

void calander :: month_name(int m)
{
switch(m)
{
case 1 : cout<<"January"; break; case 2 : cout<<"February"; break; case 3 : cout<<"March"; break; case 4 : cout<<"April"; break; case 5 : cout<<"May"; break; case 6 : cout<<"June"; break; case 7 : cout<<"July"; break; case 8 : cout<<"August"; break; case 9 : cout<<"September"; break; case 10: cout<<"October"; break; case 11: cout<<"November"; break; case 12: cout<<"December"; break; }}int calander :: no_days(int mon, int y){ int d; switch(mon) { case 1 : case 3 : case 5 : case 7 : case 8 : case 10: case 12: d=31; break; case 4 : case 6 : case 9 : case 11: d=30; break; case 2 : if(leap(y)) d=29; else d=28; break; } return d;}int calander :: leap (int y){ if (y%100==0) if (y%400==0) return 1; else return 0; else if (y%4==0) return 1; else return 0;}void main(){ restart: clrscr(); cout<<"Enter year : "; unsigned int y,m; cin>>y;
int x;
calander c;
x = c.step1(y);
int month[14][12]= {1,4,4,7,2,5,7,3,6,1,4,6,
2,5,5,1,3,6,1,4,7,2,5,7,
3,6,6,2,4,7,2,5,1,3,6,1,
4,7,7,3,5,1,3,6,2,4,7,2,
5,1,1,4,6,2,4,7,3,5,1,3,
6,2,2,5,7,3,5,1,4,6,2,4,
7,3,3,6,1,4,6,2,5,7,3,5,
1,4,5,1,3,6,1,4,7,2,5,7,
2,5,6,2,4,7,2,5,1,3,6,1,
3,6,7,3,5,1,3,6,2,4,7,2,
4,7,1,4,6,2,4,7,3,5,1,3,
5,1,2,5,7,3,5,1,4,6,2,4,
6,2,3,6,1,4,6,2,5,7,3,5,
7,3,4,7,2,5,7,3,6,1,4,6};
cout<<"Enter month (1 - 12) : "; month_input: cin>>m;
if(m<1 || m>12)
{
cout<<"Enter a valid month (1 - 12) : "; goto month_input; } clrscr(); c.month_name(m); cout << ' ' << y << "\n\n"; cout<< "Sun Mon Tue Wed Thu Fri Sat\n"; int j = month[x-1][m-1]+1, days = c.no_days(m,y); for (int i=0; i<=j-2; i++) cout<<' '; for(i=1; i<=days; i++) { cout << i <<' '; if(j==7) { cout << '\n'; j=1; } else j++; } cout<<"\n\nTry for another month? (y/n) : "; char ch; cin>>ch;
if(ch=='y' || ch=='Y')
goto restart;
else
{
clrscr();
cout << "\n\n\n\n\n\n\n\n\n";
cout.width(47);
cout << "Edited by Ankit Pokhrel";
delay(1200);
}
}