Vous êtes sur la page 1sur 20

BDA24202

COMPUTER PROGRAMMING

SECTION : 3
LECTURER : DR MUHAMAD ZAINI BIN YUNOS
PROJECT : GAME
GROUP MEMBERS
1.RONNIE CHAI TECK WEI
2.RAJA MOHD FIKRI BIN
TENGKU BADLI

MATRIC NO.
DD130055
AD130050

TITLE OF GAME : ARRANGING ALPHABET GAME

CONTENT

Table of Contents
Content.................................................................................................................................2
List of tables and figures......................................................................................................3
1.Introduction.......................................................................................................................4
1.1 About the game,advantages and constraint.............................................................6
2.Objectives..........................................................................................................................
7
3.Methodology......................................................................................................................
3.1 Program Code.........................................................................................................8
3.2 Flow Chart.............................................................................................................11
3.3 Pseudo Code..........................................................................................................16
4.Games Manual....................................................................................................................
4.1 Explanation how to run the games........................................................................18
4.2 Flowchart to play game.........................................................................................20
5.Conclusion......................................................................................................................20
6.References.......................................................................................................................21

List of Tables and Figures


Table 1[1].............................................................................................................................7

Figure 1[1]...........................................................................................................................4
Figure
2[2]..........................................................................................................................18

1. INTRODUCTION

A programming language is a formal constructed language designed to


communicate instructions to a machine, particularly a computer. Programming languages
can be used to create programs to control the behavior of a machine or to
express algorithms.
The earliest programming languages preceded the invention of the digital computer and
were used to direct the behavior of machines such as Jacquard looms and player
pianos.Thousands of different programming languages have been created, mainly in the
computer field, and many more still are being created every year. Many programming
languages require computation to be specified in an imperative form (i.e., as a sequence
of operations to perform), while other languages utilize other forms of program
specification such as the declarative form (i.e. the desired result is specified, not how to
achieve it).
The description of a programming language is usually split into the two components
of syntax (form) and semantics (meaning). Some languages are defined by a specification
document (for example, the C programming language is specified by an ISOStandard),
while other languages (such as Perl) have a dominant implementation that is treated as
a reference.

Figure 1[1]

In general,programming languages can be classified as follows :


a.Machine language
Machine language is used directly by the computer in all its calculations and processing.
It uses the combination of binary digits 0 to 1 to make up instructions. For example,the
machine code for adding up two integers might be :
01000011 00111010 00111101 01000001 00101011 01000010
b.Assembly language
A computer language that allows words and symbols(in English) to be used in an
unsophisticated manner to accomplish simple tasks. This is generally known as low level
language. This language is an improvement over machine language but still a bit vague.
Example of assembly language is as follows :
LOAD A
ADD B
STORE C
The result of running the above instructions causes the number in A to be added to the
number in B and the result to be stored for later used in C. Even though these are more
understandable than the machine language,the programmer needs to do some thinking in
figuring out the meaning of the instructions.
c.High level language
A programming language that use words and symbols to make the programs relatively
easy to read and write. Example of high level languages are
FORTRAN,COBOL,BASIC,PASCAL,C,C++,ADA,JAVA,etc.For example the c++
statement :
C= A + B;
Causes the number in A to be added to the number in B and the result to be stored for
later use in C. C language was developed by Dennis Ritchie in early 1970s,while C++
language was developed by Bjarne Stroustrup in the early 1980s.

1.1 INTRODUCTION-ABOUT THE GAME,ADVANTAGES,CONSTRAINT


This game is a scramble game. The computer will provide some alphabet. The user will
have to rearrange the randomize alphabet to form a word. The user will be given point for
each correct answer. And they will be given another sets of alphabet to form a word after
each round. At the end of the game the user will know their final score and they can try
again if they want to.
The advantages of the game is it enable the user to think in order to arrange the alphabet
correctly. The code of this game is simple and the technique had been taught in the lab. In
this game we use else if statement, switch and break. By just knowing simple step to
write code we can produce a game.
The constraint is that not much word has been prepared by both of us due to lack of time.
Besides that the code will be quite long if more sets of arranging alphabet provided for
the user. So in order to fulfill the requirement of this project we just provide 3 sets of
alphabet to arrange. If anyone have interest to bring our game to a higher level they can
add more difficult and long alphabet.

2. OBJECTIVES
In this project, we make a game by writing code in dev c++ software. The objectives of
this project are as follows :
Table 1[1]
NO
1

OBJECTIVES
Learn how to use programming software such as dev c++ 4.9.2 & dev c++
5.9.1(for windows 8)

Learn how to write advance coding

3
4

Applying the knowledge that we learn in the lab to create a game


Learn how program instructions are stored and processed

Improving our writing code skills

Learn different types of C++ statements such as output statement,input


statement,assignment statements,conditional statements,loop statements.

From this project we will also learn how to correct the error done during writing
the code.

3.METHODOLOGY
PROGRAM CODE
#include <stdio.h>
#include <conio.h.>
void correct(), wrong();
int point;
main()
{ int i, a[5];
printf("\t\tWelcome to Ron's and Raja's SCRAMBLE GAME");
printf("\n\t\t________________________________________");
printf("\n****************************************************************
***************");
printf("\n\nThis game is to rearrange the randomize alphabet to form a word.. ");
printf("\n\n***************************************************************
****************");

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


{
printf("\n\n\t\t\tRound %d", i+1);
printf("\n\t\t\t********");
if(i==0)
{
printf("\n\nPlease rearranged the following alphabet to form a word..");
printf("\n\n\talnichmeca");
printf("\n\n1 - mechanical\n2 - mcehanicla\n3 - mehcanical\n>>");
scanf("%d", &a[i]);
if(a[i]==1)
correct();
else if(a[i]==2)
wrong();
else if(a[i]==3)
wrong();
}
if(i==1)
{
printf("\n\nPlease rearranged the following alphabet to form a word..");

printf("\n\n\tgnireenigne");
printf("\n\n1 - ngeineering\n2 - engineering\n3 - enginerieng\n>>");
scanf("%d", &a[i]);
if(a[i]==1)
wrong();
else if(a[i]==2)
correct();
else if(a[i]==3)
wrong();
}
if(i==2)
{
printf("\n\nPlease rearranged the following alphabet to form a word..");
printf("\n\n\traeg");
printf("\n\n1 - gear\n2 - gaer\n3 - grea\n>>");
scanf("%d", &a[i]);
if(a[i]==1)
correct();
else if(a[i]==2)
wrong();
else if(a[i]==3)
wrong();
}
}
printf("\n\n\nYour final score is %d !!", point);
switch (point)
{
case 3 : printf("\n\nCONGRATULATIONS. You get full mark !!! "); break;
case 2 : printf("\nYou get 2 out of 3 mark. Not bad. Please try again :) "); break;
case 1 : printf("\nYou only get 1 mark. Please try again :) "); break;
}
}
void correct()
{
system("cls");
printf("\n\a\aYou are correct :D\n\n");
printf("\n****************************************************************

10

***************");
point++;
}
void wrong()
{
system("cls");
printf("\n\a\a\aYou are wrong :(\n\n");
printf("\n****************************************************************
***************");
}

11

FLOW CHART

Start

Declare int i, a[5]

i=0

i=0

i=1

i<3

i ++

Print Final Score

Final score
== 1

Final score
== 2

Print CONGRATULATIONS.
You get full mark

Print You
only get 1
mark. Please
try again
Print You
get 2 out of 3
mark. Not
bad. Please
try again

End

12

Print Please enter answer


of the question Round 1

Scanf a[i]

a [i] == 1

correct ()

a [i] == 2

wrong ()

N
wrong ()

13

Print Please enter answer


of the question Round 2

Scanf a[i]

a [i] == 1

wrong ()

a [i] == 2

correct ()

N
wrong ()

14

Print Please enter answer


of the question Round 3

Scanf a[i]

a [i] == 1

a [i] == 2

correct ()

wrong ()

N
wrong ()

15

correct ()

system cls

Print You are correct :D

point ++

wrong ()

system cls

Print You are wrong :(

16

PSEUDO CODE
1.
2.
3.
4.

START the program.


DECLARE int i, a[5].
i = 0.
If I = 0.
a. PRINT Please enter answer of the question Round 1.
b. SCAN a[i].
c. If a[i] == 1.
a. Correct ().
d. Else if a[i] ==2.
a. Wrong ().
e. Else.
a. Wrong ().
5. Else if I = 1.
f. PRINT Please enter answer of the question Round 2.
g. SCAN a[i].
h. If a[i] == 1.
a. Wrong ().
i. Else if a[i] ==2.
a. Correct ().
j. Else.
a. Wrong ().
6. Else.
k. PRINT Please enter answer of the question Round 3.
l. SCAN a[i].
m. If a[i] == 1.
a. Correct ().
n. Else if a[i] ==2.
a. Wrong ().
o. Else.
a. Wrong ().
7. Then i++.
8. If I < 3.
a. Go back to question selection.
9. Else.
a. PRINT Final score.
10. If Final score == 1.
a. Print You only get 1 mark. Please try again.
11. Else if Final score ==2.
a. Print You get 2 out of 3 mark. Not bad. Please try again.
12. Else.
a. CONGRATULATIONS. You get full mark.
13. END.

17

18

4. GAMES MANUAL

Explanation how to run the game


This game is simple. It is an arranging alphabet game. This is how we run the game. First
of all we need to have a compiler. The compiler can be either DevC++ 4.9.2 or DevC++
5.1.1. It have different version depend on the users type of windows. For us,both of us
use DevC++ 5.1.1 because our computer are using windows 8. Then when we already
have the compiler, open the code that we created and copy paste the code to the compiler.
After that we need to compile & run the code.
The compiler will show a display a greeting to the user and instruction on how to play the
game. Compiler will show some alphabet and 3 choice of answer for the user to choose
the correct one. Then user will have to choose the correct answer.
If the users answer is correct the compiler will congratulate the user and if the answer is
wrong the compiler will tell that the answer is wrong. After answering the first question,
the compiler will display next set of alphabet for the user. The same process repeated
until the user answer 3 sets of alphabet. Finally the output is the compiler will count the
correct answer and tell how many points the user have obtained. This is the end of the
game.

Figure 2[2]

Flowchart how to play


the game

Start

Randomize alphabets given to user

Compiler check the answer


One
= 1 point
Usercorrect
chooseanswer
the answer
between 1
Two
=2
points
or Compiler
2 correct
or 3 answer
display results
End
Three correct answer
=3 points

19

5. CONCLUSION
In conclusion,this project has been done successfully. We have learn how to write code to
produce a game. Although the game that we created is a simple game, however we realize
it is hard even to write a simple game. We went through lots of error before able to
complete it. From that error we know where are our mistake and went through internet
and books to repair the error of the code. Besides that we also learn how to use DevC++
well after this project as because before this we only use this software in the lab. We
apply for, else if, switch and system(cls) in our game code. Although we learn only a
few in the lab, this project enable us to explore more ways to code.
One of the most important thing of this project is we gain teamwork in order to complete
this task. We did this project as partner and the both of us help each other and keep
advising each other to find more information related to this project.
Before ending this report, we would like to thank our computer programming lecturer Dr
Muhammad Zaini Bin Yunos for guiding us to complete this project.

20

6. REFERENCES
[1] C++ Programming An Introduction, Norhashidah Mohd.Ali, Tan Guat Yew, Penerbit
Universiti Sains Malaysia, 2007.
[2] The C++ Programming Language, Special Edition, Bjarne Stroustrup,Addison
Wesley,2000.
[3] C++ Coding Standards, Herb Sutter, Andrei Alexandrescu, Addison-Wesley Pearson
Education.2004.
[4] http://en.wikipedia.org/wiki/Programming_language
[5] http://www.slideshare.net/shammimehra/c-25357907?qid=2f99cd16-9891-4c7abe9d-2b6edc3a14ed&v=qf1&b=&from_search=5
[6] http://www.gametutorials.com/tutorials/cpp-tutorials/

Vous aimerez peut-être aussi