You are on page 1of 23

ICT1101

Program Logic Formulation


Topic 1 : Introduction to Programming
Concepts

Vimala.doraisamy@s.newinti.edu.my
2020
Learning Outcomes 2

 Define the term computer program & programming language.


 Identify and explain the categories of programming languages used to write
computer programs.
 Difference between interpreter and compiler
 Implement good programming practices in coding and programs maintenance.
How do computers think? 3
Nature of a Computer Program 4

 Characteristics of computers:
 Assist human tasks
????
 High speed
 Large storage
 Precise and accurate
 Computers are sophisticated devices that cannot
think on its own (for now).
 Algorithms are being developed for machine learning
and artificial intelligence.
 These algorithms also need to be designed by humans.
Nature of a Computer Program 5

 Computers need computer programs to tell them what to do.


 A computer program is a list of instructions, that when executed, causes the
computer to behave in a predetermined manner.
 Computer programs are written using programming languages.

Do my homework. ???
Categories of Programming Languages 6

 Programming Language
 A set of instructions consisting of rules, syntax, numerical and logical operators and
utility functions.
 3 major groups of programming languages
 Machine language
 Assembly language
 High level language #include <iostream>
using namespace std;

int main()
{
cout << “Hello World!” << endl;
}
What is machine language? 7

 Machine language is the native tongue of computers.


 Data and operations are represented in binary (strings of 0s and 1s).
 Example:
 x=x+1

 Difficult to be understood by humans.


 This is the only language understood by computers.
What is assembly language? 8

 Assembly language is the oldest non-machine language.


 Uses English-like abbreviations to represent operations performed on data.
 Example:

 An assembly language must be translated into machine language in order for the
computer to understand it.
 A special program called an assembler is used for translation.
What is high-level language? 9

  Consists of instructions that resemble everyday language.


 Uses English-like statements and common mathematical notation:
 Example:
 High-level language must be translated into machine language before execution.
Question 10

 Give me a few examples of high-level languages.

**YOU MAY SHOUT YOUR ANSWER


11
12
What is high-level language? 13

 High-level language must be translated into machine language before execution.


 Types of translator programs:
 Interpreter
 High-level languages that use interpreters for translation are known as interpreted
languages.
 E.g. VBScript, Javascript
 Compiler
 High-level languages that use compilers for
translation are known as compiled languages.
 E.g. Visual Basic, C, C++
Interpreter 14

 Translates each statement into machine language and executes it immediately


before the next statement is examined.

 An interpreted program must be translated each time it is run.


Compiler 15

 Translates all statements before a program can be executed.

 A compiled program is only translated once.


 Can be executed repeatedly without any translations.
Questions

 Which one do you think will run quicker, an interpreted or compiled program ?

 Which type of programming language is the following code written


(a) grossPay = hours * rate;
System.out.println (“Gross Pay = “ + grossPay);
(b) 0010 0000 1010 0011
0011 1111 0000 1111
(c) MOV BX, [041F]
ADD BX, 0100

**YOU MAY SHOUT YOUR ANSWER


OR FRANTICALLY WAVE YOUR HANDS
SO I CAN CALL YOU OUT TO ANSWER
Good Programming Practices 17

 Importance:
 Maintain understandable and readable computer code
 Describe and reveal the logical structure of instructions
 Formatting guide:
 Indentations
 Include comments
 Standardized naming conventions
Indentations 18

 Add indentations to your code to make it easy to read.


 Rule of thumb: Indent after each opening curly bracket “{“
#include <iostream>
#include <iostream>
using namespace std;
using namespace std;
int main()
int main()
{
{
cout << “Hello World!” << endl;
cout << “Hello World!” << endl;
cout << “This is a simple C++ program.” <<
cout << “This is a simple C++ program.” << endl;
endl;
int y;
int y;
for (int x=0; x<10; x++)
for (int x=0; x<10; x++)
{
{
y+=x;
y+=x;
if (y>5)
if (y>5)
{
{
cout << y << “ is larger than 5” << endl;
cout << y << “ is larger than 5” << endl;
}
}
}
}
}
}
Comments 19

 Add comments to indicate what the code does.


#include <iostream>
using namespace std;

int main()
{
//Print out a welcome message.
cout << “Hello World!” << endl;
cout << “This is a simple C++ program.” << endl;
int y;

//Perform simple calculations on x and y


for (int x=0; x<10; x++)
{
y+=x;
if (y>5)
{
cout << y << “ is larger than 5” << endl;
}
}
}
Naming Conventions 20

 Ensure that variable names are easy to read and easy to distinguish.

#include <iostream> #include <iostream>


using namespace std; using namespace std;

int main() int main()


{ {
int numberofstudents; int numberOfStudents;
float studentmarks; float student_marks;
int numberofsubjects; int NumberOfSubjects;
} }
Review Learning Outcomes 21

 Define the term computer program & programming language.


 Identify and explain the categories of programming languages used to write
computer programs.
 Difference between interpreter and compiler
 Implement good programming practices in coding and programs maintenance.
Questions? 22
End of Topic 1 23

You might also like