You are on page 1of 25

CSC 201 LECTURE NOTE FOR DEGREE

STUDENTS (200L)

02 Thursday May 2019

COURSE CODE: CSC201

COURSE TITLE: COMPUTER AND ITS APPLICATION

COURSE UNIT: 4

COURSE OUTLINE

WEEK TOPIC
1 INTRODUCTION TO DIGITAL COMPUTERS,THEIR USES, AND STRUCTURE OF A
GENERAL PURPOSE-COMPUTER
2 BRIEF HISTORY OF COMPUTERS
3 GENERATION OF COMPUTERS
4 MODERN PROGRAMMING TECHNIQUES
5 GENERAL PROBLEM SOLVING, SYSTEMATIC DEVELOPMENT OF ALGORITHM,
ELEMENTARY NUMERICAL ALGORITHM
6 FLOW DIAGRAMS
7 MEANING OF LOGICAL PROCESSES, ANALYSIS OF COMPUTATIONAL PROBLEMS,
CODING OF PROGRAMMING
8 PRACTICAL EXPERIENCE OPERATING COMPUTERS AND PERIPHERAL
EQUIPMENT
9 EXTENSIVE PRACTICE WITH ONE OR MORE HIGH LEVEL LANGUAGE
10 EMPHASIS ON TECHNICAL APPLICATIONS
11 REVISION / CA

INTRODUCTION TO COMPUTER

A computer is a programmable machine (electronic and digital) that is capable of accepting data
(input) and performing a sequence of operations (process) in accordance with set of procedural
instructions (program) to produce a result in form of information or signals (output).

ANATOMY OF A DIGITAL COMPUTER

A digital computer consists of three units, namely:

1. Input Device
2. Central Processing Unit (CPU)
3. Output Unit

The various functions of these units can be summarized as:

1. Input Device: It reads information from input media and enters to the computer in a coded form
2. Central Processing Unit: this is sub-divided into three, namely;
3. Arithmetic Logic Unit: It performs arithmetic and logical functions
4. Control Unit: It controls the input and output devices

Memory Unit : It stores program and data e.g Register, Cache etc.

3. Output Device: It decodes information and presents it to the user

DATA, INFORMATION AND PROGRAM

Data: It is the collection of raw facts, figures & symbols. Ex : Names of students and their marks in
different subjects listed in random order.
Information: It is the data that is processed & presented in an organized manner. For example:
When the names of students are arranged in alphabetical order, total and average marks are
calculated & presented in a tabular form, it is information.
Program: This is a set of instructions that enables a computer to perform a given task

ADVANTAGES OF COMPUTERS

1. High speed: Computers have the ability to perform routine tasks at a greater speed than human
beings. They can perform millions of calculations in seconds.
2. Accuracy: Computers are used to perform tasks in a way that ensures accuracy.
3. Storage: Computers can store large amount of information. Any item of data or any instruction
stored in the memory can be retrieved by the computer at lightning speeds.
4. Automation: Computers can be instructed to perform complex tasks automatically (which
increases the productivity).
5. Diligence: Computers can perform the same task repeatedly & with the same accuracy without
getting tired.
6. Versatility: Computers are flexible to perform both simple and complex tasks.
7. Cost effectiveness: Computers reduce the amount of paper work and human effort, thereby
reducing costs.

LIMITATIONS OF COMPUTERS

1. Computers need clear and complete instructions to perform a task accurately. If the instructions
are not clear & complete, the computer will not produce the required result.
2. Computers cannot think.
3. Computers cannot learn by experience.

OVERVIEW OF COMPUTER HARDWARE

Computer hardware is the collection of the physical parts of a computer system. This includes the
computer case, monitor, speaker, scanner, printer and mouse. It also includes all the parts inside the
computer case, such as the hard disk drive, motherboard, video card etc.

SUB-CLASSIFICATION OF COMPUTER HARDWARE

The parts making up of Computer hardware include:


1. Input devices
2. Processing devices

Output devices

1. Storage devices
2. Communication networks
3. Input devices

An input device is a piece of computer hardware used to send data into a computer system. An input
device allows users to communicate and feed instructions and data to computers for processing,
display, storage and transmission

Examples of input devices include:

1. Keyboards
2. Mouse

Digital camera

1. Light pen
2. Scanner
3. Joystick

Optical Mark Reader (OMR)


Optical Character Reader (OCR)

1. Magnetic Ink Character Recognition (MICR)


2. Bar code Reader

1. Processing devices

A processing device is any device in a computer that processes data into a usable format for the user.

When a computer receives data from an input device (e.g keyboard or mouse) the data must go
through an intermediate stage before it can be sent to an output device (e.g monitor or printer). A
processing device handles the intermediate stage.

Examples of processing devices include;

1. Central Processing Unit (CPU)


2. Graphics Processing Unit (GPU)

Motherboard

1. Network card
2. Sound card
3. Video card

The Central Processing Unit/Microprocessor

The microprocessor is the major device in this category. It works closely with primary memory
during its operations. Data is stored temporarily in processor cache and primary memory during the
processing period.
The microprocessor is sub-divided into three important units, namely:

1. The Control unit: It manages and supervises the operations of the processor and other
components that are crucial in data manipulation.
2. Arithmetic and logic unit: The ALU is responsible for all arithmetic and logic operations like
addition, multiplication, subtraction, division, and comparison logic operations.
3.
Register and cache: These are storage locations inside the processor that respond to the
instructions of the control unit by moving relevant data around during processing.

Output devices

An output device is any peripheral that receives data from a computer, usually for display,
projection, or physical reproduction. An output unit is responsible for providing the output in user
readable form. It can be text, graphics, tactile, audio, and video.

Examples of Output devices include:

1. Monitor
2. Printer

Plotter

1. Projector
2. Speaker
3. Storage device

Storage device refers to a computer hardware device used to store information permanently or
temporarily. The device can be external or internal to a computer, server, and other computing
systems.

There are two types of storage devices, namely;

1. Primary storage device


2. Secondary storage device

1. Communication Networks

Computer hardware requires physical connections that allow components to communicate and
interact. A bus provides a common interconnected system composed of a group of wires or circuitry
that coordinates and moves information between the internal parts of a computer.
A bus is characterized by two features: how much information it can manipulate at one time, called
the bus width, and how quickly it can transfer these data.

1. A serial connection is a wire or set of wires used to transfer information from the CPU to an
external device such as a mouse, keyboard, modem, scanner, and some types of printers. This
type of connection transfers only one piece of data at a time, and is therefore slow.
2. A parallel connection uses multiple sets of wires to transfer blocks of information simultaneously.
Most scanners and printers use this type of connection. A parallel connection is faster than a serial
connection.

SOFTWARE

Software is a collection of programs that utilize and enhance the capability of the hardware.

There are two types of software:

1. System software
2. Application software
3. System software

System software is responsible for controlling, integrating, and managing the individual hardware
components of a computer system so that other software and the users of the system see it as a
functional unit without having to be concerned with the low-level details such as transferring data
from memory to disk, or rendering text onto a display.

Examples of system software include Microsoft Windows Operating System, Linux, UNIX, Macintosh
OS, Disk Operating System, AVG etc.

Classifications of System software

There are four major sub-classification of system software, namely:

1. Operating System
2. Language translator
3. Utility programs
4. Device driver
5. Operating system

An operating system is a suite of programs that manage computer hardware and software resources.

Functions of Operating System

1. It manages the computer’s resources such as central processing unit (CPU), memory, disk drives,
printer etc.
2. It provides services for applications software.

It manages input and output devices

1. Language translator

Language translator is a computer program that performs the translation of a program written in a
given programming language into a functionally equivalent program in another computer language.

There are three major types of language translators, namely:


Compiler
Interpreter
Assembler

1. Utility programs

These programs are primarily used for diagnostic and maintenance tasks of the computer.

Examples include

Antivirus e.g AVG,Avast,Norton etc.


Firewall for protection against external threats e.g Windows firewall
File Compressor e.g WinRaR, Winzip, 7-Zip etc.

1. Device Driver

Device driver is a type of system software that activates computer devices and peripherals. Drivers
make it possible for all connected components and external devices to perform their intended tasks as
directed by the operating system.

Examples of devices that require drivers include:

Soundcard
Network card
Display card

Application software

Application software is a program primarily designed to perform a group of coordinated functions,


tasks or activities for the benefits of the user.

These include:

1. Entertainment software
2. Educational and Reference software

Specialty software

1. Productivity software
2. Personal software

BRIEF HISTORY OF COMPUTERS

Since the creation of man, a significant amount of human activities has been ascribed to organizing
and processing information so that it could be more easily presented for easy comprehension. It is
necessary to examine the evolution of computers.

1. Tally Sticks
A tally stick was an ancient memory aid device to record and document numbers, quantities, or even
messages.

2. Abacus

An abacus is a mechanical device used to aid an individual in performing mathematical calculations.


The abacus was first used in China in around 500 B.C. The abacus was invented in Babylonia in 2400
B.C. It used to perform basic arithmetic operations.

3. Napier’s Bone

In 1614, John Napier invented Napier’s Bone. This consists of small rods with appropriate markings
on them. It is a mechanical device used to perform multiplication, division and calculate square and
cube roots by moving the rods around and placing them in specially constructed boards.

4. Slide Rule

In 1622, William Oughtred invented the Slide Rule but announced it in 1632. The Slide Rule permits
calculation involving multiplication, division, exponents,logarithm, trigonometric functions etc.

5. Pascal mechanical calculator (Pascaline)

Blaise Pascal, a French mathematician in 1642 invented the first adding machine called Pascaline. It
can perform addition and subtraction.

6. Leibnitz mechanical multiplier (Stepped Reckoner)


In 1694, Gottfried Wilhem Von Leibnitz improved upon the Pascaline by creating a machine that can
perform multiplication and division using a system of dials and gear.

7. Jacquard Loom

1801, Joseph-Marie Jacquard invented Jacquard loom. His invention provided a mechanized means of
controlling weaving looms leading to woven fabrics such that complex patterns can be woven to the
cloth. It an automatic loom controlled by punched cards.

8. Arithmometer

In 1820, Thomas de Colmar invented a mechanical calculator, the first reliable, useful and
commercially successful calculating machine. The machine could perform the four basic mathematic
functions.

9. Difference Engine and Analytical Engine

In 1812, Charles Babbage developed Difference Engine. This machine had the capability of
polynomial evaluation by means of finite difference and consequently was very useful in the
generation of mathematical tables.

In 1832, Charles Babbage made a more serious effort which resulted in his invention of the Analytical
Engine. The Analytical Engine was programmed by Lady Augusta Ada Byron.

10. Hollerith Census Machine

In 1890, Herman Hollerith, an American Statistician developed Hollerith Machine to help Americans
in census result processing.

11. ENIAC

In 1946, John Presper Eckert and John Mauchly developed the first electronic general purpose
computer called ENIAC. ENIAC stands for Electronic Numerical Integrator And Computer.
Electronic Controls Company (ECC) was the First Computer Company founded by John Presper
Eckert and John Mauchly in 1949.

12. UNIVAC 1

The UNIVAC I (UNIVersal Automatic Computer 1) was the first commercial computer designed by
John Presper Eckert and John Mauchly in 1951.

13. EDVAC

EDVAC stands for Electronic Discrete Variable Automatic Computer. EDVAC was the first stored
program computer designed by Von Neumann in 1952. It has a memory to hold both a stored
program as well as data.

CLASSIFICATION OF COMPUTERS

Computers can be classified as follows:


1. According to generation
2. According to versatility (purpose)

According to data handling(data types)

1. According to size
2. ACCORDING TO GENERATION

The history of computer development is often referred to in reference to the different generations of
computing devices. Each generation of computer is characterized by a major technological
development that fundamentally changed the way computers operate, resulting in increasingly
smaller, cheaper, more powerful, efficient and reliable devices.

1. First Generation (1940-1956): Vacuum Tubes

The first generation computers made use of:

1. Vacuum tube technology


2. Punched cards for data input

Punched cards and paper tape for output

1. Machine Language for writing programs


2. Magnetic tapes and drums for external storage.

2. Second Generation (1956-1963): Transistors

The second generation computers made use of:

1. Transistor technology
2. Assembly language

Concept of stored program emerged

1. High level languages were invented.

3. Third Generation (1964-1971): Integrated Circuits

The third generation computers were characterized by:

1. Use of Integrated circuits


2. Phenomenal increase in computation speed

Substantial reduction in size and power consumption of the machines

1. Use of magnetic tapes and drums for external storage


2. Design-of Operating systems and new higher level languages
3. Commercial production of computers.
4. Fourth Generation (1971-Early 1990’s): Microprocessors

The general features of the fourth generation computers were:


1. Use of Very Large Scale Integration
2. Invention of microcomputers

Introduction of Personal Computers

1. Networking
2. Fourth Generation Languages
3. Fifth Generation – Present and Beyond: Artificial Intelligence

Fifth generation computing devices, based on Artificial intelligence and Expert Systems, are still in
development, though there are some applications, such as voice recognition, that are being used
today. The use of parallel processing and superconductors is helping to make artificial intelligence a
reality. Quantum computation and molecular and nanotechnology will radically change the face of
computers in years to come. The goal of fifth-generation computing is to develop devices that
respond to natural language input and are capable of learning and self- organization.

1. ACCORDING TO PURPOSE

Computers are either general purpose or specific purpose.

General purpose computers: These are designed to perform a range of tasks. They have the ability to
store numerous programs, but lack in speed and efficiency.

Specific purpose computers: These are designed to handle a specific problem or to perform a specific
task.

ACCORDING TO DATA HANDLING (DATA TYPES)

1. Analog Computer: In analog computers, data is recognized as a continuous measurement of a


physical property like voltage, speed, pressure etc.
2. Digital computers: These are high speed electronic devices. These devices are programmable.
They process data by way of mathematical calculations, comparison, sorting etc. They accept
input and produce output as discrete signals representing high (on) or low (off) voltage state of
electricity.

Hybrid computers : Hybrid Computers combine the features of both analog and digital
computers. They are mostly used in specialized applications where the input data is in an analog
form i.e. measurement. This is converted into digital form for further processing.

1. According to size
2. Super Computer

The fastest and most powerful type of computer Supercomputers are very expensive and are
employed for specialized applications that require immense amounts of mathematical calculations.
For example, weather forecasting requires a supercomputer. Other uses of supercomputers include
animated graphics, fluid dynamic calculations, nuclear energy research, and petroleum exploration.

1. Mainframe Computer

Main frame computers are very large computers which process data at very high speeds of the order
of several million instructions per second. They can be linked into a network with smaller computers,
microcomputers and with each other. They are typically used in large organizations, government
departments’ etc. ex. IBM4381, CDC

1. Mini Computer
A mid-sized computer in size and power, minicomputers lie between workstations and mainframes.
A minicomputer is a multiprocessing system capable of supporting from 4 to about 200 users
simultaneously. They are mainly used in applications like payrolls, financial accounting, Computer
aided design etc.

1. Micro Computer or Personal Computer

Microcomputers are generally referred to as Personal Computers (PCs). They have smallest memory
and less power. They are widely used in day to day applications like office automation, and
professional applications, ex. PCAT, Pentium etc

APPLICATIONS OF COMPUTERS

Today computers find widespread applications in all activities of the modern world. Some of the
major application areas include:

1. Scientific, Engineering and Research: This is the major area where computers find vast
applications. They are used in areas which require lot of experiments, mathematical calculations
weather forecasting, and complex mathematical and engineering applications. Computer Aided
Design (CAD) and Computer Aided Manufacturing (CAM) help in designing robotics,
automobile manufacturing, automatic process control devices etc.
2. Business: Record keeping, budgets, reports, inventory, payroll, invoicing, accounts are all the
areas of business and industry where computers are used to a great extent.
3. Medicine: Computerized systems are now in widespread use in monitoring patient data like,
pulse rate, blood pressure etc. resulting in faster and accurate diagnosis. Modern day medical
equipment are highly computerized today. Computers are also widely used in medical research.
4. Information: This is the age of information. Television, Satellite communication, Internet,
networks are all based on computers.
5. Education: The use of computers in education is increasing day by day. The students develop the
habit of thinking more logically and are able to formulate problem solving techniques. CDs on a
variety of subjects are available to impart education. Online training programs for students are
also becoming popular day by day. All the major encyclopedias, dictionaries and books are now
available in the digital form and therefore are easily accessible to the student of today.
6. Games and Entertainment: Computer games are popular with children and adults alike.
Computers are nowadays also used in entertainment areas like movies, sports, advertising etc.

COMPUTER MEMORY

Computer memory is any physical device capable of storing information temporarily or permanently.

Types of Memory

There are two types of computer memory

1. Primary Memory (Internal storage)


2. Secondary Memory (External storage)
3. Primary Memory

Primary memory is also called internal memory and is an important part of a computer. It is the main
area in a computer where the data is stored. The stored data can be recalled instantly and correctly
whenever desired. This memory can be quickly accessed by the CPU for reading or storing
information.
Primary memory is further classified into two types:

1. Random Access Memory (RAM)


2. Read Only Memory (ROM )

1. RAM: RAM is also known as read/write memory as information can be read from and written
onto it. RAM is a place in a computer that holds instructions for the computer, its programs and
the data. The CPU can directly access the data from RAM almost immediately. However, the
storage of data and instructions in RAM is temporary, till the time the computer is running. It
disappears from RAM as soon as the power to the computer is switched off. i.e it is volatile
memory.
2. ROM: It is called Read-only memory as information can only be read from and not written or
changed onto ROM. ROM is the “built-in” memory of a computer. It stores some basic input –
output instructions put by the manufacturer to operate the computer. The storage of data and
instructions in ROM is permanent. It does not depend on the power supply. i.e it is non-volatile
memory.
3. Secondary memory

The secondary memory is for massive storage of data. It is also referred as backup storage as it is
used to store large volume of data on a permanent basis which can be transferred to the primary
memory whenever required for processing. Some of the devices of secondary storages are Floppy
Disk, Hard Disk, CD-ROM, DVD and Flash drive.

UNITS OF MEMORY

The computer stores a character in the storage cells with binary (0,1) mechanism. Thus the basic unit
of memory is a bit (binary digit – 0,1). To store a character, a computer requires 8 bits or 1 byte. This is
called the word length the storage unit. Hence the storage capacity of the computer is measured in
the number of words it can store and is expressed in terms of bytes.

The different units of measurement are:

1. 8 Bits = 1 Byte
2. 4 Bits = 1 Nibble

1024 Bytes = 1 Kilo Byte (KB)

1. 1024 KB = 1 Mega Byte (MB)


2. 1024 MB = 1 Giga Byte (GB)
3. 1024 GB = 1 Tera Byte (TB)

INTRODUCTION TO PROGRAMMING

Computer programming is the process of designing and building an executable computer


program for accomplishing a specific computing task. In other words, programming is the process of
taking an algorithm and encoding it into a notation, a programming language, so that it can be
executed by a computer.

PROGRAMMING LANGUAGES

There are three types of programming languages, namely:


1. Machine Language (ML): Computers respond only to machine language. This language is in terms
of binary codes (0,1). i.e. all programs should be written with these codes, which is difficult, time
consuming and leading to errors while writing the programs. There is no unique standard
machine language. Rather there are many machine languages. These are machine dependent.
These are referred as the first generation languages.
2. Assembly Language (AL): It uses mnemonic codes rather than numeric codes (as in machine
languages). Ex. Add or A is used as a symbol for addition. It requires translators to convert into
machine language. Like machine language, writing program in assembly language is also time
consuming. These are also machine dependent.
3. High Level Languages (HLL): These are referred as problem oriented languages (POL). These are
referred as third generation languages. Such languages are considered high-level because they are
closer to human languages.

Advantages of High Level Languages (HLL)

1. The high level languages are convenient for writing programs as they can be written without any
codes. These languages follow rules like – English language.
2. They are machine independent. A program written in any HLL can be run on computers of
different types without any modifications.

Examples of High Level Languages (HLL) include:

1. FORTRAN : FORmula TRANslation


2. COBOL : Common Business Oriented Language
3. BASIC : Beginner‘s All purpose Symbolic Instruction Code
4. PROLOG: PROgramming in LOGic
5. ALGOL : ALGOrithmic Language
6. PASCAL
7. C Language
8. C++: C Plus plus
9. C# : C Sharp

STAGES IN THE DEVELOPMENT OF A COMPUTER PROGRAM

The various stages in the development of a computer program are:

1. Problem Definition
2. Program Design
3. Coding
4. Testing
5. Debugging
6. Documentation
7. Maintenance

1. a) Problem Definition: Thorough understanding and identification of the problem for which a
program is to be written.
2. b) Program Design: Tools like algorithms and flowcharts are used to design the program. The
techniques employed in design are modular-programming, top-down design.
3. c) Coding: At this stage, the actual program is written using a computer language.
4. d) Debugging: Here the errors in the program are detected and corrected. e) Testing: A test plan
for the program which has been done at the design stage is applied here to test the program on a
number of suitable test cases.
5. f) Documentation: This stage ensures that further modifications, redesign and maintenance can be
made easy to the user who maintains the software.
6. g) Maintenance: Updating and correction of programs is covered in maintenance.

ALGORITHM

An algorithm is a step by step procedure for solving a specific problem.

Characteristics of a good algorithm are:

1. Precision: the steps are clearly stated (defined).

1. Uniqueness: results of each step are uniquely defined and only depend on the input and the result
of the preceding steps.
2. Finiteness: the algorithm stops after a finite number of instructions are executed.
3. Generality: the algorithm applies to a set of inputs.

Example

Write an algorithm to calculate the area of a rectangle

Solution:

Step 1: Start

Step 2: Input the Length L and Width W

Step 3: A= L X W

Step 4: Print the area, A

Step 5: Stop.

FLOWCHART

A flowchart is the graphical or pictorial representation of an algorithm with the help of different
symbols, shapes and arrows in order to demonstrate a process or a program. The main purpose of a
flowchart is to analyze different processes.

Several standard graphics are applied in a flowchart:

The symbol denotes the


beginning, ending and halt
TERMINAL (START/STOP) operation in the program
logic.
INPUT/OUTPUT It Indicates when an input
or output operation is to
performed in the process.
PROCESS This represents the
arithmetic operations like
addition, subtraction etc,
and the movement of data in
the process
DECISION The decision symbol is used
to represent a point where
one or more alternatives is
possible.
CONNECTOR A connector is used to
indicate the logic flow from
one page to another when
the flowchart becomes very
long.
FLOW LINES These indicatetheflowof
operation
EXAMPLE

Develop a flowchart to calculate the area of a rectangle


BASIC PROGRAMMING

BASIC is an acronym for Beginners’ All-purpose Symbolic Instruction Code. BASIC is the name of a
high level programming language developed at Dartmouth College, New Hampshire USA under the
auspices of professors John G. Kemeny and Thomas E. Kurtz during their academic years- 1963-64.
The language was developed to teach beginners the basic construct s of programming theory and as
much, one of the easiest programming languages to learn.

As a high level programming language program code written in written in BASIC must be translated
to its equivalence in machine code before it can be executed on the computer.

Merits of BASIC Programming Language

1. BASIC is the simplest programming language


2. BASIC is friendly, easy to teach and to learn compared to other HLL languages

It is flexible and easy to code or modify existing code

1. It has simplified grammar (syntax) and relatively fewer number of statements

Demerits of BASIC Programming Language

1. It has slow execution pace, as translation is combined with execution.


2. Many versions of BASIC are unstructured because of statements such as GOTO.

Limited portability as different versions requires different interpreter for source code translation.

Different Versions of BASIC Programming Language

More than 50 versions of BASIC exist today as a result of variations in hardware systems. All these
variations are expected to conform to the universally accepted standard set out by American National
Standard Institute (ANSI).

Some of these versions are: ANSI BASIC, VISUAL BASIC, GW BASIC, QUICK BASIC, TURBO
BASIC, BASICA, MFBASIC, CASSETTE BASIC, APPLE BASIC etc.

BASIC Character Set

1. Alphabets Letters: A-Z; a-z


2. Numbers: 0-9

Special characters: ?, (,), +, =, *, &, ”, %, $, n, !, >, <, ; etc.

Structure of Basic Program

Every statement must appear on a separate line

A statement must not exceed one line in length

Each statement must be preceded by a line number (or statement number or label) which must be an
integer.
Two statements cannot have the same line number.

Blank spaces can be inserted wherever desired to improved readability of the program. Each line
number must be followed by a BASIC keywords which indicates the type of instruction that is to be
carried out in the line. Successive statements must have increasing statement numbers. Although
these rules are relaxed in some versions of BASIC, programs written with adherence to these rules
remain valid.

In summary, BASIC program consists of the following components;

1. Program heading
2. Variable/Constant Declaration

Program Statement

1. Terminal Statement

Example

Write a BASIC program to compute the area of a rectangle whose length is 10cm and its width is 8cm.

10 REM PROGRAM TO COMPUTE THE AREA OF A RECTANGLE

20 INPUT LENGTH, L AND WIDTH, W

30 LET L=10

40 LET W=8

50 LET AREA=L X W

60 PRINT AREA

70 END PROGRAM

Identifiers (or Names) in BASIC

There are two types of identifiers in BASIC:

BASIC Keywords or reserved words: these are identifiers that have predefined meanings e.g . LET,
PRINT, END, INPUT,etc.

BASIC User-defined names : these are identifiers created by the programmers according to his needs
and following Basic rules for creating such e.g. NAME$, SCORES%, ”CATERORY A” etc.

Types of User-defined Names in BASIC

There are two types of user defined names or identifiers in BASIC, namely: i. Variables

1. Constants.

Variables in BASIC
A variable is a name or identifier that represents number or a string of characters whose value can
change during or after the execution of a BASIC program.

There are two types of variable valid in BASIC, they are:

1. Numeric Variables
2. String Variables

The rule is that every alphanumeric, that is string variable must end with the data-type symbol $.
When a variable name has no $ symbol after it, it is taken to be a numeric variable.

Constants in BASIC

A constant is an identifier, a number, a string of characters whose value cannot change during or after
the execution of a BASIC program.

There are two types of constants:

3. Numeric constants e.g. 0, 3.14 etc


4. Alphanumeric or string constants e.g. “The bride’s age is”

Operations in BASIC

BASIC recognizes the following different types of operations in a BASIC program.

Arithmetic Operations

Arithmetic Operators are used to carry out arithmetic operations in BASIC. These operators are
executed according to precedence of rule i:e hierarchy

The hierarchy of arithmetic operations in descending order:

1. Exponentiation
2. Multiplication/Division

Addition/Subtraction

Algebraic Expression

Mathematical Expression BASIC Expression


2A+B 2*A+B
A+B/C+D
A(B+C) A*(B+C)
B2-4AC B^2  ̶ 4*A*C

Relational Operations in BASIC

These involve the use of relational operators listed below:

Operator symbol Operation performed


= Equals to
> Greater than
< Less than
>= Greater than or equals to
<= Less than or equals to
<> Not equals to

Logical Operations in BASIC

Logical operations in BASIC involve the use of logical operators e.g NOT, AND, OR which must yield
logical values TRUE (T) or FALSE (F)

NOT-this logical operator has the highest precedence or priority over others. It affects only one
operand or variable at a time.

There could only be two possible combinations and outcomes as shown in the truth table below:

INPUT OUTPUT
T F
F T
AND – this is another logical operator that affects two variables at a time thus providing four
possible combinations as shown below:

INPUT A AND INPUT B OUTPUT


T X T T
T X F F
F X T F
F X F F
OR – this logical operator with the lowest precedence affects two operators at a time giving rise to
four possible combinations as shown in the table below:

INPUT A OR INPUT B OUTPUT


T + T T
T + F T
F + T T
F + F F

FUNCTIONAL OPERATORS

Functional operators are inbuilt operators that the programmer can call or invoke from BASIC
functions library to solve some programming related problems instead of writing the code that will
solve such problems himself. Examples of such functions include: COS, SIN, ABS, SORT, TAN, SUM,
LEN, etc for cosine, sine, absolute, square root, tangent, summation, and word- length functions
respectively.
o
Example: Given that x = 45 , Develop a BASIC program that generate and display the sine, cosine
and Tan of x.

Solution

10 REM PROGRAM TO GENERATE AND DEVELOP THE SINE, COSINE AND TAN OF X

20 INPUT X

30 LET X = 45

40 LET P = SINE (X)

50 LET Q = COS (X)

60 LET R = TAN (X)

70 PRINT P, Q, R

80 END

PROJECT

1. Develop an algorithm, flowchart and write a BASIC program to input the radius of the base of a
cone at the keyboard of a computer, calculate the base area, volume and output these values to the
screen of a monitor.
2. Develop an algorithm, flowchart and write a BASIC program to calculate the simple interest on
#20,000 at 5% per annum for 4 years.

INTRODUCTION TO C++ PROGRAMMING

C++ is a high-level programming language developed by Bjarne Stroustrup at Bell Labs. C++
adds object-oriented features to its predecessor, C. The main highlight of C++ is a collection of
predefined classes, which are data types that can be instantiated multiple times. The language also
facilitates declaration of user-defined classes. Classes can further accommodate member functions to
implement specific functionality. Multiple objects of a particular class can be defined to implement
the functions within the class. Objects can be defined as instances created at run time. These classes
can also be inherited by other new classes which take in the public and protected functionalities by
default.

Object-Oriented Programming Language (OOPL)


OOPL is a programming language specifically designed to support the writing of object-oriented
programs. Such languages typically support three features not found in traditional programming
languages: classes, encapsulation and inheritance, though the actual constructs that embody these
features may have different names in different languages. The first such OOPL to be invented was
SIMULA, and the most widely used OOPL today is C++, which is a derivative of the C language with
added object-oriented features. Other important OOPLs include Java, Object Pascal, Eiffel etc.

C++ includes several operators such as comparison, arithmetic, bit manipulation and logical
operators.

Let’s get coding

#include <iostream>

using namespace std;

int main()

cout<<“Hello World!”;

return 0;

The program prints Hello Word! in the output screen.

The code is divided into six major parts:

1. #include <iostream>
2. using namespace std
3. ;
4. int main() { }
5. cout << “Hello World!”;
6. return 0;

1. #include <iostream>
This statement includes the header file into the application so that you are able to use the
operations included in them. Also, you can create your own header files and include them in your
program using the #include.
iostream

iostream is what you call the header file. It is a standard C++ input/output library file.
It comes packaged with the compiler/IDE coupled with mechanisms to get the information from the
user and print same or added information to a file, screen or any other media.

What is #include?

The #include iostream file, into the program. This ensures that now you’re able to use the
operations, iostream operations (like: taking input from user, displaying output on the screen), in the
program.
2. What is using namespace std;”?
The statement is intuitive in itself; you are “using” the “namespace” “std” in your file.
We use the namespace std to make it easier to reference operations included in that namespace.
If we hadn’t used the namespace, we’d have written std::coutinstead of cout. This tells the
compiler that every cout is actually std::cout.

What’s a namespace?

It’s a region where your code resides. It limits or expands the scope of your code to one or more
files.

Why do you use namespace?

Like two persons can have the same name, variables and functions in C++ can have same names as
well. The use of namespace is to avoid the confusion of which variables/functions you are
referencing to.

What is std?
std is a standard namespace used in C++.

3. Semicolon ”;”
The semicolon is a terminal. It terminates a statement. When missed or incorrectly used, it will
cause a lot of issues.
4. int main() { }
As the name suggests, it is the main function of the program. The code inside { } is called the body
and is executed first when you run your C++ program.
It is one code that is mandatory in a C++ program. If you just have this line of code alone, your
program will be valid.
5. cout << “Hello World!”;
This statement prints “Hello World!” onto the output screen.
The cout is an object of standard output stream. What this means is, it outputs/prints the data
after <<, i.e. Hello World! into a stream (in this case, the output screen).
What is a stream?
Stream is basically a sequence of objects, usually bytes. It can describe files, input/output terminal,
sockets, etc.

What is <<?
<< is the insertion operator used to write formatted data into the stream.

6. What is return 0;?


This statement returns 0 ‘zero’.
This is called a return statement. It isn’t mandatory to return anything from the main() function
but is rather a convention. If not return, the compiler returns a status automatically.
Why zero in return statement?
It denotes Exit status of the application that basically the tells system “The program worked fine.”

FEATURES OF C++ PROGRAMMING

Being a general-purpose language, C++ is undoubtedly feature-rich. Going through all the features
will take you some time but, as a beginner, below are the most important features you should know.
1. C++ is fast
Since, C++ is an extended version of C, the C part of it is very low level.
This offers a huge boost in speed that high level languages like Python, Java don’t give you.
2. C++ is statically typed
C++ is a statically typed programming language.
In simple terms, C++ doesn’t allow the compiler to make assumptions about the type of data e.g.
10 is different from “10” and you have to let C++ know which one you are talking about.
3. C++ is a multi-paradigm programming language
C++ supports at least 7 different styles of programming and gives developers the freedom to
choose one at their will.
4. Object oriented programming with C++
Object oriented programming helps you solve a complex problem intuitively.
With its use in C++, you are able to divide these complex problems into smaller sets by creating
objects.
5. Power of standard library (Standard template library – STL)
The power of C++ extends with the use of standard libraries contained in it.
These libraries contain efficient algorithms that you use extensively while coding.
This saves ample amount of programming effort, which otherwise would have been
wasted reinventing the wheel.

STRUCTURE OF A C++ PROGRAM

Programs are a sequence of instructions or statements. These statements form the structure of a C++
program. C++ program structure is divided into various sections, namely, headers, class definition,
member functions definitions and main function.

Escape Sequences

Commonly used escape sequences are \n, \t and \a. The escape sequences are enclosed in single
quotes. \n is a new line character and helps in transferring control to the next line. If more than one
line is to be skipped, \n is repeated as many times as the number of lines to be skipped. \n can also
be combined with any other message string to be displayed. \t is used for giving tab and \a is used
for giving a beep.

Escape Sequence Represented Character


\a System bell (beep sound)
\b Backspace
\f Formfeed (page break)
\n Newline (line break)
\r “Carriage return” (returns cursor to start of line)
\t Tab
\\ Backslash
\’ Single quote character
\” Double quote character
\some integer x The character represented by x
Input Output Statements in C++

cin and cout are two predefined objects which represent standard input and output stream. The
standard output stream represents the screen, while the standard input stream represents the
keyboard. These objects are members of iostream class. Hence the header file <iostream.h> should be
included in the beginning of all programs.

Comments in C++

C++ supports comment format which is indicated by a // sign before the comment. In this case, the
comment can proceed only till the end of current line. In case it is required to extend the comment
beyond the current line, the comments should be preceded by the // symbol on subsequent lines also.

Expressions in C++

Expression can be described as a combination of variables, constants and operators that represents a
computation forms an expression. Depending upon the type of operands involved in an expression or
the result obtained after evaluating expression, there are different categories of an expression.

Input/Output Operator in C++

In C++, input and output (I/O) operators are used to take input and display output. The operator used
for taking the input is known as the extraction or get from operator (>>), while the operator used for
displaying the output is known as the insertion or put to operator (<<).

Operators

Operators act on expressions to form a new expression. For example, we could replace “Hello,
world!\n” with (4 + 2) / 3, which would cause the program to print the number 2. In this case, the +
operator acts on the expressions 4 and 2 (its operands).

Operator types:

1. Mathematical: +, -, *, /, and parentheses have their usual mathematical meanings, including using
-for negation. % (the modulus operator) takes the remainder of two numbers: 6%5 evaluates to 1.
2. Logical: used for “AND,” “OR,” ” NOT, “NOR,” etc.
3. Bitwise: used to manipulate the binary representations of numbers.

Data Types

A data type determines the type and the operations that can be performed on the data. C++ provides
various data types and each data type is represented differently within the computer’s memory.

Type Description Size Range


Names
char Single text character or small integer. 1 byte signed: -128 to 127 unsigned: 0 to
Indicated with single quotes (’a’, ’3’). 255
int Larger integer. 4 signed: -2147483648 to 2147483647
bytes unsigned: 0 to 4294967295
bool Boolean (true/false). Indicated with the 1 byte Just true (1)or false (0).
keywords true and false.
double “Doubly” precise floating point number. 8 +/-1.7e +/-308 ( 15 digits)
bytes
TOKENS

Tokens are the minimal chunk of programs that have meaning to the compiler –the smallest
meaningful symbols in the language. Our code displays all 6 kinds of tokens, though the usual use of
operators is not present here:

Token type Description/Purpose Examples


Keywords Words withspecial meaningto the int, double, for, auto
compiler
Identifiers Names of things that are not built cout,cin, std, x, myFunction
into the language
Literals Basic constant values whose “Hello, world!”, 24.3, 0, ’c’
value is specified directly in the
source code
Operators Mathematical or logical +, -, &&, %, <<
operations
Punctuation/Separators Punctuation defining the {}(),;
structure of a program
Whitespace Spaces of various sorts; ignored Spaces, tabs, newlines, comments
by the compiler

Blog at WordPress.com.

You might also like