Вы находитесь на странице: 1из 17

HOLY TRINITY SCHOOL

AFFILIATED TO CBSE, NEW DELHI-AFFILIATION NO: 930027

KANJIKODE WEST, PALAKKAD

COMPUTER SCIENCE PROJECT REPORT ON MEMORY GAME

Submitted by
Gokul.P.V XI-A 2010-2011

CONTENTS
S CONTENTS NO. 1 Certificate 2 3 4 5 6 7 Acknowledgement Introduction Source Code Output Conclusion Bibliography Page number 3 4 5 6 11 14 15

CERTIFICATE
Certified that this is the bonafied project work of done during the year 2010-2011

Date:

Head of the department

Submitted for practical examination held on at Holy Trinity School, Kanjikode, Palakkad.

Principal

Internal Examiner

External Examiner

School Seal

ACKNOWLEDEMENT
In preparing this report and along with it, in leading to its successful completion, my appreciation and thanks are to Mrs.S.V.Ajeetha, our computer science teacher for her generous ideas and help. I would also like to record my sincere gratitude to the principal, Mrs.Vyja.S.Kumar for making available all the facilities for the submission of my project.

INTRODUCTION
C++ originated with Bjarne Stroustrup. In the simplest sense, if not the most accurate, we can consider it to be a better. Although it is not an entirely new language C+ + represents a significant extension of C abilities. We might then consider C to be a subset of C++. C++ supports essentially every desirable ones of its predecessors. But provides general language as well as adding OOP. C++ does not force you to use its OOP features. You can simply create structured code that uses only C++s non OOP features. A C++ program is structured in a specific, particular manner. C++ is a language and therefore has a grammar similar to a spoken language like English. The grammar of computer language is usually much simpler than spoken languages but comes with the disadvantage of having stricter rules. Applying this structured or grammar to the language is what allows the computer to understand the program and what it is support to do. The overall program has a structure, but it is also important to understand the purpose of part of that structure. By analogy, a textbook can be spilt into sections, chapters, paragraphs, sentences and words(the structure), but it is also necessary to understand the overall meaning of the words, the sentences and chapters to fully understand the content
5

of the textbook. You can think if this as the semantics of the program.

SOURCE CODE
//Project-Memory Game #include<iostream.h> #include<iomanip.h> #include<conio.h> #include<stdlib.h> #include<time.h> #define INIT 1000 void main() { int base[8][8]; char mask[8][8],check,X,Y,Z; int row,column,side,value,j,j1,j2,j3,j4,val_done,level, no_of_attempts,score,count_left; do {

clrscr(); cout<<"Memory Game\n\n"; cout<<"Enter the level (1-4): "; cin>>level; } while (level<1 || level>4); //Using twice the level value as the side of the matrix side=level*2; //Initialize the base and mask arrays for(row=0;row<side;row++)
6

for(column=0;column<side;column++) { base[row][column]=INIT; mask[row][column]= 'X'; }

} //Setting up the base for(j=0;j<32;j++) { /*Getting the random number for value and positions*/ value= rand()%1000; j1 = rand()%side; j2 = rand()%side; j3 = rand()%side; j4 = rand()%side; /*Two if statements to set up the pair of values at distinct locations*/ if(base[j1][j2]==INIT) base[j1][j2] = value; else { val_done = 1; for(row=0;row<side;row++) { for(column=0;column<side;column++) { if(base[row][column]==INIT && val_done==1) {
7

base[row][column]=value; val_done=0; } } }

} if(base[j3][j4]==INIT) base[j3][j4]=value; else { val_done = 1; for(row=side-1;row>=0;row--) { for(column=side1;column>=0;column--) { if(base[row][column]==INIT && { } } } val_done==1) base[row][column] = value; val_done =0;

} }//end for loop no_of_attempts=0; count_left = side*side; do { clrscr(); for(row=0;row<side;row++)


8

for(column=0;column<side;column++) { if(mask[row][column]=='Y' || mask[row] [column]=='Z') cout<<setw(9)<<base[row] else cout<<'\t'<<mask[row][column];

[column];

} cout<<"\n"; } cout<<"Enter the row and column numbers separated by space: "; cin>>j1>>j2; cout<<"Enter the second row and column numbers separated by space: "; cin>>j3>>j4; //if values entered are greater than side continue if(j1>side || j2>side || j3>side || j4>side) continue; no_of_attempts++; if(mask[j1-1][j2-1]=='X') mask[j1-1][j2-2]='Y'; else { /*the value has already been identified, so continue*/
9

} if(mask[j3-1][j4-1]=='X') mask[j3-1][j4-1]='Y'; else continue; clrscr(); for(row=0;row<side;row++) { for(column=0;column<side;column++) { if(mask[row][column]=='Y') { if(base[j1-1][j2-1]== base[j3-1] [j4-1]) { mask[j1-1][j2-1]='Z'; mask[j3-1][j4-1]='Z'; count_left=count_left-2; } else mask[row][column]='X'; cout<<setw(9)<<base[row] [column]; } else if(mask[row][column]=='Z') cout<<setw(9)<<base[row] else cout<<'\t'<<mask[row][column]; } cout<<"\n";
10

continue;

[column];

} cout<<"Press C to continue or Q to quit: "; cin>>check; } while(count_left>0 && check!='Q' && check! ='q'); if((check!='Q')&&(check!='q')) { score=(side*side) + (side*side/2no_of_attempts); cout<<"\n\nScore: "<<score<<"\n"; } getch(); }//end main

OUTPUT
The output of the above project will be: Memory Game Enter the level (1-4): 1 X X X X Enter the row and column numbers separated by space: 1 1 Enter the second row and column numbers separated by space: 1 2 724 41 X X Press C to continue or Q to quit: C X X X X
11

Enter the row and column numbers separated by space: 1 1 Enter the second row and column numbers separated by space: 2 1 724 X 41 X Press C to continue or Q to quit: C X X X X Enter the row and column numbers separated by space: 1 1 Enter the second row and column numbers separated by space: 2 2 724 X X 724 Press C to continue or Q quit: C 724 X X 724 Enter the row and column numbers separated by space: 2 1 Enter the second row and column numbers separated by space: 1 2 724 41 41 724 Press C to continue or Q to quit: C Score:3 Memory Game Enter the level (1-4): 2 X X X X X X X X

X X X X

X X X X

12

Enter the row and column numbers separated by space: 1 1 Enter the second row and column numbers separated by space: 1 2 491 41 X X X X X X X X X X X X X X Press C to continue or Q to quit: C X X X X X X X X X X X X X X X X Enter the row and column numbers separated by space: 1 3 Enter the second row and column numbers separated by space: 3 1 X X 391 X X X X X 724 X X X X X X X Press C to continue or Q to quit: C X X X X X X X X X X X X X X X X Enter the row and column numbers separated by space: 1 4 Enter the second row and column numbers separated by space: 2 4 X X X 382 X X X 912 X X X X
13

X X X X Press C to continue or Q quit: C X X X X X X X X X X X X X X X X Enter the row and column numbers separated by space: 3 3 Enter the second row and column numbers separated by space: 4 4 X X X X X X X X X X 724 X X X X 912 Press C to continue or Q to quit: Q

CONCLUSION
In the above project, the user is prompted to enter the level. In the first, case level entered is 1. By the project logic, the side of matrix chosen is 2. Now random numbers are selected with their positions using the rand() function; and a masked matrix is displayed to the user. The user makes his/her first guess for the first two elements, but they are distinct. So, the matrix closes on him/her. In second attempt, he/she tries the values in the first column, but they are also distinct. Now its all open and he/she correctly recognizes the pairs and finally gets a score of 3 by the scoring logic.

14

In the second attempt the level 2 has been entered and after attempts, option q has been selected. The game program is an example of Event Driven programming. The game programs give mental relaxation and refreshment. The memory game also helps to increase our memory power.

BIBLIOGRAPHY
NEW APPROACH TO CBSE COMPUTER SCIENCE WITH C++ - CLASS XI

15

16

17

Вам также может понравиться