Sunteți pe pagina 1din 83

Code@Rena 2

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.

Names: Bipin Kalra


Jatin Katyal
Chinmay Bindal
Code@Rena 3

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.

Mrs Chandni Agarwal


(PGT Computer Science)
Code@Rena 4

Index
What is Code@Rena

Source of our Idea!

Manual to the Project

Major topics covered

Header Files used

Main Class

Division in modules and files

Source Code

Codes of few Peripheries

Output Screens

Problems Faced and Solutions

Learning via this Project

What makes this stand out!

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.

1. Beginning with, The greeting screen gives a brief


description of our project i.e. Code@Rena and lists
the names of its programmers.
Pressing any key would take you to the login screen.

Important Mention - A draw code which has been


created by us only has been used in the creation of
the home screen and the presentation of all the
screens.
Code@Rena 8

2. The Login page contains two options namely:


a. Login – This you can use if you have already
registered at Code@Rena realier and have
already created an account.
b. Sign Up – This lets you create a new account for
future use.
Code@Rena 9

3. After logging in you can view the options of


Code@Rena Main menu. We have divided our
directory of codes primarily into 4 sections –
a. Class 11th
b. Class 12th
c. HOTS questions
d. FUN Section
After this, The codes in Class 11th and Class 12th
sections have further been divided topic wise
whereas the programmes in HOTS and FUN sections
have been directly listed. After Making the necessary
choices and finding the desired programme, one can
opt out of the two available options.
a. Open Code – To compile and run the
programme. (opens in new window)
b. View Source Code – To view the source code of
the programme in the same window.
Code@Rena 10

4. Once through with viewing or working with the


desired code one can give suggestions regarding
any improvements that can be made or leave
remarks of appreciation on the SUGGESTION
PANEL.

5. Once through with the procedure (which can always


be skipped) one can flip back to the menus to search
for another code or exit the programme post the
desired use.
Code@Rena 11

Flowchart
Login Page

Login Sign Up
Fill in the required
details to sign up to
Code@Rena and
proceed to login.

Class 11th Class 12th HOTS FUN

After making the


Required necessary choices in
Code the hierarchical
menus.

View Code Run Code

Suggestions

Continue Exit
Code@Rena 12

Major Topics
Covered
Loops and Selection Statements

2D arrays

String arrays

Structures

Classes and OOPS concepts

Inheritence

Data file handling

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()

All the defined functions are public


members of the class.
Code@Rena 15

Source Code of the Main Class -


//Header files
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;

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

file has been created for each different


category.)
ii. A few of our codes use text files for storing
their output. (for example – our drawing code)
iii. There is a separate C++ file for each of the
codes that we offer in our directory of codes.
(Saved in separate folders for each type).
Even though this created a huge file base to
maintain but allows easy access to each code
individually because of the modular nature of
the approach.
b. Main class – The main class of our project has
also been separately saved as a C++ file and
incorporated in other codes as a header file.
Code@Rena 19

Source Code
Main Programme -
/*CODE@RENA*/

//Use of #define funtion


#define _WIN32_WINNT 0x0500

//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];

//Prototypes to the funtions used


void set_size(); //To set the size of output window
void main_page(); //Displays the welcome page
void in(); //Displays the main login page
void Signup(); //Helps create a new user
char* getpass(); //Funtion to enter password
void Signin(); //Checks for the authenticity of entered
credentials
int check(char user[30]); //Checks for user with a common username
void titles (char *topic, int std); //Returns the title selected to seacrh funtion
int findsno(char* topic); //Detects the main topic chosen
Code@Rena 20

void menu1(); //Displays the Main Menu


void menu11(); //Next four funtions display the submenus
void menu12();
void menu13();
void menu14();
void search(int no,int std,char *top); //Main searching mechanism
void open(code c1); //Function to open or view the selected
code
void openfun(int t); //Function to open codes of the fun section
void create(char *top); //Funtion to create new C++ file
void review(); //Function to accept reviews from the user
void review_show(); //Function to display existing reviews

//Class used to manage the users


class Sign_up
{
char user[20];
char pass[20];
char name[30];
char email[40];
int age;
public:

void create()
{
system("cls");
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\t Sign Up"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
Code@Rena 21

cout<<"\t\t\tEnter your name - ";


cin.ignore();
cin.getline(name,30);
cout<<"\t\t\tEnter email ID - ";
cin.getline(email,40);
cout<<"\t\t\tEnter age - ";
cin>>age;
cout<<"\n--------------------------------------------------------------------------------
"<<endl;
cout<<"\t\t\tEnter User ID - ";
cin>>user;

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();
}
}

char* get_id () //Function to return username


{
return user;
}

char* get_pass () //Function to return password


{
return pass;
}
};

//class used for reviews


class reviews
{
char r[1000];
Code@Rena 23

public:
void enter()
{
cin.getline(r,1000,'$');
}

void display()
{
cout<<r;
}
};

//Main Function
int main()
{
set_size();
main_page();
in();

getch();
return 0;
}

//Funtions used in the program


void set_size()
{
HWND console = GetConsoleWindow();
RECT r;
GetWindowRect(console, &r);
Code@Rena 24

MoveWindow(console, r.left, r.top, 1200, 700, TRUE);


}

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

cout<<" A project by Bipin, Jatin and Chinmay... ";


cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
cout<<" Press any key to continue...";
getch();
}

void in()
{
Sign_up S;
system("cls");
int ans;
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\tWelcome to Code@Rena..."<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;

cout<<"\t\t\t\t 1.LOGIN IN"


<<"\n\t\t\t\t 2.SIGN UP"<<endl<<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;

cout<<"\t\t\tEnter username - ";


cin>>username;
cout<<"\t\t\tEnter Password - ";
strcpy(password,getpass());

while(!fin.eof()) //Loop to check the authenticity of the user


{
fin.read((char*)&S,sizeof(S));
if(!strcmpi(S.get_id(),username))
{
if(!strcmpi(S.get_pass(),password))
{
cout<<"\n\nCorrect username and password. (Press any key
to proceed)..."<<endl;
cout<<"-----------------------------------------------------------------
---------------";
getch();
menu1();
}
}
}
cout<<"\n\nEither of the username or password are incorrect."
<<"\nPress any key to try again..."<<endl;
cout<<"--------------------------------------------------------------------------------";
Code@Rena 29

getch();
Signin();
}

int check (char *user)


{
ifstream file ("sign.dat", ios::binary);
Sign_up temp;

while (file.read((char*)&temp, sizeof(temp)))


{
if(strcmpi(user,temp.get_id())==0)
return 1;
}
return 0;
}

void titles (char *topic, int std)


{
system("cls");
cout<<"--------------------------------------------------------------------------------";
cout<<"\t\t\t\tList of codes"<<endl;
cout<<"--------------------------------------------------------------------------------
"<<endl;
ifstream file;
if (std==11)
file.open ("list11.dat", ios::binary);
else if (std==12)
file.open ("list12.dat", ios::binary);
Code@Rena 30

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

int findsno(char* topic)


{
ifstream 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;
}
int cnt=0;
code c;
while(f.read((char*)&c,sizeof(c)))
{
if(!strcmpi(c.get_topic(),topic))
cnt++;
}
f.close();
return cnt+1;
}

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

cout<<"\n\t\t\t1. Getting Started with C++."


<<"\n\t\t\t2. Basic Programmes"
<<"\n\t\t\t3. Ctype"
<<"\n\t\t\t4. Flow of Control"
<<"\n\t\t\t5. Data Handling"
<<"\n\t\t\t6. Arrays"
<<"\n\t\t\t7. Functions"
<<"\n\t\t\t8. Integer Arrays"
<<"\n\t\t\t9. String"
<<"\n\t\t\t10.Loops"
<<"\n\t\t\t11. Nested Loops"
<<"\n\t\t\t12. Structures"<<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,"Getting Started with C++");
break;

case 2: strcpy(l,"Basic");
break;

case 3: strcpy(l,"Ctype");
break;
Code@Rena 36

case 4: strcpy(l,"Flow of Control");


break;

case 5: strcpy(l,"Data Handling");


break;

case 6: strcpy(l,"Array");
break;

case 7: strcpy(l,"Functions");
break;

case 8: strcpy(l,"Integer Array");


break;

case 9: strcpy(l,"String");
break;

case 10: strcpy(l,"Loops");


break;

case 11: strcpy(l,"Nested Loops");


break;

case 12: strcpy(l,"Structures");


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 2: strcpy(l,"Binary Files");


break;

case 3: strcpy(l,"TextFiles");
break;

case 4: strcpy(l,"Classes");
break;

case 5: strcpy(l,"Constructor nd Destructor");


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);
}

void search(int no,int std,char *top)


{
Code@Rena 41

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();
}

void open(code c1)


{

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();
}

void create(char *top)


Code@Rena 44

{
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

case 12: strcat(temp,"12\\"); break;


case 13: strcat(temp,"HOTS\\"); break;
}

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<<"\nPlease enter your choice (Y/N)- ";


char ans;
cin>>ans;
if(ans=='y'||ans=='y')
{
system("cls");
cout<<"--------------------------------------------------------------------------------
";
Code@Rena 47

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;
}

cout<<"\n\nPress any key to continue to main menu..."<<endl;


cout<<"--------------------------------------------------------------------------------";
getch();
menu1();
}
Code@Rena 49

Source codes to other integral


parts of our program -
Snake Game -
/*Snake Game*/

//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

Tic Tac Toe -


/*Tic Tac Toe*/

//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

if (turn == 'X' && board[row][column] != 'X' && board[row][column] != 'O')


{
board[row][column] = 'X';
turn = 'O';
}
else if (turn == 'O' && board[row][column] != 'X' && board[row][column] != 'O')
{
board[row][column] = 'O';
turn = 'X';
}
else
{
cout << "\n\t\t Cell is preoccupied..!! Try again...\n\n";
player_turn();
}
}

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

for (int i = 0; i < 3; i++)


{
for (int j = 0; j < 3; j++)
{
if (board[i][j] != 'X' && board[i][j] != 'O')
{
return false;
}
}
}
draw = true;
return true;
}

//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 || | |-------| | || ";
cout<<"\n\t\t || | | | | || ";
cout<<"\n\t\t || | | | --------- || ";

cout<<"\n\t\t || || ";

cout<<"\n\t\t || --------- --------- --------- || ";


cout<<"\n\t\t || | | | | || ";
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\n\n\t\t\t Wanna play..? (Y/N) - ";


cin>>ch1;
if(ch1=='Y'||ch1=='y')
{
system("cls");
turn = 'X';

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");
}

if (turn == 'O' && !draw)


{
display_board();
cout << endl << endl << "Player 1 [X] Wins...! Game Over...!\n";
}
else if (turn == 'X' && !draw)
{
display_board();
cout << endl << endl << "Player 2 [O] Wins...! Game Over...!\n";
}
else
{
display_board();
cout << endl << endl << "It's a draw...! Game Over...!\n";
}
}
else
{
system("cls");
cout<<"\n\n\n\n\t\tNot ready to play yet..? Come back prepared; soon...";
}
}
Code@Rena 64

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);
}

void execute() //Complete functioning of the program


{
int cmd=1;

char brd[80][80];
for (int i=0; i<80; i++)
{
for (int j=0; j<80; j++)
brd[i][j]=' ';
}
Code@Rena 65

int brdx, brdy;


int pen=1;
int posx = 1;
int posy = 9;
gotoxy(posx, posy);
brd[posy][posx]='@';
while (cmd)
{
switch (getch()){
case 'a':if(posx>1)
posx--;
gotoxy(posx, posy);
if(pen){ cout<<"@";
brd[posy][posx]='@';}
break;
case 'd':if(posx<80)
posx++;
gotoxy(posx, posy);
if(pen){ cout<<"@";
brd[posy][posx]='@';}
break;
case 'w':if(posy>9)
posy--;
gotoxy(posx, posy);
if(pen){ cout<<"@";
brd[posy][posx]='@';}
break;
case 's':if(posy<80)
posy++;
gotoxy(posx, posy);
Code@Rena 66

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

Tic Tac Toe-


Code@Rena 75

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 –

1. Shortcomings of System() Command and use of


Powershell() commands –
System command is a platform specific command i.e.
it functions only on windows platform i.e. it is
platform dependent. It's slow and insecure as well.
Calling "system" is literally like typing a command
into the windows command prompt. There is a ton of
setup and teardown for your application to make
such a call. Therefore if an alternative exists. Use of
a system command should be avoided.
eg. System(“pause”); can be easily and effectively
replaced by getch(); wherein the latter serves as a
much better alternative to the purpose of stagnating
the programme for a while.
Code@Rena 77

Shell commands overcome these problems to an


extent and furthermore are able to open the
required code in a new window which was our
ultimate motive. Therefore we have used shell
commands in our codes to serve the purpose.
eg. Few Shell commands in our programme –

 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);

2. Errors in Binary file –


A tiny mistake in our code and our main binary file
got totally messed up as we had made certain
mistakes in the display names and the call names of
our programmes.
But we solved the problem in a completely justified
programming way by making a correction code
which would correct the binary file with just one run
and spare us the time of making another binary file.

SOURCE CODE FOR CORRECTION PROGRAM -


Code@Rena 78

//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

3. Use of flush() command – Flushing is used to empty


the buffer of a buffered stream.
A set amount of information is transferred to a buffer
before being flushed and written to an external data
store (a file). The benefits of a Buffered stream is
that it is faster and more efficient as writing to the
disk costs memory so doing it in larger batches with
the help of a buffer is useful.
The flush function manually flushes the buffer. You
may wish to do this when closing an application to
ensure there is no left over information in the buffer.

Thus we used this function to clear out the buffer


while writing to the file containing records of various
users.
Code@Rena 80

Learning via this


project
This project offered us a lot of learning opportunities
which we availed heartily and thus post completing this
project we have learnt a few new topics, techniques and
segments of C++ programming language which we were
not aware of its completion. Some of these include –
Practical usage of Data File Handling

Use of Shell Commands

Practical usage of Pointers

Sensitivity of Binary files and ways to correct


them
Usage of a class over various Programmes by
saving and calling it as an header file
Dynamic initialisation (Dynamic binding) of
arrays i.e. defining size of array at runtime.
Use of Data file handling to create and store
templates for our programme's presentation
Code@Rena 81

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!!

S-ar putea să vă placă și