You are on page 1of 43

Algorithm And Programming

IF UBAYA
(Infor+SI+MM+ITDD)

Learning Method
14 Weeks of lessons
6 Hours per week (2 x 3 Hours per meeting)

In every meeting we will


See the programming concept to be learnt
See the example of how the concept can be used
Hands on experience by writing your own
program

Programming Language: C# (read: C Sharp)


2

iTALC
There is a software that we use to see all the
students monitor, named: iTALC
Because we can see all of your activities in
your computer, please use all of your time in
the Labs to do something that is related to
ALPRO only.

Ubaya Learning Space (uls)


All slides can be downloaded from:
uls.ubaya.ac.id
You need your Ubaya account to login
This account and password is the same as
your Ubaya email account and password
Make sure that you can login to the ULS
because you need to upload your work there
for some assignments and tests.
4

Software
Software: Visual Studio(VS) 2013 or 2015
All labs use VS 2013
You can download the software for FREE and
LEGAL from: dreamspark.ubaya.ac.id

Marking
Final Mark (NMA) = 40% Mid Term Mark (NTS) +
60% Final Term Mark (NAS)
Mid Term Mark = 5% selfie + 10% class engagement +
10% Practice work1 + 15% Practice work2 +
20% Quiz + 40% Mid Term Exam
Final Term Mark = 10% class engagement +
15% Practice work1 + 15% Practice work2 +
20% Quiz + 40% Mid Term Exam
Note: NMA=Nilai Mentah Akhir, NTS=Nilai Tengah Semester,
NAS=Nilai Akhir Semester
6

FINAL MARK to GRADE


FINAL MARK
(NMA)
NMA >= 81

GRADE

Grade Point

73 <= NMA < 81

AB

3.5

66 <= NMA < 73

60 <= NMA < 66

BC

2.5

55 <= NMA < 60

40 <= NMA < 55

NMA < 40

0
7

Assignment 1: Installing VS (Selfie)


Install the VS 2013 or VS 2015 to your
laptop/computer
Take a selfie photo, showing you and your
laptop/computer that is running VS.
Send the photo to your teacher.
The photo must be sent from: sNRP@student.ubaya.ac.id
The subject of the email must be: ALPRO Tugas1
yourShortName (eg. ALPRO Tugas1 Budi)
The filename must be: MeAndVS yourShortName
(eg. MeAndVS Budi)
Due date: 1 week after you get this information.

And you will get 5 point in ALPRO for free (yeee..)


8

Learning Programming
Programming is not just a knowledge,
but a SKILL that can only be mastered
by practicing it regularly

Comment about SKILL


Other example of Skill in our everyday life: Driving a
car/plane/, playing football/ badminton/
,swimming, etc.
For example, what should you do to pass a driving
test for a driving license?
Can you just read a book about how to drive, memorize it,
and expect to pass the driving test?
Can you practice driving for one or two days before the test
and expect to become a good driver?
What do you think you should do ?
Do the same thing for learning programming.
10

What is a program?
A program is
a collection of statements / commands,
that is arranged in a certain order,
and be written in a certain programming
language and rule,
to perform a certain process.

11

Executing a program
How can computer understand the
commands from human?
We need a software that can translate the
command from human language to
machine language
In this case:
The software that we will use is: Visual Studio
The human language that we will use is: C#
12

The language: C#
Although it looks like English, some rules
in C# language IS DIFFERENT FROM the
rules in English
For example, the full stop in English is .
but the full stop in C# is ;
In English, you can write conditions
without bracket but in C# all conditions
must be put inside bracket
and so on
13

The language: C#
Therefore:
You should follow STRICTLY to the rules
and the grammar of C# language.
Unlike human, computer WILL NOT
understand your statements/commands if
you make a typing mistake in your code.

14

Visual Studio (VS)


VS is used to convert the program from
human language machine language
(application)
The process is called: build
The application, that is in exe file format can
be run without using VS anymore (it is in
Debug/Release folder well show you later
where can you find this file)
15

Visual Studio (VS)


VS can also check the syntax of your
commands. If you see a red underline on
your code then it means that you have an
error in your code. This error is called syntax
error.
You have to fix all of the errors before you
can continue to run (execute) the program.

16

Writing the Program using C#


C# uses a programming concept that is
called Object Oriented Programming
(OOP).
In this concept, almost all items used are
objects, and the program works because
of the interaction between objects.
This imitates the process in our real world
(things that happen in our life come from
the interaction of objects).
17

Object Oriented Programming


There are two basic terms in OOP that are
called:
Object
Class

Object: is an instance of a class.


Class: is a template used to create an
object. You can see the example of the
class when we start writing the program.
18

Object Oriented Programming


Example of objects (all things that you see
in this example are objects)
object of Label
object of Form

object of Textbox
object of Buttons

19

Property
You can change the characteristics of the
object through its Property.
For example, there are several properties
for a button that you can use to change
the button background color, its text, size,
font, etc.
You can change the value of a property
using two ways:
Change directly in the VS Design View
Change by writing the code
20

Example of the Button property


in the VS Design View

Name of the object


that its properties
displayed

Selected button

Make sure the


Properties option is
selected (not the
Events option), and
Sort by name
21

Method
Method is used to do some actions that
usually cannot be performed directly
through Properties.
Method can only be typed in a program

22

Property and Method Symbol


Property Symbol:
Method Symbol:

23

Example
Create the following application:
The user can enter his/her name in a Text Box
When the user click the button OK, the name in the
Text Box is displayed to a Label below it.
Button Clear to clear all text
Button Exit to close the form

24

STEP 1
CREATE THE USER INTERFACE

25

Creating the project

26

Add Controls to the Form


You can get a control from the window Toolbox and
put it on the form, by click and drag.

Click and Drag

27

TextBox

Naming of an Object
VS will automatically create an object of that control
and give a default name.
You can see this default name through the property
(Name)

Initial name
of the object

Change the
name to
buttonOK
28

Naming Convention of an Object


The object name should represent its purpose.
Start the object name with the type of the control (for
example: button, label, textbox, etc)
Start the name with lower case, then give capital for
every next word.
Some examples of some valid object names:

buttonExit
buttonStart
textBoxUserName
labelMessageFromServer
29

Experiment with the control Properties


You can change the text on the control from Text
property.
Try to change all the text in the controls to meet the
example given.
You can play with other properties, such as the Font,
BackColor, ForeColor, etc.
Dont forget to also change the text of the Form
(click on the form to select it)

30

STEP 2
ADD THE FUNCTIONALITY
(WRITE THE PROGRAM TO MAKE
THE FORM ALIVE)

31

Event Based Programming


In event based programming, some codes are
executed as an action when a certain event occurs.
Event Occurs Performs Actions
Example in our everyday life:
When we see a lightning (this is event), we close our
ears with our hands (this is action)
Example in programming:
When the button OK is clicked (clicked is an
event), there are some codes executed to do
something (these codes are performing action)
s32

What events available for a control?

Turn on the Lightning


Icon to show events
The other icon is used
to show the properties

33

Write the program as an action of an event


The program must be written in a place named:
method or event handler
Creating an event handler of an event
Method 1: Double click on the event name (in the event
window)
Method 2: Every control has a default event. If you want to
use the default event, just double click on the control (no
need to open the event window)

The name of the event handler will contain the name


of the object. Make sure you change the object
name first before creating the event handler.
s34

Event Handler

Write your code here

s35

Delete the event Handler


Delete the name of the
Event handler in here FIRST

Then delete this event handler


if it still exist (this will be deleted
automatically if it is still empty)

s36

What program to be written?


textBoxName

labelInfo

LOGIC: When the button OK is clicked,


Get the text from the textbox (from property Text)
and Set it to the text of the label
ALL the process of GETTING value from a
property must be put on the RIGHT side of =
sign. The opposite applies for setting the property.
37

Accessing the Property


Type the object name, dot, then property name
Selecting the object name or property name
from the list displayed by VS is MUCH Better
than typing all the text yourself.
All statements must be ended with semicolon
(;). This is similar as dot (.) to end a
sentence in English/Indonesian.

38

Combining Text
Use + sign.
Text must be put inside the quote (eg.your text)

The meaning of the program can be read from right to the left:
Get the value from the Text property of object textBoxName
And combine it using + sign with a text Your name is:
Then store the result of the combination in the property Text
Of object labelName.
39

Clear and Exit


Create the event handler for event Click for each
button then do the following for each event
handler:
Clear: change the value in the Text property
with empty string ()
Exit: write the following command:
this.Close();

40

Exercise
Project Name: yourShortName Favorite Animal

41

Exercise
If the user enter the following data:

Fav Animal: Elephant


Fav Color: Pink
Fav Body part: Eye
Fav Number: 10

Then the text in the summary 1 and 2 will be:


Summary 1: Pink Elephant
Summary 2: With 10 Eye

42

Always SHUT DOWN the


computer before you leave
the Lab.

43

You might also like