Upload
dong-lai
View
222
Download
0
Embed Size (px)
Citation preview
8/2/2019 Algorithmic and Problem Solving
1/13
Ha Le Do Page 0
Introducing to
programming,algorithmic and problem
solvingTUTOR : MOHAMMED
This is the first weekly submission due to the first lab activity
of 2012 year. This document contain the the output and the
source code for all of the three task which are required to
finish. Also there is the answer to the questions of
HouseDrawing task and evidence to support the answer.
There is one more extra task that is finished, the extension
drawing base on the HouseDrawing task.
Student : Ha Le Do6/3/2012
8/2/2019 Algorithmic and Problem Solving
2/13
Introducing to programming, algorithmic and problem solving
1
ALGORITHMIC AND PROBLEM SOLVING , INTRODCTION TO
PROGRAMMING
1/. HELLO WORLD EXTENSION
Beside putting in the code for the output of the text hello world , I have a test to run on the
output of numeric character and even calculation. For the part of calculation, the aim for the
output is not number becasue this is not programming for calculation but only for the reliability
of the system. Therefore if you input a math calculation with an answer into the system will
give the system the answer is true or false . In this case the input is 1+1=2 therefor the
output is True.
Source code:
program HelloWorld;
begin
WriteLn('Hello World');
WriteLn( 156);
WriteLn ( 1 + 1 = 2);
end.
Output:
8/2/2019 Algorithmic and Problem Solving
3/13
Introducing to programming, algorithmic and problem solving
2
Build script for HelloWorld.pas
#!/bin/sh
echo "Building my HelloWorld program"
fpc -S2 HelloWorld.pas
echo "Done!"
This code is used in a bash file. Which is allow to manage and compile one or more pas file in
just one single step. It just simply putting in the fpc-S2 step for all the file in the bash file then
simply compile the bash file and all the pas file which are linked to the bash file will be
compiled. This will save time but will put a lot of memory to function.
8/2/2019 Algorithmic and Problem Solving
4/13
Introducing to programming, algorithmic and problem solving
3
3/.HOUSE DRAWING
Programmings sequence:
Programmings sequence is one the of the most important and basic structure of any
programming language. It will allow the programmer decide the order of any procedure or
action which is made within the the source code. A sequence of action is how the program
work and the way you put the actions in the order will decide which task will be done first and
which will be done at last.
The sequence in programming language usually put the first action above the second one and
go on until the last action. Therefore if theres been a change occured in the sequence, the
program will change the procedure and therefore the output will be different. The output is
depended on the order of the each action therefore it will be different if the actions order has
been changed. This following example have been demonstrated on the program HouseDrawing:
BEFORE begin
OpenAudio();
OpenGraphicsWindow('Saya', 800, 600);
LoadDefaultColors();
ClearScreen(ColorWhite);
FillEllipse ( ColorGreen, 0, 400, 800, 400 );
FillRectangle( ColorBlue, 300, 300, 200, 200);FillTriangle(ColorRed, 250, 300,
400, 150,
550, 300);
FillRectangle (ColorRed, 300, 350, 50, 50);
FillRectangle (ColorRed, 390, 350, 60, 150);
AFTER
(take a
look at
the
changeof
order)
OpenGraphicsWindow('Saya', 800, 600);
LoadDefaultColors();
ClearScreen(ColorWhite);
FillRectangle( ColorBlue, 300, 300, 200, 200);
FillEllipse ( ColorGreen, 0, 400, 800, 400 );FillTriangle(ColorRed, 250, 300,
400, 150,
550, 300);
8/2/2019 Algorithmic and Problem Solving
5/13
Introducing to programming, algorithmic and problem solving
4
BEFORE FillRectangle (ColorGrey, 680, 400, 50, 100);
FillCircle ( ColorGreen, 702, 350, 70);
RefreshScreen();
Delay(15000);
CloseAudio();
ReleaseAllResources();
AFTER FillCircle ( ColorGreen, 702, 350, 70);
FillRectangle (ColorGrey, 680, 400, 50, 100);
RefreshScreen();
Delay(15000);
CloseAudio();
ReleaseAllResources();
Statement : In a programming system , statement is used to declare a word and make it into an
action. Sometimes its a basic statement which is existed already for the program. Sometime
the programmer have to declare it at the beginning of the coding phase to make it available
through the programming.
Procedure : In a program, there could be a lot of actions that are required in 1
moment.Therefore the programmer will need to group those actions(tasks) in a group. Those
kind of group mean procedures. To make it easier to remember and to group the tasks , the
programmer will name each procedure a different name and declare it. Then he/she will put in
the code for the action which will take in the procedure. Those actions are called Procedure
calls. Those action are coded in the same way as a normal code. Procedure call is one kind of
the Statement. When you declared it, everytime you type in your Procedure callits a call for
the program to run all of the action in that Procedure.
In house drawing , beside putting in image , we have to use the resources from swingame. All of
the procedure from swingame have been declared to be Statements therefore by saying at the
beginning of the programming code: uses SwinGame; means all the statements of SwinGame will
be available to use. Therefore we could see through the program, before the image of the
drawing house appear , there is sound effect and window screen. It is appear because we type
in the Procedure call which will link us to all the action which are available through thoseprocedures :
OpenAudio();
OpenGraphicsWindow('Saya', 800, 600);
LoadDefaultColors();
8/2/2019 Algorithmic and Problem Solving
6/13
Introducing to programming, algorithmic and problem solving
5
program HouseDrawing;
uses SwinGame;
begin
OpenAudio();
OpenGraphicsWindow('Saya', 800, 600);
LoadDefaultColors();
ClearScreen(ColorWhite);
FillEllipse ( ColorGreen, 0, 400, 800, 400 );
FillRectangle( ColorBlue, 300, 300, 200, 200);
FillTriangle(ColorRed, 250, 300,
400, 150,
550, 300);
8/2/2019 Algorithmic and Problem Solving
7/13
Introducing to programming, algorithmic and problem solving
6
FillCircle ( ColorYellow, 100, 100, 50);
FillRectangle (ColorRed, 300, 350, 50, 50);
FillRectangle (ColorRed, 390, 350, 60, 150);
FillEllipse ( ColorBlue, 500, 50, 100, 50);
FillEllipse ( ColorBlue, 200, 30, 100, 50);
FillEllipse ( ColorBlue, 400, 80, 100, 50);
FillEllipse ( ColorBlue, 600, 100, 100, 50);
FillEllipse ( ColorBlue, 300, 60, 100, 50);
FillRectangle (ColorGrey, 120, 400, 50, 100);
FillCircle ( ColorGreen, 142, 350, 70);
FillRectangle (ColorGrey, 680, 400, 50, 100);
FillCircle ( ColorGreen, 702, 350, 70);
RefreshScreen();
Delay(15000);
CloseAudio();
ReleaseAllResources();
end.
8/2/2019 Algorithmic and Problem Solving
8/13
Introducing to programming, algorithmic and problem solving
7
EXTENSION:
program snowdrawing
uses Swingame;
begin
OpenAudio();
OpenGraphicsWindow('snow', 800, 600);
LoadDefaultColors();
ClearScreen(ColorBlack);
FillTriangle(ColorRed, 485, 250,
485, 300 ,
600 , 275);
FillCircle(ColorWhite, 400, 450, 150);
FillCircle(ColorWhite, 400, 260, 95);
8/2/2019 Algorithmic and Problem Solving
9/13
Introducing to programming, algorithmic and problem solving
8
FillCircle(ColorWhite, 565, 400, 40);
FillCircle(ColorWhite, 265, 368, 42);
FillCircle(ColorBlack , 400, 570, 10);
FillCircle(ColorBlack , 400, 530, 10);
FillCircle(ColorBlack , 400, 490, 10);
FillCircle(ColorBlack , 400, 450, 10);
FillCircle(ColorBlack , 400, 410, 10);
FillTriangle(ColorRed, 280, 200,
400, 100,
510, 200);
FillCircle(ColorBlack, 450, 240, 10);
RefreshScreen();
Delay(8000);
CloseAudio();
ReleaseAllResources();
end.
.
8/2/2019 Algorithmic and Problem Solving
10/13
Introducing to programming, algorithmic and problem solving
9
4/. KNOCK KNOCK GAME
program Knock;
uses SwinGame;
procedure LoadResources();
begin
LoadBitmapNamed( 'door', 'KnockKnock.jpg');
LoadSoundEffectNamed('knock', 'door-knock-3.wav');
LoadFontNamed('joke font', 'arial.ttf', 40);
LoadSoundEffectNamed ('mad', 'scream.wav');
LoadBitmapNamed( 'mad', 'Higurashi___Scarlet_Blood_by_Kaza_SOU.jpg');
LoadBitmapNamed( 'fu', 'images.jpg');
LoadSoundEffectNamed ('holy', 'HolyShit.wav');
8/2/2019 Algorithmic and Problem Solving
11/13
Introducing to programming, algorithmic and problem solving
10
end;
procedure DrawDoor();
begin
DrawBitmap ( 'door', 0, 0 );
RefreshScreen();
Delay(3000);
end;
procedure ClearTextArea();
begin
FillRectangle ( ColorBlack, 0, 450, 800, 150 );
RefreshScreen ( );
Delay ( 500 );
end;
procedure ShowKnockKnock();
begin
ClearTextArea ( );
PlaySoundEffect ( 'knock' );
DrawText ( 'Knock knock...', ColorWhite,'joke font', 200, 500 );
RefreshScreen ( );
Delay ( 2000 );
end;
procedure ShowWhoThere();
begin
8/2/2019 Algorithmic and Problem Solving
12/13
Introducing to programming, algorithmic and problem solving
11
ClearTextArea ( );
DrawText ( 'Whos There...', ColorWhite,'joke font', 200, 500 );
RefreshScreen ( );
Delay ( 2000 );
end;
procedure DrawDoor2();
begin
DrawBitmap ( 'mad', 0, 0 );
RefreshScreen();
Delay(0000);
end;
procedure MadLaugh();
begin
ClearTextArea();
PlaySoundEffect ('mad');
DrawText ('Come to me babe...', ColorWhite, 'joke font', 200, 500);
RefreshScreen();
Delay (3000);
end;
procedure DrawDoor3();
begin
DrawBitmap ( 'fu', 300, 150 );
RefreshScreen();
Delay(0000);
8/2/2019 Algorithmic and Problem Solving
13/13
Introducing to programming, algorithmic and problem solving
12
end;
procedure FU();
begin
ClearTextArea();
PlaySoundEffect ('holy');
DrawText ('HOLY SH*T', ColorWhite, 'joke font', 200, 500);
RefreshScreen();
Delay (8000);
end;
begin
OpenAudio();
OpenGraphicsWindow('Knock', 800, 600);
LoadDefaultColors();
ClearScreen(ColorWhite);
LoadResources();
DrawDoor();
ShowKnockKnock();
ShowWhoThere();
DrawDoor2();
MadLaugh();
DrawDoor3();
FU();
CloseAudio();
ReleaseAllResources();
End.