0% found this document useful (0 votes)
13 views

Lecture 1 Understanding Computer System 1

PLF lesson 1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lecture 1 Understanding Computer System 1

PLF lesson 1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

PLF

(PROGRAM LOGIC FORMULATION)


1ST Semester 2023-2024
Understanding
Computer Systems
Computer System
⦿ A computer system is a combination of all the components required
to process and store data using a computer.
- Hardware is the equipment, or the physical devices,
associated with a computer.
For example ( keyboards, mice, speakers, and printers are all
hardware.)
- Software is computer instructions that tell the hardware what
to do. When you write software instructions, you are programming.

3
Software Types

⦿ Application software comprises all the programs you apply to a task,


such as word processing programs, spreadsheets, payroll and
inventory programs, and games.
⦿ System software comprises the programs that you use to manage
your computer, including operating systems.

4
Operations in Computer Program

⦿ Input—Data items enter the computer system and are placed in


memory, where they can be processed. Hardware devices that
perform input operations include keyboards and mice.

Data items include all the text, numbers, and other raw material that
are entered into and processed by a computer.

5
Operations in Computer Program

⦿ Processing—Processing data items may involve organizing or


sorting them, checking them for accuracy, or performing calculations
with them.
⦿ Output—After data items have been processed, the resulting
information usually is sent to a printer, monitor, or some other
output device so people can view, interpret, and use the results.

6
Other Important Terms
o Program code - The instructions you write using a programming
language
o Syntax - rules governing a programming word usage and
punctuation.
o Syntax errors - Mistakes in a language’s usage.
o Random access memory, or RAM - is a form of internal, volatile
memory.
Programs that are currently running and data items that are
currently being used are stored in RAM for quick access.

7
Other Important Terms
o Compiler or interpreter - translate your source code into machine
language
o Machine language is also called binary language, and is represented
as a series of 0s and 1s.

8
Two Truths and a Lie
In each Two Truths and a Lie section, two of the numbered statements are
true, and one is false. Identify the false statement and explain why it is false.

1. Hardware is the equipment, or the devices, associated with a


computer. Software is computer instructions.

2. The grammar rules of a computer programming language are its


syntax.

3. You write programs using machine language, and translation software


converts the statements to a programming language.

9
Understanding
Simple Program Logic
Simple Program Logic
o For a program to work properly, you must develop correct logic;

11
Simple Program Logic
o Computer program to double any number you provide represented in
English-like statements:
input myNumber
set myAnswer = myNumber * 2
output myAnswer

12
Simple Program Logic
o The number-doubling process includes three instructions:

o The instruction to input myNumber is an example of an input


operation. A variable is a named memory location whose value can
vary
o The instruction set myAnswer = myNumber * 2 is an example of a
processing operation.
o In the number-doubling program, the output myAnswer instruction
is an example of an output operation.
input myNumber
set myAnswer = myNumber * 2
output myAnswer

13
Two Truths and a Lie
In each Two Truths and a Lie section, two of the numbered statements
are true, and one is false. Identify the false statement and explain why it is false.

1. A program with syntax errors can execute but might produce incorrect
results.

2. Although the syntax of programming languages differs, the same


program logic can be expressed in different languages.

3. Most simple computer programs include steps that perform input,


processing, and output.

14
Understanding the
Program
Development Cycle
Program development cycle
1. Understand the problem.
2. Plan the logic.
3. Code the program.
4. Use software (a compiler or interpreter) to translate the program into
machine language.
5. Test the program.
6. Put the program into production.
7. Maintain the program.

16
Program development cycle

17
Understanding the Problem

⦿ Professional computer programmers write programs to satisfy the


needs of others, called users or end users.
⦿ Documentation consists of all the supporting paperwork for a
program; it might include items such as original requests for the
program from users, sample output, and descriptions of the data
items available for input.

18
Planning the Logic

⦿ The heart of the programming process lies in planning the program’s


logic. During this phase of the process, the programmer plans the
steps of the program, deciding what steps to include and how to
order them.
⦿ Algorithm is the sequence of steps or rules you follow to solve a
problem.
⦿ Desk-checking is the process of walking through a program’s logic
on paper before you actually write the program.

19
Coding the Program
⦿ After the logic is developed, only then can the programmer write the
source code for a program.
⦿ Coding refers to the part of programming that deals with writing
codes that a machine can understand.

20
QUESTION

Which step is harder?


Planning the logic or
coding the program?
21
Using Software to Translate the
Program into Machine Language
⦿ Languages like Java or Visual Basic are available for programmers

⦿ Someone has written a translator program (a compiler or interpreter)


that changes the programmer’s English-like high-level programming
language into the low-level machine language that the
computer understands.

22
Creating an Executable Program

23
Testing the Program

⦿A program that is free of syntax errors is not necessarily free of


logical errors.
⦿ A logical error results when you use a syntactically correct statement
but use the wrong one for the current context.

Example: Example:

input myNumber input myNumber


set myAnswer = myNumber * 2 set myAnswer = myNumber * 20
output myAnswer output myAnswer

24
Testing the Program

⦿ Debugging - The process of finding and correcting program errors

Example:

input myNumber
set myAnswer = myNumber + 2
output myAnswer

25
Putting the Program into Production

⦿ Putting the program into production might mean simply running the
program once, if it was written to satisfy a user’s request for a
special list.
⦿ Conversion, the entire set of actions an organization must take to
switch over to using a new program or set of programs.

26
Maintaining the Program

⦿ Maintenance - after programs are put into production, making


necessary changes is referred to as maintenance.

27
Declaring and Using
Variables and
Constants
Data Types
⦿ Numeric - one that can hold digits and have mathematical operations
performed on it.
⦿ String - can hold text, such as letters of the alphabet, and other special
characters, such as punctuation marks.

Languages such as C++, C#, Visual Basic, and Java distinguish between
integer (whole number) numeric variables and floating-point (fractional)
numeric variables that contain a decimal point.

Type-safety - feature of some programming languages that prevents


assigning values of an incorrect data type.
29
Data Types

⦿ Numeric Constant - A specific numeric value.


⦿ String Constant - A specific text value, or string of characters, such
as “Amanda”.
String values are also called alphanumeric values.

30
Working with Variables

⦿ Variables are named memory locations whose contents can vary or


differ over time.
Example:

input myNumber
set myAnswer = myNumber * 2
output myAnswer

31
Working with Variables

⦿A declaration is a statement that provides a data type and an


identifier for a variable.
⦿ An identifier is a program component’s name.
⦿ A data item’s data type is a classification that describes the
following:
- What values can be held by the item
- How the item is stored in computer memory
- What operations can be performed on the item

32
Working with Variables

⦿ Initializing the variable - Declaring a starting value to a variable


Example:

num mySalary
num yourSalary = 14.55
string myName
string yourName = "Juanita"

⦿ A variable’s unknown value commonly is called garbage.


33
Naming Variables

⦿ As a programmer, you choose reasonable and descriptive names for


your variables.
⦿ The language translator (interpreter or compiler) then associates the
names you choose with specific memory addresses.
⦿ Keywords are not allowed as variable names because they are part
of the language’s syntax.
Example : num and string

34
Variable Naming Conventions

35
Rules in Naming Variables

1. Variable names must be one word.


2. Variable names must start with a letter.
3. Variable names should have some appropriate
meaning.

36
Assigning Values to Variables
⦿ Assignment statement - this statement incorporates two actions
that uses = symbol as an assignment operator.

Example: set myAnswer = myNumber * 2

The assignment operator is an example of a binary operator, meaning it


requires two operands—one on each side. (An operand is simply a value
used by an operator.)

The assignment operator always operates from right to left,


which means that it has right-associativity or right-to-left associativity. 37
Assigning Values to Variables
⦿ Valid Assignment Statements

Example:

set someNumber = 2
set someNumber = 3 + 7
set someOtherNumber = someNumber
set someOtherNumber = someNumber * 5

38
Assigning Values to Variables
⦿ lvalue - The result to the left of an assignment operator. The l is for
left.
Example: Not valid

set 2 + 4 = someNumber
set someOtherNumber * 10 = someNumber
set someNumber + someOtherNumber = 10

39
Assigning Values to Variables
⦿ Assignment Statements in Simpler Form

Example :

someNumber = 2
someOtherNumber = someNumber

40
Assigning Values to Variables
⦿ Assignment Statements

Example : valid Example : Invalid

taxRate = 2.5 taxRate = "2.5"


inventoryItem = "monitor" inventoryItem = 2.5
taxRate = inventoryItem
inventoryItem = taxRate

41
Declaring Named Constants
⦿ Named constant - similar to a variable, except it can be assigned a
value only once.
Example :

num SALES_TAX_RATE = 0.06

Example :

taxAmount = price * 0.06


taxAmount = price * SALES_TAX_RATE

42
Two Truths and a Lie
In each Two Truths and a Lie section, two of the numbered statements
are true, and one is false. Identify the false statement and explain why it is false.

1. A variable’s data type describes the kind of values the variable


can hold and the types of operations that can be performed with it.

2. If name is a string variable, then the statement set name = "Ed" is


valid.

3. The operand to the right of an assignment operator must be a


name that represents a memory address.

43

You might also like