Вы находитесь на странице: 1из 14

LESSON 1: INTRODUCTION TO COMPUTERS AND PROGRAMMING

INTRODUCTION
 Program – set of instructions that a computer follow to perform a task; commonly referred to as
software
 Software – essential to a computer because without software, a computer can do nothing
 Programmer or Software Developer – person with training and skills necessary to design, create,
and test computer programs

HARDWARE
The term “hardware” refers to all of the physical devices, or components, that a computer is made of. A
computer is not one single device, but a system of devices that all work together. A typical computer
system consists of the following components:
 CPU (central processing unit)
 Main memory
 Secondary storage devices
 Input devices
 Output devices

CPU (CENTRAL PROCESSING UNIT)


 The central processing unit (CPU) is the part of the computer that actually runs programs.
 The CPU is the most important component in a computer.
 In the earliest computers, CPUs were huge devices made of electrical and mechanical components
such as vacuum tubes and switches.

 Today, CPUs are small chips known as microprocessors.

MAIN MEMORY
 Main memory is where the computer stores a program while the program is running.
 Main memory is commonly known as random-access memory or RAM.
 RAM is usually volatile type of memory that is used only for temporary storage while a program is
running.
 When the computer is turned off, the contents of RAM are erased.

SECONDARY STORAGE DEVICES


 Secondary storage is a type of memory that can hold data for long periods of time, even when there
is no power to the computer.
 Programs are normally stored in secondary memory and loaded into main memory as needed.
 The most common type of secondary storage device is the disk drive.
 A disk drive stores data by magnetically encoding it onto a circular disk.
 External disk drives can be used to create backup copies of important data or to move data to
another computer.
 A floppy disk drive records data onto a small floppy disk, which can be removed from the drive.
 Floppy disks hold only a small amount of data, are slow to access data, and are sometimes
unreliable.
 USB drives are small devices that plug into the computer’s USB (universal serial bus) port, and
appear to the system as a disk drive.
 They store data in a special type of memory known as flash memory.
 USB drives, which are also known as memory sticks and flash drives, are inexpensive, reliable, and
small enough to be carried in your pocket.
 Optical devices such as the CD (compact disc) and the DVD (digital versatile disc) are also popular
for data storage.
 CD and DVD drives use a laser to detect the pits on disc surface and thus read the encoded data.
 Optical discs hold large amounts of data, and because recordable CD and DVD drives are now
commonplace, they are good mediums for creating backup copies of data.

INPUT DEVICES
 Input is any data the computer collects from people and from other devices.
 The component that collects the data and sends it to the computer is called an input device.
 Common input devices are the keyboard, mouse, scanner, microphone, and digital camera.

OUTPUT DEVICES
 Output is any data the computer produces for people or for other devices.
 The data is sent to an output device, which formats and presents it.
 Common output devices are video displays and printers.

HOW THE COMPUTER STORE DATA


 All data that is stored in a computer is converted to sequences of 0s and 1s.
 A computer’s memory is divided into tiny storage locations known as bytes.
 Each byte is divided into eight smaller storage locations known as bits.
 The term bit stands for binary digit.

STORING NUMBERS
 A bit that is turned off represents the number 0 and a bit that is turned on represents the number 1.
 The position of each digit in a binary number has a value assigned to it.

STORING CHARACTERS
 Any piece of data that is stored in a computer’s memory must be stored as a binary number That
includes characters, such as letters and punctuation marks.
 When a character is stored in memory, it is first converted to a numeric code then numeric code is
then stored in memory as a binary number.
 The most important of these coding schemes is ASCII, which stands for the American Standard
Code for Information Interchange.
 ASCII is a set of 128 numeric codes that represent the English letters, various punctuation marks,
and other characters.
 Unicode is an extensive encoding scheme that is compatible with ASCII, and can also represent the
characters of many of the world’s languages.

ASCII CODE TABLE

HOW A PROGRAM WORKS


 A computer’s CPU can only understand instructions that are written in machine language. But
people find it very difficult to write entire programs in machine language, programming languages
have been invented.
 CPU is the most important component in a computer because it is the part of the computer that runs
programs. (CPU is called “computer’s brain” and described as being smart)
 CPU performs simple operations on pieces of data.
 A program is nothing more than a list of instructions that cause the CPU to perform operations.
 The entire set of instructions that a CPU can execute is known as the CPU’s instruction set.

FROM MACHINE TO ASSEMBLY LANGUAGE


 Although a computer’s CPU only understands machine language, it is impractical for people to write
programs in machine language.
 Assembly language was created in the early days of computing as an alternative to machine
language.
 Assembly language uses short words that are known as mnemonics.
 A special program known as an assembler is used to translate an assembly language program to a
machine language program.
LOW-LEVEL AND HIGH-LEVEL LANGUAGE
 Assembly language is so close in nature to machine language; it is referred to as a low-level
language.
 A high-level language allows you to create powerful and complex programs without knowing how
the CPU works, and without writing large numbers of low-level instructions.
 The words that make up a high-level programming language are known as key words or reserved
words.
 Each key word has a specific meaning, and cannot be used for any other purpose.

COMPILER VS. INTERPRETER VS. ASSEMBLER

SOFTWARE
Programs generally fall into one of two categories:
 System software control or enhance the operation of a computer.
 Application software makes a computer useful for everyday tasks

SYSTEM SOFTWARE
System software typically includes the following types of programs:
 Operating System controls internal operations of the computer’s hardware, manages all devices
connected to the computer, allows data to be saved to and retrieved from storage devices, and
allows other program to run on the computer. (i.e. Windows, IOS, Mac OS, Linux)
 Utiliy Programs performs a specialized task that enhances the computer’s operation or safeguards
data. (i.e. virus scanners, file compression programs and data back-up)
 Software Development Tools are the programs that programmers use to create, modify, and test
software. (i.e. assemblers, compilers, and intepreters)
LABORATORY EXERCISE NO. 1: INTRODUCTION TO COMPUTER AND PROGRAMMING

Multiple Choice.
1. A(n) __________ is a set of instructions that a computer follows to perform a task.
a. Compiler
b. Program
c. Interpreter
d. programming language
2. The physical devices that a computer is made of are referred to as __________.
a. hardware
b. software
c. the operating system
d. tools
3. The part of a computer that runs programs is called __________.
a. RAM
b. secondary storage
c. main memory
d. the CPU
4. Today, CPUs are small chips known as __________.
a. ENIACs
b. Microprocessors
c. memory chips
d. operating systems
5. The computer stores a program while the program is running, as well as the data that the program is
working with, in _________.
a. secondary storage
b. the CPU
c. main memory
d. the microprocessor
6. This is a volatile type of memory that is used only for temporary storage while a program is running.
a. RAM
b. secondary storage
c. the disk drive
d. the USB drive
7. A type of memory that can hold data for long periods of time—even when there is no power to the
computer––is called _______
a. RAM
b. main memory
c. secondary storage
d. CPU storage
8. A component that collects data from people or other devices and sends it to the computer is called
a. an output device
b. an input device
c. a secondary storage device
d. main memory
9. A video display is a(n) __________.
a. output device
b. input device
c. secondary storage device
d. main memory
10. A __________ is enough memory to store a letter of the alphabet or a small number.
a. Byte
b. Bit
c. Switch
d. Transistor
11. A byte is made up of eight __________.
a. CPUs
b. Instructions
c. Variables
d. Bits
12. In a(n) __________ numbering system, all numeric values are written as sequences of 0s and 1s.
a. Hexadecimal
b. Binary
c. Octal
d. Decimal
13. A bit that is turned off represents the following value:
a. 1
b. -1
c. 0
d. “no”
14. A set of 128 numeric codes that represent the English letters, various punctuation marks, and other
characters is
a. binary numbering
b. ASCII
c. Unicode
d. ENIAC
15. An extensive encoding scheme that can represent the characters of many of the languages in the
world is _________
a. binary numbering
b. ASCII
c. Unicode
d. ENIAC
16. Negative numbers are encoded using the __________ technique.
a. two’s complement
b. floating-point
c. ASCII
d. Unicode
17. Real numbers are encoded using the _________technique.
a. two’s complement
b. floating-point
c. ASCII
d. Unicode
18. The tiny dots of color that digital images are composed of are called __________.
a. Bits
b. Bytes
c. color packets
d. pixels
19. If you were to look at a machine language program, you would see __________.
a. Java code
b. a stream of binary numbers
c. English words
d. Circuits
20. In the __________ part of the fetch-decode-execute cycle, the CPU determines which operation it
should perform.
a. Fetch
b. Decode
c. Execute
d. immediately after the instruction is executed
21. Computers can only execute programs that are written in
a. Java
b. assembly language
c. machine language
d. C++
22. The __________ translates an assembly language program to a machine language program.
a. Assembler
b. Compiler
c. Translator
d. Interpreter
23. The words that make up a high-level programming language are called __________.
a. binary instructions
b. mnemonics
c. commands
d. key words
24. The rules that must be followed when writing a program are called __________.
a. Syntax
b. Punctuation
c. key words
d. operators
25. A(n) __________ program translates a high-level language program into a separate machine
language program.
a. Assembler
b. Compiler
c. Translator
d. Utility

Practice.
1. Convert the following decimal numbers to binary:
11
61
104
257
2. Convert the following binary numbers to decimal:
1101
1010
1001101
3. Determine the decimal and binary codes for each letter of your nickname (at most 5 letters).
LESSON 2: PROGRAM METHODOLOGIES

PROGRAM DEVELOPMENT CYCLE


1. Understand the problem
2. Plan the Logic
3. Code the program
4. Use software to translate the program into machine language
5. Test the program
6. Put the program into production
7. Maintain the program

ALGORITHM
 Derived from mathematician Al-Khowarizmi which means procedure or technique
 Sequence of steps to solve a particular problem
 Characteristics of algorithm:
o Input: may or may not require input
o Output: expected to produce at least one result
o Definiteness: must be clear and unambiguous
o Finiteness: certain number of steps

CONTROL STRUCTURE OF ALGORITHM


a. Sequence – statements are placed one after the other
b. Selection – statements are conditional or decisions either TRUE or FALSE
c. Repetition – executed repeatedly based on certain loop condition

ADVANTAGES OF ALGORITHM
 It is a step-wise representation of a solution to a given problem, which makes it easy to understand.
 An algorithm uses a definite procedure.
 It is not dependent on any programming language, so it is easy to understand for anyone even
without programming knowledge.
 Every step in an algorithm has its own logical sequence so it is easy to debug.

HOW TO WRITE ALGORITHM


 Define your algorithms input
 Define the variables
 Outline the algorithm's operations
 Output the results of your algorithm's operations

PSEUDOCODE
 Structured English that describes algorithm
 Meant for human reading rather than machine reading
 No standards define in writing a pseudocode
 Models and resemble real programming code

FLOWCHART
 Designed by John Von Neumann
 Uses symbols to design a solution
 Commonly used for programming tools

ADVANTAGES OF FLOWCHART
 Excellent way of communicating logic of program
 Easy and efficient to analyze
 Develop process easier
 Easy to convert to programming language code

FLOWCHART SYMBOL

GENERAL RULES
 All boxes are connected with arrow and not lines
 Entry point on the top and endpoint on the bottom

SAMPLE ALGORITHM AND FLOWCHARTS (DISCUSSED ON BOARD)


1. Design an algorithm and flowchart for adding test scores given below: 26, 49, 68, 87, 62
2. Design an algorithm and flowchart to find greater number between two numbers.
3. Design an algorithm and flowchart to find the area and perimeter of a triangle
4. Design an algorithm and flowchart to find all divisor of a certain number
LABORATORY EXERCISE NO. 2: PROGRAM METHODOLOGIES

Practice.
1. Design an algorithm and flowchart to convert temperature from Celsius to Fahrenheit.
Algorithm Flowchart

2. Design an algorithm and flowchart to find the area and perimeter of a circle.
Algorithm Flowchart

3. Design an algorithm and flowchart to find simple interest.


Algorithm Flowchart

4. Design an algorithm and flowchart to find the smallest of two numbers.


Algorithm Flowchart

5. Design an algorithm and flowchart to find the largest of three numbers.


Algorithm Flowchart
LESSON 3: TOOLS FOR DEVELOPING PROGRAMMING LOGIC

MATHEMATICAL OPERATORS

RELATIONAL OPERATORS

LOGICAL OPERATORS

SELECTION CONTROL STATEMENTS


REPETITION CONTROL STATEMENTS

SAMPLE ALGORITHM AND FLOWCHARTS OF CONTROL STRUCUTRES (DISCUSSED ON BOARD)


Sequence Control Structure
1. Design an algorithm and flowchart to swap two string characters using temporary variable.
2. Design an algorithm and flowchart to find compound interest
3. Design an algorithm and flowchart to convert temperature from Fahrenheit to Celsius

Selection Control Structure


1. Design an algorithm and flow chart to find the largest among three input numbers
2. Design an algorithm and flowchart to find the smallest of two numbers

Repetition Control Structure


1. Design an algorithm and flowchart for a program repeatedly ask for entry of a number in the range 1
to 100 and stop until an invalid number is entered.
2. Design an algorithm and flowchart for a program repeatedly ask for five input score and find the sum
and average.
3. Design an algorithm and flowchart for a program asking count and repeatedly print the input string
data depends on the number of count
LABORATORY EXERCISE NO. 3: SEQUENCE AND SELECTION CONTROL STRUCTURES

Practice.
1. Design an algorithm and flowchart to read height in centimeters and convert to feet and inches.
Algorithm Flowchart

2. Design an algorithm and flowchart to swap two numbers using temporary variable.
Algorithm Flowchart

3. Design an algorithm and flowchart to swap two numbers without using temporary variable
Algorithm Flowchart

4. Design an algorithm and flowchart to check whether the input year is a leap year or not
Algorithm Flowchart

5. Design an algorithm and flowchart to evaluate the input grade or scores if its grade A, B, C, D, or E.
A: 95 – 100
B: 90 – 94
C: 80 – 89
D: 70 – 79
E: 69 and below
Algorithm Flowchart
LABORATORY EXERCISE NO. 4: REPETITION CONTROL STRUCTURES

Practice.
1. Design an algorithm and flowchart to find the factorial of a certain number
Algorithm Flowchart

2. Design an algorithm and flowchart to display the scores of both teams in 10 set of games.
Algorithm Flowchart

3. Design an algorithm and flowchart to find the value ( ) if x is from 1 to 10.


Algorithm Flowchart

4. Design an algorithm and flowchart to calculate the average of 25 scores and evaluate if it is grade
A, B, C, D, or E.
A: 95 – 100
B: 90 – 94
C: 80 – 89
D: 70 – 79
E: 69 and below
Algorithm Flowchart

Вам также может понравиться