0% found this document useful (0 votes)
6 views19 pages

COM1003 2023-24 Sem 2 Lecture 7

The document discusses fundamental programming concepts, including commands, control structures, and loops, emphasizing their importance in programming. It provides examples using assembly language and modern programming languages, illustrating how to write simple programs and the significance of decision-making and repetition in coding. Additionally, it mentions programming modules available for students interested in learning programming skills at a higher level.

Uploaded by

li
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views19 pages

COM1003 2023-24 Sem 2 Lecture 7

The document discusses fundamental programming concepts, including commands, control structures, and loops, emphasizing their importance in programming. It provides examples using assembly language and modern programming languages, illustrating how to write simple programs and the significance of decision-making and repetition in coding. Additionally, it mentions programming modules available for students interested in learning programming skills at a higher level.

Uploaded by

li
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

COM1003

What Makes A Computer


A Computer
(2023/24 Sem 2)
Lecture 7: Programming Concepts

1
Objectives
 Programming (at conceptual level)
 Command or instruction
 Important concepts in programming
• Control structure (for decision making)
• Loop (for task repetition)

2
What Is A Program?
 Seelecture notes “History of Programming
Languages” slide #2
 A program is a set of instructions

 Programming
 Put down the instructions in some particular orders

3
Recall Our Simple Calculator
Example (In Assembly Language)
 What is the function of the following
programs? Code Assembly language Meaning
00XXXX Start XXXX Start of program, Set the
Start 0001 Start 0010 data to be XXXX
Add 0001 Add 0010 01XXXX Add XXXX Add XXXX to the data
End Subtract 0001
End 10XXXX Subtract XXXX Subtract YYYY from the
data
11XXXX End End of program

 Write a program for the following functions


 Find 3 – 2 + 4

4
Congratulations!!!!

 Youhave successfully written your first


program in assembly language!

5
In Modern Programming
Languages
 More instructions and syntax

 Example:
 The following 4 statements have the same function
 “c++”, “++c”, “c += 1”, “c = c + 1”
 This module does not teach you programming …
we just discuss about it at high level
6
If You Are Interested In
Programming …
 Programming modules offered by
Department of Computer Science in HSU
 COM2005 Introduction to Computer Programming
• For non-computing majors to learn general programming
 COM1101 Programming Methodology
• Specialized for applied computing students to learn general
programming
 COM1005 Excel VBA Programming
• For non-computing majors to learn programming in Excel VBA

7
Programming Concept 1:
Control Structure
 Sometimes, the program needs to execute
different instructions under different
situations
 Example:
Login
 Facebook login OK?
 Example Java program Yes No
if ( loginOK() ) {
Display the Display an
displayHome(); home page error message
} else {
displayError();
} Reminder: you are not supposed to learn Java
programming here. However, can you read it
8
and understand the task behind the codes?
Control Structure:
More Examples
member
Nil
Class?
Original Gold
Bronze
price Silver

10% off 15% off 20% off

 Example Java program


switch (memberClass) {
case Nil : charge = price; break;
case Bronze: charge = price * 0.9; break;
case Silver: charge = price * 0.85; break;
case Gold: charge = price * 0.8; break;
}
Reminder: you are not supposed to learn Java
programming here. However, can you read it
and understand the task behind the codes? 9
Using Control Structure
 Can you give me some example
applications?
 Your module grade is based on your total score
 In a game, e.g., RPG game, if conditions are not met,
you cannot trigger the event(s)
 And more …

10
Using Control Structure:
An Example Of Score And Grade

11
Programming Concept 2: Loop
 Inmany situations, our program repeats the
same process again and again
 Example:
 Bank: give 1% interest to every account
• What action is repeated?
New account balance = old account balance * 1.01
 Example Java program
for (account : accountList) {
account.balance = account.balance *1.01;
}
Reminder: you are not supposed to learn Java
programming here. However, can you read it
and understand the task behind the codes?
12
Loop Example
 Data entry
 Keep asking the user to enter the age information until
the entered number is an integer greater than 0 or equal
to 0
 Example Java program Ask the user to
enter a number
do {
number = readInputFromUser(); Loop
Yes
} while (number < 0);
Number < 0?
Reminder: you are not supposed to learn Java
programming here. However, can you read it
and understand the task behind the codes? No

Next step 13
Using Loop
 Can you give me some example
applications?
 Chess, which move should the AI make? Loop and try
every move and pick the best one
 Find the total amount of a transaction. Loop every item
and add the price of the item to the sum
 And more …

14
Combining Different Techniques
Together
 Control
structure in loop (Repetition +
Decision Making)
 Example: give 2% interest to VIP account, 1% otherwise
 Example Java program
for (account : accountList) {
if ( account.isVIP() ) {
account.balance = account.balance * 1.02;
}
else {
account.balance = account.balance * 1.01;
}
} Reminder: you are not supposed to learn Java
programming here. However, can you read it
and understand the task behind the codes? 15
Combining Different Techniques
Together
 Loop in loop (Nested Loop)
 Example: find the total number of people in the school
 Example Java program Male Female
sum = 0; Student 300 200
Teacher 25 10
for (row : allRows)
{
for (col : row.allColumns)
{
sum = sum + col.value;
}
} Reminder: you are not supposed to learn Java
programming here. However, can you read it
and understand the task behind the codes? 16
Drag-n-drop Visual Programming
 Minimal typing or coding
 Learning drag-n-drop programming online
 An hour of code: learn programming by
gaming
 An hour of code (Minecraft)
• https://code.org/minecraft

17
Development Using Drag-n-drop
Programming
 App Inventor 2
 Allows you to develop mobile Apps for Android

18
Additional Materials
 Drag-n-drop programming @ UC Berkeley
 https://www.youtube.com/watch?v=_Mwc1gc77dc

19

You might also like