Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Computer Programming

The document provides a comprehensive overview of computer programming, defining key terms such as computer language, programming, and program. It details the three levels of programming languages: machine language, low-level language, and high-level language, along with their advantages and disadvantages. Additionally, it introduces BASIC programming, its keywords, and sample programs demonstrating basic programming concepts.

Uploaded by

esther tope
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Programming

The document provides a comprehensive overview of computer programming, defining key terms such as computer language, programming, and program. It details the three levels of programming languages: machine language, low-level language, and high-level language, along with their advantages and disadvantages. Additionally, it introduces BASIC programming, its keywords, and sample programs demonstrating basic programming concepts.

Uploaded by

esther tope
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

COMPUTER PROGRAMMING

Definition of Terms

Language is a system of communication by written or spoken word which is used by the people
of a particular country or area.

Computer language is a system of instructions and commands for operating a computer. It is a


language that the computer understands and executes.

A program is a series of instructions which enable the computer to carry out some laid down
procedures to accomplish a given task or solve a problem.

Programming is the act of giving the computer a set of instructions or codes to carry out, or
perform a specific task.

Programming can also be said to be the process of taking the step in a procedure and putting
such in special languages (coding), which is the computer can understand.

A computer programming language is a large number of steps required to carry out a


procedure, for example, to compute student examination scores.

Levels of programming language

There are three major levels or types of programming language.

1. Machine Language: This language is made up of binary numbers. This means the
character set of machine language contains only 0s and 1s (zeros and ones). It requires
no translation hence the name machine language. It is the native language of a computer.
Machine language is machine dependent. This means machine language programs are not
portable.

Advantages of Machine Language

1. Machine language makes fast and efficient use of the computer.


2. It requires no translator to translate the code. It is directly understood by the
computer.

Disadvantages of Machine Language

1. All operation codes have to be remembered


2. It is machine dependent
3. It is hard to amend or find errors in a program written in the machine language.

2. Low-level language: A low Level programming Language is a programming that


provides little or no abstraction from a computer’s microprocessor. The word low does
not imply that the language is inferior to high level programming languages but rather
refers to the small or nonexistent amount of abstraction between the language and
machine: because of this, low level languages are sometimes described as being “close to
the hardware. Assembly language is a mnemonic representation of machine language. It
is one level above machine language. A program for translating low assembly language is
called assembler.
Advantages of Assembly Language
1. It is easier to understand and use as compared to machine language.
2. It is easy to locate and correct error as compared to machine language
3. Program written in assembly language executes faster than that of high level
language.
Disadvantages of Assembly Language
1. Assembly language, like machine code is also machine dependent
2. Difficult to remember the syntax.
3. High-level language: these languages are close to human languages and are far from
machine language. They are machine independent. This means programs written on one
machine or computer can be run on another machine, unlike the case of machine
language. The languages are problem oriented and not machine oriented. They are
designed to ease the work of the programmer.

Examples of High-Level Language include

a. PASCAL

b. BASIC (Beginners All-purpose Symbolic Instruction Code)

c. C ++

d. Java

e. FORTRAN (Formula Translation)


f. COBOL (Common Business Oriented Language)

g. PROLOG

h. ALGOL (Algorithmic language)

i. APL (A Programming Language)

j. RPG (Report Program Generator)

k. Python

Advantages of High Level Language


1. It is easier to learn and use
2. It user friendly
3. Programs in high level language requires less time to write
4. It is easier to maintain
5. It is machine independent
6. It does not require programmer to have knowledge of the computer hardware
architecture
Disadvantages of High Level Languages
1. It takes time to execute or run because it must first be translated into machine
code by a translator before it can be executed.
2. Programmers need to remember a large set of syntax and semantics

Comparison of Machine Language, Low Level Language (assembly language) and High

Level language

Language Characteristics

1. Machine Language 1. Machine dependent

2. Uses special code and the assignment of storage location


2. Low Level Language 1. Machine dependent

(Assembly language) 2. Uses mnemonics (symbolic operation code) and operand

(symbolic storage address)

3. 1 to 1 language

3. High Level Language 1. Machine independent

2. Uses instructions that seem English like

3. 1 to many languages, i.e. for one high level instruction, many

machine level statement may be generated.

Comparison Between Compiler, Interpreter, and Assembler

Feature Compiler Interpreter Assembler


Translates entire high- Translates high-level code Translates assembly
Definition level code into machine into machine code line-by- language code into
code before execution. line during execution. machine code.
Executes the translated Executes the translated
Executes the code directly
Execution code after the entire machine code
line-by-line.
program is compiled. immediately.
Generates an executable No separate executable file Generates an object file or
Output
file. generated; runs directly. machine code.
Generally faster execution Fast execution as it
Slower execution due to
Performance since the entire code is translates low-level code
line-by-line translation.
precompiled. directly to machine code.
Detects errors during Detects errors at runtime;
Error Detects errors in assembly
compilation; provides a stops at the first error
Detection code syntax.
list of errors at once. encountered.
Suitable for large
Suitable for scripting and Used for low-level
programs where
Use Case small programs where ease hardware programming
execution speed is
of debugging is important. and system development.
critical.
Languages Examples include C, C+Examples include Python,Examples include
Feature Compiler Interpreter Assembler
assembly languages like
+, and Java. Ruby, and JavaScript.
NASM, MASM.

SUMMARY:

 Language is a system of communication by written or spoken word which is used by the people
of a particular country or area.
 Computer language is a system of instructions and commands for operating a computer. It is a
language that the computer understands and executes.
 A program is a series of instructions which enable the computer to carry out some laid down
procedures to accomplish a given task or solve a problem.
 Programming is the act of giving the computer a set of instructions or codes to carry out, or
perform a specific task.
 Programming can also be said to be the process of taking the step in a procedure and putting such
in special languages (coding), which is the computer can understand.
 A computer programming language is a large number of steps required to carry out a procedure,
for example, to compute student examination scores.
 Low-Level Language Unlike human beings, the computer understands codes of digital binary
numbers.
 NEW: New is used when you want to start a new program
 OPEN: When you want to update a program that you already worked on, choose open and then
choose the program that you wish to work on
 SAVE: When you have saved a program once before and you want to save it again, choose save.
Save your work often
 SAVE AS: When you want to save a program for the first time, choose Save As. You then have
to give your program a name. Your program name should not be more than 8 letters long.
 PRINT: Choose print when you want to send your program to the printer.

BASIC IN PROGRAMMING

BASIC stands for BEGINNERS ALL-PURPOSE SYMBOLIC INSTRUCTION CODE. It is a


single easy to use language designed also for beginners. It is not only simple but also powerful. It
is science oriented. Professor John Kemeny and Thomas Kurtz developed the language in 1964
at Dartmouth College, U.S.A., as a means of teaching students a simple language for
programming a computer. The program can be used to solve problem covering a wide range of
application on many different types of digital computer. Because the BASIC Language has been
designed for ease of use and is readily available on most computers, program development can
be achieved in minimum time.

There are different versions of Basic. They include:


 Turbo Basic (T-BASIC)
 BASIC PLUS
 GW BASIC
 QUICK BASIC (Q-BASIC)
 VISUAL BASIC (V-BASIC)

KEYWORDS IN BASIC

This is also referred to as BASIC statement or a reserved word. It is an instruction in BASIC,


which has a specific means to the compiler or interpreter.

1. REM STATEMENT

The REM statement is a remark statement. It is used to insert remarks in the program. Such
remarks are used to explain what the program is all about.

Example:

10 REM This program finds the average of 5 numbers

2. LET STATEMENT

The LET statement is used to assign (or give) values to variables.

Examples:

10 LET A = B + C

3. INPUT STATEMENT

Input is used to assign or give values to variables while program is running. It can be used with
both numeric and string variables.

Examples:

10 INPUT A, B, C

4. PRINT STATEMENT

The print statement tells your computer to display the output of the executed program on the
screen of the monitor (VDU).

Example:

10 PRINT SUMS
5. END STATEMENT

End Statement is an instruction used to terminate the program. One the computer encounters
END statement, it automatically terminates the program.

50 END

6. RUN STATEMENT

The RUN statement is used to execute a program. In Q-BASIC, F5 is used to RUN a program.
Note that the program will not RUN if any mistake or error is detected in it.

PROGRAM SAMPLE

STEP 1: Writing Simple Basic Programs

1. Write a BASIC program to calculate the product of three numbers

Solution:

100 REM: Program to calculate the product of three numbers

200 LIST:

300 PROD

400 READ A, B, C

500 DATA 3, 4, 9

600 LET P = A*B*C

700 PRINT P

800 END

Note: The line number does not affect the program.

2. Write a program to calculate the area of a circle. (Area= πr2)

Solution:

10 CLS

15 Program to calculate area of a circle


20 Let area = 3.142*r**2

30 PRINT area

30 END

3. Write a program to calculate simple interest

Solution:

Algorithm to calculate S.I

STEP (1) Using pseudo code

S.I. = PRT

100

Begin

INPUT P, R, T

S.I. = (P*R*T)/100

PRINT 1

4. Write a BASIC program to calculate the sum of two numbers

Solution:

REM a program to add 2 numbers

CLS

INPUT Number 1

INPUT Number 2

TOTAL = Number 1 + Number 2

PRINT “TOTAL”

END

5. Write a BASIC program to find the average of 3 Numbers


Solution:

REM A program to find the average of 3 numbers

CLS

INPUT NUMBER 1

INPUT Number 2

INPUT Number 3

TOTAL = Number 1 + Number 2 + Number 3

AVERAGE = TOTAL/3

PRINT

END

6. Write a BASIC program to calculate the area of a triangle with base

Solution:

REM A program to find the average of 3 numbers

CLS

INPUT base

INPUT height

AREA = 0.5 base * height

PRINT

EVALUATION:

1. Write a program to find the product of four numbers using the ‘LET’ statement?
2. Write a program to calculate the average of five numbers using the ‘INPUT’ statement?

You might also like