Documente Academic
Documente Profesional
Documente Cultură
Acknowledgeme
nt
It would be our utmost pleasure to express our sincere
gratitude to our computer teacher ‘Mrs. Chandni Agarwal’
who has been a constant supporter and guide in completing
our project and has supported us in every possible way.
Furthermore our special thanks to our lab coordinator ‘Mr.
Ashish’ for putting his tremendous efforts and helping us
with technical matters during the completion of this project.
We should also like to sincerely acknowledge our school
administration for providing us with a computer such that
we are able to work on project in the school hours.
Certificate
This is to certify that Bipin Kalra, Jatin Katyal and Chinmay
Bindal of class XII-B who were allowed to do work on this
project entitled“Code@Rena” in the computer
lab of Maharaja Agrasen Model School have faithfully
carried out this project under my guidance and supervision
and accompanied report is completely their genuine work.
They had completed the necessary preliminaries and put in
the required attendance in practical periods.
Index
What is Code@Rena
Main Class
Source Code
Output Screens
Bibliography
Code@Rena 5
Code@Rena !!
Code@Rena as the name suggests is and arena for the
lovers of programming, specifically for those like us
students who are new to the programming scenario to learn
via our archives of codes that we ourselves learned from
over the years. This project is thus extremely useful for the
students as they can easily search for programmes
confusing them and save a lot of their CODING time from
getting wasted in searching codes on the Internet.
We have accumulated codes in various hierarchical
categories which makes searching your desired code a
breeze. Keeping in mind our own experiences we have
tried to provide a simplified and user friendly project which
would be easy to use for even novice users.
HOPE OUR EFFORTS HAVE BEEN WORTHWHILE!!
Code@Rena 6
Source of our
IDEA !!
We had this idea of creating a sort of a code school (which
we like to call a CODING ARENA) when a few months ago
we had to spend 2-3 hours in creating a folder of the all
the codes that we had practiced over two years. We were
late in submitting that folder to our teacher because all the
codes were incomplete in some way or the other and
furthermore were erratically saved in unsearchable
directories of our computers. That particular moment we felt
the need to formulate a directory which would not only
prevent such inefficiency in future but as it has been, be a
source of learning (quick learning at that) for all the
students who can access our project.
Therefor the idea of creating Code@Rena came from the
late Completion of an appointed task.
Code@Rena 7
Project Manual
Now we would be describing the skeletal structure of our
project giving an overview of the flow of data in our
project run.
Our project has majorly been divided into two parts:
1. Main Page – This serves as the hub of all our codes
and files and an access point to them as well.
2. Peripheries – This section includes an array of data
files and source codes of various codes that our main
page can access.
Now we would give you and ordered tour through our
project listing all the portions of our project in their order
of occurrence.
Flowchart
Login Page
Login Sign Up
Fill in the required
details to sign up to
Code@Rena and
proceed to login.
Suggestions
Continue Exit
Code@Rena 12
Major Topics
Covered
Loops and Selection Statements
2D arrays
String arrays
Structures
Inheritence
Pointers
Code@Rena 13
Header Files
used
The following header files have been incorporated in our
programme (Developer C++)–
1. #inlclude<iostream>
2. #inlclude<conio.h>
3. #inlclude<stdio.h>
4. #inlclude<stdlib.h>
5. #inlclude<windows.h>
6. #inlclude<ctype.h>
7. #inlclude<string.h>
8. #inlclude<math.h>
9. #include<process.h>
Code@Rena 14
Main Class
The main class that has its roots in all segments of our
program contains the following components –
1. Data Members –
a. int sno;
b. char topic[100]; Private
c. char name[100]; Members
d. char title[100];
2. Member Functions –
a. Constructor –
i. Default - code();
ii. Parameterized - code (int no,char c[], char a[],
char b[]);
b. Other Member Functions –
i. char* get_topic();
ii. char* get_name();
iii. char* get_title();
iv. int get_sno();
v. void display()
class code
{
int sno;
char topic[100];
char name[100];
char title[100];
public:
code() //Default constructor
{}
code (int no,char c[], char a[], char b[]) //Parameterized constructor
{
sno=no;
strcpy(topic,c);
strcpy(name,a);
strcpy(title,b);
}
char* get_topic()
{
return topic;
}
Code@Rena 16
char* get_name()
{
return name;
}
char* get_title()
{
return title;
}
int get_sno()
{
return sno;
}
void display()
{
cout<<sno<<endl;
cout<<topic<<endl;
cout<<name<<endl;
}
};
Code@Rena 17
Division in
Modules and
Files
Our program, because of its huge size needed to be
divided into various files that are linked together by our
main file. The following hierarchical setups of modules and
files has been maintained –
1. Inside the individual codes – The codes have
been divided into suitable modules with a major use
of functions rather than passing commands in the
‘main’ function itself. Thereby allowing us to reuse the
recurring functions without wasting time in recreating
them.
2. In the entire Project –
a. Main file – This file contains the menus and links
all of our other C++ files together and executes
them as well on user’s command.
i. Separate binary files have been created as an
index to our list of codes. (a separate binary
Code@Rena 18
Source Code
Main Programme -
/*CODE@RENA*/
//All the required header files have already been inserted in these files
#include "main_class.cpp"
#include "login.cpp"
//Global Variables
int j=0;
char l[50];
void create()
{
system("cls");
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\t Sign Up"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
Code@Rena 21
int i=check(user);
if(i==1)
{
cout<<"\nThe user ID already exists. (Press any key to continue...)"<<endl;
cout<<"--------------------------------------------------------------------------------
";
getch();
Signup();
}
char pass_temp[30],pass_temp2[30];
cout<<"\t\t\tEnter password - ";
strcpy(pass_temp,getpass());
cout<<"\n\t\t\tConfirm the password- ";
strcpy(pass_temp2,getpass());
if (!strcmpi(pass_temp,pass_temp2))
Code@Rena 22
{
strcpy(pass,pass_temp);
}
else
{
cout<<"\n\nPassword mismatch (Press any key to retry the
signup...)"<<endl;
cout<<"--------------------------------------------------------------------------------
";
getch();
Signup();
}
}
public:
void enter()
{
cin.getline(r,1000,'$');
}
void display()
{
cout<<r;
}
};
//Main Function
int main()
{
set_size();
main_page();
in();
getch();
return 0;
}
void main_page()
{
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"@@@@@ @@@@@ @@@@ @@@@@ @@@@@
@@@@@ @@@@@ @@ @ @@@@@@"<<endl
<<"@ @ @ @ @ @ @ @ @ @ @ @@
@ @ @"<<endl
<<"@ @ @ @ @ @ @ @@ @ @ @ @ @ @
@ @ @"<<endl
<<"@ @ @ @ @ @ @ @ @@ @ @ @ @ @
@ @ @"<<endl
<<"@ @ @ @ @ @ @ @ @ @ @@@@@ @
@ @ @ @ @"<<endl
<<"@ @ @ @ @ @@@@@ @ @ @ @ @@
@@@@@ @ @ @ @@@@@@"<<endl
<<"@ @ @ @ @ @ @ @ @@ @@ @ @
@ @ @ @"<<endl
<<"@ @ @ @ @ @ @ @ @@ @ @ @ @
@ @ @ @"<<endl
<<"@ @ @ @ @ @ @ @@@ @ @ @ @
@ @ @ @"<<endl
<<"@ @ @ @ @ @ @ @ @ @ @ @
@@ @ @"<<endl
<<"@@@@@ @@@@@ @@@@ @@@@@ @@@@@
@ @ @@@@@ @ @@ @ @"<<endl;
cout<<"--------------------------------------------------------------------------------";
Code@Rena 25
void in()
{
Sign_up S;
system("cls");
int ans;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\tWelcome to Code@Rena..."<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
cout<<"Please enter your choice - ";
cin>>ans;
if(ans==1)
Code@Rena 26
{
system("cls");
Signin();
}
else
{
system("cls");
Signup();
}
system("cls");
}
void Signup()
{
Sign_up S;
fstream fout("sign.dat",ios::binary|ios::out|ios::app);
S.create();
fout.write((char*)&S,sizeof(S));
fout.flush(); //Function to get rid of buffer associated with class
cout<<"\n\nSignup Complete. (Press any key to continue)..."<<endl;
cout<<"--------------------------------------------------------------------------------";
getch();
in();
}
char *getpass()
{
Code@Rena 27
char pass1[30];
char c;
int i=0;
while (1)
{
c=getch();
if(c!=13&&c!='\b')
{
pass1[i++]=c;
cout<<"*";
}
else if (c==13)
{
pass1[i]='\0';
return pass1;
}
else if (c=='\b'&&i>0)
{
i--;
cout<<"\b \b";
}
}
void Signin()
{
system("cls");
Sign_up S;
char username[20], password[20];
Code@Rena 28
ifstream fin("sign.dat",ios::binary);
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\t Log In"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
getch();
Signin();
}
else if (std==13)
file.open("HOTS.dat",ios::binary);
code temp;
int cnt=0,n1,n2;
while (file.read((char*)&temp, sizeof(temp)))
{
if (!strcmpi(temp.get_topic(),topic))
{
cout<<"\t\t\t"<<temp.get_sno()<<". "<<temp.get_title()<<endl;
cnt++;
}
}
n1=++cnt;
n2=++cnt;
cout<<endl<<"-------------------------------------------------------------------------------
-";
cout<<"\t\t\t"<<n1<<". Required code not available.";
cout<<endl<<"\t\t\t"<<n2<<". Back to previous menu."<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\nEnter your choice - ";
int sno;
cin>>sno;
if(sno==n1)
{
char ans;
system("cls");
cout<<"--------------------------------------------------------------------------------
Code@Rena 31
";
cout<<"--------------------------------------------------------------------------------
";
cout<<"The code you are searching for is not present in our
database.\nHelp expanding our database by entering the code yourself."
<<"\nEnter your choice (Y/N):";
cin>>ans;
switch(ans)
{
case 'Y':
case 'y':create(topic);break;
case 'N':
case 'n':menu1();break;
}
}
else if(sno==n2)
{
system("cls");
switch(::j)
{
case 11:menu11();
break;
case 12:menu12();
break;
case 13:menu1();
break;
}
}
else
search(sno,std,topic);
Code@Rena 32
void menu1()
{
system("cls");
int i;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\tWelcome to the main menu of CODE@RENA - "<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\n\t\t\t\t1. 11th"
Code@Rena 33
<<"\n\t\t\t\t2. 12th"
<<"\n\t\t\t\t3. HOTS"
<<"\n\t\t\t\t4. Fun Section"
<<"\n\t\t\t\t5. Reviews"
<<"\n\t\t\t\t0. Exit"<<endl<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\nEnter your choice - ";
cin>>i;
switch(i)
{
case 1: system("cls");
::j=11;
menu11();
break;
case 2: system("cls");
::j=12;
menu12();
break;
case 3: system("cls");
::j=13;
menu13();
break;
case 4: system("cls");
menu14();
break;
Code@Rena 34
case 5: system("cls");
review_show();
break;
case 0: exit(0);
default:system("cls");
char n;
cout<<"--------------------------------------------------------------------------------
";
cout<<"--------------------------------------------------------------------------------
";
cout<<"Choice is not recognized."
<<"\nDo you want to try again? (Y/N) - ";
cin>>n;
if(n=='y'||n=='Y')
menu1();
else
exit(0);
}
void menu11()
{
int n;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\t Class 11th"<<endl;
cout<<"--------------------------------------------------------------------------------";
Code@Rena 35
switch(n)
{
case 1: strcpy(l,"Getting Started with C++");
break;
case 2: strcpy(l,"Basic");
break;
case 3: strcpy(l,"Ctype");
break;
Code@Rena 36
case 6: strcpy(l,"Array");
break;
case 7: strcpy(l,"Functions");
break;
case 9: strcpy(l,"String");
break;
case 0: system("cls");
menu1();
Code@Rena 37
break;
default: system("cls");
char n;
cout<<"-----------------------------------------------------------------
---------------";
cout<<"-----------------------------------------------------------------
---------------";
cout<<"\nChoice is not recognized."
<<"\nDo you want to try again? (Y/N) - ";
cin>>n;
if(n=='y'||n=='Y')
menu1();
else
exit(0);
}
titles(l,::j);
}
void menu12()
{
int n;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\t Class 12th"<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\n\t\t\t1. Arrays."
<<"\n\t\t\t2. Binary Files"
<<"\n\t\t\t3. Text Files"
Code@Rena 38
<<"\n\t\t\t4. Classes"
<<"\n\t\t\t5. Constructors and Destructors."
<<"\n\t\t\t6. Inheritence"
<<"\n\t\t\t7. Merging"
<<"\n\t\t\t8. Searching"
<<"\n\t\t\t9. Sorting"<<endl<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t0. Back to Main menu."<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\nEnter your choice - ";
cin>>n;
switch(n)
{
case 1: strcpy(l,"Arrays");
break;
case 3: strcpy(l,"TextFiles");
break;
case 4: strcpy(l,"Classes");
break;
case 6: strcpy(l,"Inheritance");
Code@Rena 39
break;
case 7: strcpy(l,"Merging");
break;
case 8: strcpy(l,"Searching");
break;
case 9: strcpy(l,"Sorting");
break;
case 0: system("cls");
menu1();
break;
default: system("cls");
char n;
cout<<"-----------------------------------------------------------------
---------------";
cout<<"-----------------------------------------------------------------
---------------";
cout<<"\nChoice is not recognized."
<<"\nDo you want to try again? (Y/N) - ";
cin>>n;
if(n=='y'||n=='Y')
menu1();
else
exit(0);
}
Code@Rena 40
titles(l,::j);
}
void menu13()
{
strcpy(l,"HOTS");
titles("HOTS",::j);
}
void menu14()
{
int t;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\t FUN Section"<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\n\t\t\t1. Snake Game"
<<"\n\t\t\t2. Tic Tac Toe"
<<"\n\t\t\t3. C++ Artist (Drawing)"
<<"\n\t\t\t4. Friends book (Social)"<<endl<<endl;
cout<<"--------------------------------------------------------------------------------
";
cout<<"\t\t\t0. Back to Main Menu"<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\nEnter you choice - ";
cin>>t;
openfun(t);
}
ifstream fin;
code c;
if(std==11)
{
fin.open ("list11.dat",ios::binary);
}
else if(std==12)
{
fin.open("list12.dat",ios::binary);
}
else if(std==13)
fin.open("HOTS.dat",ios::binary);
else
{
cout<<"Invalid choice.";
}
while(fin.read((char*)&c,sizeof(c)))
{
if((c.get_sno()==no)&&!strcmpi(c.get_topic(),top))
{
open(c);
}
}
fin.close();
}
void openfun(int t)
{
switch(t)
{
Code@Rena 42
case1:ShellExecute(NULL,"open","snakegame.exe",NULL,NULL,SW_SHO);
break;
case 2:ShellExecute(NULL,"open","tictactoe.exe",NULL,NULL,SW_SHOW);
break;
case3:ShellExecute(NULL,"open","drawingartist.exe",NULL,NULL,SW_SHOW);
break;
case4:ShellExecute(NULL,"open","friendsbook\\login.exe",NULL,NULL,SW_SHOW
);
break;
default:menu1();
}
system("cls");
menu14();
}
int ans;
char line[200];
system("cls");
cout<<"--------------------------------------------------------------------------------";
cout<<"1.See the source code"<<endl;
cout<<"2.Run the source code"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
cout<<"Please enter your choice - ";
cin>>ans;
char std[50];
itoa(j, std, 10);
Code@Rena 43
strcat(std,"\\");
strcat(std,c1.get_topic());
strcat(std,"\\");
strcat(std,c1.get_name());
if(ans==1)
{
ifstream fread;
fread.open(strcat(std,".cpp"));
system("cls");
cout<<"//*****"<<c1.get_title()<<"*****//"<<endl<<endl;
while(!fread.eof())
{
fread.getline(line,100);
cout<<line<<endl;
}
getch();
}
else if(ans==2)
{
char t[80];
char *temp2=strcat(std,".exe");
ShellExecute(NULL,"open",temp2,NULL,NULL,SW_SHOW);
}
review();
}
{
system("cls");
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\tCreate a Code"<<endl;
cout<<"--------------------------------------------------------------------------------";
int s=findsno(top);
char name[30],title[100];
cout<<"\nEnter Name of the Code - ";
cin.ignore();
cin.getline(name,30);
cout<<"Enter Title of program - ";
cin.getline(title, 100);
cout<<endl<<"--------------------------------------------------------------------------------";
char loc[100];
switch (::j)
{
case 11: strcpy(loc,"11\\"); break;
case 12: strcpy(loc,"12\\"); break;
case 13: strcpy(loc,"13\\"); break;
}
strcat(loc,top);
strcat(loc,"\\");
strcat(loc,name);
ofstream file(strcat(loc,".cpp"));
char cod[1000];
system("cls");
Code@Rena 45
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\tCreate a Code"<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"Enter your code here: ($ to end)"<<endl;
cout<<"--------------------------------------------------------------------------------";
cin.getline(cod, 1000, '$');
file<<cod;
file.close();
ofstream f;
switch (::j)
{
case 11: f.open("list11(t).dat",ios::binary|ios::app); break;
case 12: f.open("list12(t).dat",ios::binary|ios::app); break;
case 13: f.open("HOTS(t).dat",ios::binary|ios::app); break;
}
code wr(s, top, name, title);
f.write((char*)&wr, sizeof (wr));
char temp[50];
strcpy(temp,"g++ ");
strcat(temp, "\"");
strcat(temp, loc);
strcat(temp, "\"");
strcat(temp," -o ");
strcat(temp, "\"");
switch (s)
{
case 11: strcat(temp,"11\\"); break;
Code@Rena 46
strcat(temp,top);
strcat(temp,"\\");
strcat(temp,name);
strcat(temp, "\"");
system(temp);
menu1();
}
void review()
{
ofstream fout("Reviews.dat",ios::binary|ios::app);
reviews R;
system("cls");
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\tDo you want to enter your reviews."<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\tReviews"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
cout<<"Enter Reviews here ($ to end)- "<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
R.enter();
fout.write((char*)&R,sizeof(R));
}
else
{
cout<<"--------------------------------------------------------------------------------
";
cout<<"Press any key to continue to main menu...";
getch();
menu1();
}
titles(l,::j);
}
void review_show()
{
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t Reviews for Code@Rena"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl<<endl;
ifstream fin("Reviews.dat",ios::binary);
reviews R;
int i=1;
while(fin.read((char*)&R,sizeof(R)))
Code@Rena 48
{
cout<<i++<<". ";
R.display();
cout<<endl<<"-----------------------------------------------------------------------
---------"<<endl<<endl;
}
//Header Files
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
using namespace std;
//Global variables
const int m=30; //h
const int n=50; //w
char brd[m][n]; //b
int x_pl=4, y_pl=4; //i
int score=0; //s
int x_food=2, y_food=2; //f
char pl=(char)1;
int x_pl_del=4, y_pl_del=4;
int flg=0;
const int len=1000;
int pl_x_log[len], pl_y_log[len];
int pl_ptr_x=0, pl_ptr_y=0;
int del_ptr_x=0, del_ptr_y=0;
Code@Rena 50
//Functions
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void init()
{
brd[x_pl][y_pl]=pl;
brd[y_food][x_food]='-';
for (int i=0; i<m; i++)
{
for (int j=0; j<n; j++)
{
if (brd[i][j]!='-'&&brd[i][j]!='+')
brd[i][j]=' ';
}
}
cout<<"Score: \n";
for (int i=0; i<n+2; i++)
cout<<"*";
cout<<endl;
for (int i=0; i<m; i++)
{
cout<<"*";
for (int j=0; j<n; j++)
Code@Rena 51
cout<<" ";
cout<<"*"<<endl;
}
for (int i=0; i<n+2; i++)
cout<<"*";
}
void disp()
{
gotoxy(7,0);
cout<<score;
}
void end()
{
system("cls");
gotoxy(0,0);
cout<<"Game Over..!!\n";
cout<<"Your Final Score: "<<score<<endl;
cout<<"Press esc to exit the game";
while (getch()!=(char)27);
exit(0);
}
void run()
{
char choice;
choice=getch();
if (choice=='s'&&y_pl<m+1&&y_pl>1)
Code@Rena 52
{
if (brd[y_pl+1][x_pl]!='+'&&brd[y_pl+1][x_pl+1]!=pl)
{
if (pl_ptr_x==len)
pl_ptr_x=0;
pl_x_log[pl_ptr_x++]=x_pl;
if (pl_ptr_y==len)
pl_ptr_y=0;
pl_y_log[pl_ptr_y++]=y_pl;
if(!flg)
{
if (del_ptr_x==len)
del_ptr_x=0;
x_pl_del=pl_x_log[del_ptr_x++];
if (pl_ptr_y==len)
del_ptr_y=0;
y_pl_del=pl_y_log[del_ptr_y++];
gotoxy(x_pl_del,y_pl_del);
cout<<" ";
brd[y_pl_del][x_pl_del]=' ';
}
gotoxy(x_pl,++y_pl);
cout<<pl;
brd[y_pl][x_pl]=pl;
}
else
end();
}
if (choice=='w'&&y_pl<m+2&&y_pl>2)
{
Code@Rena 53
if (brd[y_pl-1][x_pl]!='+'&&brd[y_pl-1][x_pl]!=pl)
{
if (pl_ptr_x==len)
pl_ptr_x=0;
pl_x_log[pl_ptr_x++]=x_pl;
if (pl_ptr_y==len)
pl_ptr_y=0;
pl_y_log[pl_ptr_y++]=y_pl;
if(!flg)
{
if (del_ptr_x==len)
del_ptr_x=0;
x_pl_del=pl_x_log[del_ptr_x++];
if (pl_ptr_y==len)
del_ptr_y=0;
y_pl_del=pl_y_log[del_ptr_y++];
gotoxy(x_pl_del,y_pl_del);
cout<<" ";
brd[y_pl_del][x_pl_del]=' ';
}
gotoxy(x_pl,--y_pl);
cout<<pl;
brd[y_pl][x_pl]=pl;
}
else
end();
}
if (choice=='a'&&x_pl<n+1&&x_pl>1)
{
if (brd[y_pl][x_pl-1]!='+'&&brd[y_pl][x_pl-1]!=pl)
Code@Rena 54
{
if (pl_ptr_x==len)
pl_ptr_x=0;
pl_x_log[pl_ptr_x++]=x_pl;
if (pl_ptr_y==len)
pl_ptr_y=0;
pl_y_log[pl_ptr_y++]=y_pl;
if(!flg)
{
if (del_ptr_x==len)
del_ptr_x=0;
x_pl_del=pl_x_log[del_ptr_x++];
if (pl_ptr_y==len)
del_ptr_y=0;
y_pl_del=pl_y_log[del_ptr_y++];
gotoxy(x_pl_del,y_pl_del);
cout<<" ";
brd[y_pl_del][x_pl_del]=' ';
}
gotoxy(--x_pl,y_pl);
cout<<pl;
brd[y_pl][x_pl]=pl;
}
else
end();
}
if (choice=='d'&&x_pl<n&&x_pl>0)
{
if (brd[y_pl][x_pl+1]!='+'&&brd[y_pl][x_pl+1]!=pl)
{
Code@Rena 55
if (pl_ptr_x==len)
pl_ptr_x=0;
pl_x_log[pl_ptr_x++]=x_pl;
if (pl_ptr_y==len)
pl_ptr_y=0;
pl_y_log[pl_ptr_y++]=y_pl;
if(!flg)
{
if (del_ptr_x==len)
del_ptr_x=0;
x_pl_del=pl_x_log[del_ptr_x++];
if (pl_ptr_y==len)
del_ptr_y=0;
y_pl_del=pl_y_log[del_ptr_y++];
gotoxy(x_pl_del,y_pl_del);
cout<<" ";
brd[y_pl_del][x_pl_del]=' ';
}
gotoxy(++x_pl,y_pl);
cout<<pl;
brd[y_pl][x_pl]=pl;
}
else
end();
}
}
void food()
{
if (brd[y_food][x_food]!='-')
Code@Rena 56
{
flg=1;
score++;
disp();
do
{
y_food = (rand()%(m-2))+1;
x_food = (rand()%(n-2))+2;
}while(brd[y_food][x_food]=='+'||brd[y_food][x_food]==pl);
gotoxy(x_food,y_food);
cout<<"-";
brd[y_food][x_food]='-';
}
else
flg=0;
}
void hur()
{
for (int i=10; i<15; i++)
for (int k=8; k<12; k++)
{
brd[i][k]='+';
gotoxy(k,i);
cout<<"+";
}
}
void set_size()
{
HWND console = GetConsoleWindow();
Code@Rena 57
RECT r;
GetWindowRect(console, &r);
MoveWindow(console, r.left, r.top, 640, 480, TRUE);
}
//Main Function
int main()
{
set_size();
init(); //initializing board array
disp(); //disp the game
hur(); //disp the hurdles and store hurdles in the array
gotoxy(x_pl,y_pl); //positioning player
cout<<pl;
gotoxy(x_food,y_food); //positioning food
cout<<"-";
while (1)
{
run();
food();
}
}
Code@Rena 58
//Header Files
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
//Global variables
char turn;
bool draw = false;
char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}};
//Functions
void display_board()
{
cout<< "\t\t\t ----------------------\n\n";
cout<< "\t\t\t | | \n";
cout<< "\t\t\t " << board[0][0] << " | " << board[0][1] << " | " <<
board[0][2] << "\n";
cout<< "\t\t\t _____|_____|_____\n";
cout<< "\t\t\t | | \n";
cout<< "\t\t\t " << board[1][0] << " | " << board[1][1] << " | " <<
board[1][2] << "\n";
cout<< "\t\t\t _____|_____|_____\n";
cout<< "\t\t\t | | \n";
cout<< "\t\t\t " << board[2][0] << " | " << board[2][1] << " | " <<
board[2][2] << "\n";
cout<< "\t\t\t | | \n\n";
cout<< "\t\t\t ----------------------\n";
Code@Rena 59
void player_turn()
{
int choice;
int row = 0, column = 0;
if (turn == 'X')
{
cout << "\n\n\t\t\t Player 1 [X] turn : ";
}
else if (turn == 'O')
{
cout << "\n\n\t\t\t Player 2 [O] turn : ";
}
cin >> choice;
switch (choice)
{
case 1: row = 0; column = 0; break;
case 2: row = 0; column = 1; break;
case 3: row = 0; column = 2; break;
case 4: row = 1; column = 0; break;
case 5: row = 1; column = 1; break;
case 6: row = 1; column = 2; break;
case 7: row = 2; column = 0; break;
case 8: row = 2; column = 1; break;
case 9: row = 2; column = 2; break;
default:cout << "\n\t\t Invalid nmber..!! Try again...\n\n";
player_turn();
Code@Rena 60
bool gameover()
{
for (int i = 0; i < 3; i++)
{
if ((board[i][0] == board[i][1] && board[i][1] == board[i][2]) ||
(board[0][i] == board[1][i] && board[1][i] == board[2][i]) || (board[0][0] ==
board[1][1] && board[1][1] == board[2][2]) || (board[0][2] == board[1][1] &&
board[1][1] == board[2][0]))
{
return true;
}
}
Code@Rena 61
//Main Function
int main()
{
char ch1;
cout<<"\n\t\t |-------------------------------------|";
cout<<"\n\t\t |-------------------------------------|";
cout<<"\n\t\t || || \n\t\t || --------- --------- -------
-- || ";
cout<<"\n\t\t || | | | || ";
cout<<"\n\t\t || | | | || ";
cout<<"\n\t\t || | | | || ";
cout<<"\n\t\t || | --------- --------- || ";
cout<<"\n\t\t || || ";
Code@Rena 62
cout<<"\n\t\t || || ";
cout<<"\n\t\t |-------------------------------------|";
cout<<"\n\t\t |-------------------------------------|";
while (!gameover())
{
cout<< "\n\n\t\t Player 1 [X] v/s Player 2 [O]\n\n";
display_board();
player_turn();
Code@Rena 63
gameover();
system("cls");
}
C++ Artist -
/*Drawing code*/
//Header Files
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <fstream>
using namespace std;
//Functions
void gotoxy (int x, int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
char brd[80][80];
for (int i=0; i<80; i++)
{
for (int j=0; j<80; j++)
brd[i][j]=' ';
}
Code@Rena 65
if(pen){ cout<<"@";
brd[posy][posx]='@';}
break;
case 'c': cmd=0;
break;
case 'p': if (pen)
pen=0;
else
pen=1;
break;
}
}
system("cls");
cout<<"Do you want to write your drawing to a file ? <y/n> ";
char sel;
cin>>sel;
if (sel=='y')
{
ofstream fout("draw.txt", ios::out);
for (int i=0; i<80; i++)
{
for (int j=0; j<80; j++)
fout.put(brd[i][j]);
fout<<"\n";
}
}
}
Code@Rena 67
//Main Function
int main()
{
cout<<"--------------------------------------------------------------------------------"<<endl;
gotoxy(35,1);
cout<<"C++ Artist"<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"\n\tINSTRUCTIONS:";
cout<<"\n\t1.MOVE YOUR PEN USING w,a,s,d..";
cout<<"\n\t2.PRESS p TO LIFT AND PUT DOWN YOUR PEN..";
cout<<"\n\t3.PRESS c TO END YOUR DRAWING..";
cout<<"\n--------------------------------------------------------------------------------";
execute();
return 0;
}
Code@Rena 68
Output Screens
Code@Rena 69
Code@Rena 70
Code@Rena 71
Code@Rena 72
Code@Rena 73
Fun Section
Prorammes
Snake Game-
Code@Rena 74
C++ Artist -
Code@Rena 76
Problems faced
by us
While making this project we faced a few problems which
we tried to solve using C++ only and succeeded in doing
the same. Following is list of a few of those problems –
ShellExecute(NULL,"open","snakegame.exe",NU
LL,NULL,SW_SHOW);
ShellExecute(NULL,"open","tictactoe.exe",NULL,
NULL,SW_SHOW);
ShellExecute(NULL,"open","drawingartist.exe",
NULL,NULL,SW_SHOW);
//Header Files
#include "main_class.cpp"
#include <fstream>
using namespace std;
int main()
{
fstream file("list11.dat", ios::in|ios::out|ios::binary);
int n=1;
while (!file.eof())
{
cout<<"done";
code temp;
int pos = file.tellg();
file.read((char*)&temp, sizeof(temp));
if (temp.get_sno()>=41&&temp.get_sno()<=43)
{
code temp2 (n, temp.get_topic(),temp.get_name(), temp.get_title());
n++;
file.seekp(pos);
file.write((char*)&temp2, sizeof(temp2));
cout<<"step "<<n<<" done";
}
}
cout<<"Done";
getch();
return 0;}
Code@Rena 79
System
Requirements
1. Windows 95 or higher.
2. 32 MB of RAM.
3. 50 MB of free Disc Space.
4. The executables compiled by Dev-C++
will need MSVCRT.DLL (comes with
Windows 95 OSR 2 or higher).
Code@Rena 82
Bibliography
The sources that enabled us to gather information
regarding this project and thus be able to complete it
successfully are –
1. www.stackoverflow.com
2. www.cplusplus.com
3. www.developerfusion.com
4. Sumita Arora Class 12th and Class 11th
course books
5. Mastering C++ by KR Venugopal
6. The impeccable knowledge of our
teacher (Mrs. Chandni Agarwal)
Code@Rena 83
And keep
Coding on
Code@Rena!!