(Class 1 - Note 1)
CSC 218
(FOUNDATIONS OF SEQUENTIAL PROGRAMMINING)
1.0 Overview:
This course presents an overview of fundamental principles of programming languages as it
relates to
* how data and instructions are processed in programming languages in view of the
computer architecture.
* It covers aspects on program structures, evolution of programming languages, basic
computer architecture considering data storage and representation, computer instruction
format, operations on data, block structured concept of programming languages, and
specification and translation of programming languages.
1.1 AIM
The aim is to introduces you to the fundamental concepts of computer programs and how
computer systems process such programs ( just like the title implies….. Foundations of
Sequential program.
Another aim of this course is to equip you with the basic knowledge you require to
understand the principles of designing good program structure in computer Programming and
basic computer architecture.
More importantly, this course is a foundational course that will help you in understanding
other higher level courses such as Software Engineering, System Analysis and Design,
Computer Architecture, Survey of Programming Languages, Compiler Techniques and
many others. Your ability to understand the content of this course will help you in these
other courses.
1.1.1 OBJECTIVES
By the end of the unit, you will be able to:
• Understand what programming is all about
• Know the steps to be followed in designing programs
• Describe sequential programming
• Understand the basic structures in which sequential program components are constructed
1.1.2 WHAT IS PROGRAMMING
A program is a set of instructions that a computer follows to perform a specific task.
Programs are created using specific programming languages such as C++, Python, Ruby,
etc. These are high-level programming languages that are human-readable and writable.
A computer program is a collection of instructions that can be executed by a computer to
perform a specific task.
It’s a piece of software designed for a certain use or task eg operating system
2-types (Application software : which fulfills a specific need like MS Word) and ( System
Software which is designed to run the computer hardware and also provide a platform for the
applications to run on top of)
A computer program is usually written by a computer programmer in a programming
language.
Programming is the process or activity of writing computer programs. It involves
instructing computers to perform tasks.
A programming language is a vocabulary and set of grammatical rules for instructing
a computer or computing device to perform specific tasks. The term programming
language usually refers to high-level languages, such as BASIC, C, C+
+, COBOL, Java, FORTRAN, Ada, and Pascal.
Computers don't understand natural language like English. They're instructed in special
computer languages before they can perform any task. The process of developing or writing
the series of sequence of instructions known as programming.
Though computer is viewed as a super machine, it cannot solve any problem that it has not
been directed to solve by humans (Programmers). It is better said that the intelligence of
computer is derived from the intelligence of man (garbage in garbage out).
1.2 PROGRAM DESIGN AND SPECIFICATION
This simply means those program specification and technical information which enables
someone skilled in software design, analysis or programming to maintain, support, and
further develop the program.
Program design is the process of breaking down a complex problem into simpler sub-
problems. It applies to the development or production of computer programs. A basic
knowledge of program design is needed to write programs of reasonable quality.
A program specification is usually part of a system specification, which defines the whole
system. (it’s the definition of what a computer program is expected to do)
The aims of program design are summarized as follows:
i. Reliability: The program can be depended upon always to do what is supposed to do.
ii. Maintainability: The program will be easy to change or modify when the need arises
iii. Readability: The program will be easy for a programmer to read and understand
iv. Performance: The program causes the tasks to be done quickly and efficiently
v. Storage Saving: The program is not allowed to be unnecessarily long to achieve memory
efficiency.
1.2.1 Program Development Life Cycle (PDLC)
When a computer program is to be developed using any programming language, a sequence
of steps is followed. These steps are called phases in program development and should be
carefully follow to develop a successfully computer programs.
The process associated with this computer program development is called program
development life cycle (PDLC). The program development life cycle is a set of steps or
phases that are used to develop a program in any programming language.
PDLC is a systematic way of developing quality software. It provides an organized plan for
breaking down the task of program development into manageable chunks, each of which
must be successfully completed before moving on to the next phase.
Benefits of Pdlc
Provides a structured approach:
PDLC provides a structured approach to developing software, which helps to ensure that the
program is developed in a logical and organized way.
The program development process (cycle) is divided into six (6) steps.
1. Problem Definition
what can it be called
What does it do
What will it do
2. Problem Analysis
Why are we doing it
Why shd we use this instead of this
Why shd it answer this
3. Algorithm Development
So, how do will start
How will it be done
How do we go about it
How do we achieve it
Problem Definition: The first step is to define the problem.: : In this phase, the goals and
objectives of the program are defined, and a plan is developed to achieve them. This
includes identifying the resources required and determining the budget and schedule for the
program.
In this phase, the problem statement is defined and the boundaries of the problem are
decided. (you define the problem statement, the requirements, and the input/output designs).
In major software projects,
(i) System Analyst
(a) It’s a job of the system analyst to define the project problems, and provides the results of
their work to programmers in form of a program specification.
(b) A system analyst discusses the requirements-specification with the users. A requirement
is simply a statement of what the system must do or what characteristics it needs to have.
(c ) The program specification defines the data used in program, the processing that should
take place while finding a solution, the format of the input/output and the user interface.
(ii) The program developers obtains the program requirements from the users and document
the requirements.
(iii) A programmer is usually given specification of what proposed program is required to do.
The programmer then designs and implements the program such that it meets the
specification.
A program that meets its specification is said to be correct. An important factor in
determining program specification is to produce requirements specification.
During a systems development project, requirements will be created that describe what the
business needs (business requirements); what the users need to do (user requirements); what
the software should do ( functional requirements); characteristics the system should have
(nonfunctional requirements); and how the system should be built (system requirements).
Although this list of requirement.
2. Problem Analysis
* programmer‘s review specifications to fully understand what the software should do
* analyze the requirements for the program , including identifying the stakeholders, their
needs and expectations, and determining the functional and non-functional requirements
for the program
3. Algorithm Development
During this phase, a step by step procedure to solve the problem using the specification given
in the previous phase is developed. This phase is very important for program development.
That means we write the solution in step by step statements. Program design starts by
focusing on the main goal that the program is trying to achieve and then breaking the
program into manageable components, each of which contributes to this goal. This approach
of program design is called top-bottom program design or modular programming. The first
step involve identifying main routine, which is the one of program’s major activity. From
that point, programmers try to divide the various components of the main routine into smaller
parts called modules. For each module, programmer draws a conceptual plan using an
appropriate program design tool to visualize how the module will do its assign job.
The various program design tools are described below:
i. ) Algorithms An algorithm is a step-by-step description/procedure to solve a problem. in
the easiest way. Algorithms are not restricted to computer world alone, we use them in our
everyday life.
Its easy to debug, plain-text like, its complex to understand, difficult to construct, does not
follow any rules and its the pseudo-code for the program.
Ii). Decision tables A Decision table is a special kind of table, which is divided into four
parts by a pair of horizontal and vertical lines.
Iii. . Flowcharts A flowchart is a diagram that shows the logic of the program.
iv. Pseudo-code A pseudo-code is another tool to describe the way to arrive at a solution.
They are different from algorithm by the fact that they are expressed in program language
like constructs.
4. Coding and Documentation
In this phase, we construct the actual program. That means we write the program to solve the
given problem using programming languages like C, C++, Java, etc., Coding the program
means translating an algorithm into specific programming language. The technique of
programming using only well-defined control structures is known as Structured
programming. Programmer must follow the language rules, violation of any rule causes error.
These errors must be eliminated before going to the next step.
5. Testing and Debugging
During this phase, there is need to check or test whether
* the written code is solving the specified problem (like various input data values) or not.
* also test whether it is providing the desired output or not.
However, after removal of syntax errors and the output of the program is not being correct (
program did not execute), its as a result of logical error in the program. A logical error is a
mistake that the programmer made while designing the solution to a problem. So the
programmer must find and correct logical errors by carefully examining the program output
using Test data.
Syntax error and Logical error are collectively known as Bugs. The process of identifying
errors and eliminating them is known as Debugging.
6. Maintenance
After testing, the software project is almost complete. The structure charts, pseudo-codes,
flowcharts and decision tables developed during the design phase become documentation for
others who are associated with the software project. This phase ends by writing a manual that
provides an overview of the program’s functionality, tutorials for the beginner, in-depth
explanations of major program features, reference documentation of all program commands
and a thorough description of the error messages generated by the program.
The program is actively used by the users. If there is need for any enhancements, all the
phases are to be repeated to make the enhancements. That means in this phase, the solution
(program) is used by the end-user. The program is deployed (installed) at the user’s site. Here
also, the program is kept under watch till the user gives a green signal to it.
Even after the software is completed, it needs to be maintained and evaluated regularly. In
software maintenance, the programming team fixes program errors and updates the software.
1.3 The sequential structure in a program refers to
Following a clear order of instructions.
Executing instructions in the order they are presented.
Achieving step-by-step processing.
Using control flow structures to control the sequence of instructions.
In computer programming, a sequential program structure refers to the line-by-line
execution of statements in the same order they appear in the program. Essentially, it’s like
following a recipe step by step. Each action or operation is carried out one after another,
without any branching or decision-making.
writing data, or assigning values to variables. These straightforward sequences form the
building blocks for more complex software.
Computers and Micro Processors
In simple words, a Microprocessor is a digital device (brain of a computer) on a chip that
can fetch instructions from memory, decode and execute them and give results.
Based on the number of microprocessors, computers can be classified into:
(a) Sequential computers and
(b) Parallel computers.
*** Any task complete in sequential computers is with one microcomputer
only. Most of the computers we see today are sequential computers where any task is
completed sequentially, instruction after instruction, from the beginning to the end.
***The parallel computer is relatively fast. New types of computers that use a large number
of processors. The processors perform different tasks independently and simultaneously thus
improving the speed of execution of complex programs dramatically. Parallel computers
match the speed of supercomputers at a
fraction of the cost.
,,,more insight
Sequential computing refers to a traditional method where instructions are executed one
after the other, in a sequence. Some examples of sequential circuits and their applications:
Flip-Flops: These are basic building blocks used for storing binary information. They can be
either D flip-flops, JK flip-flops, or T flip-flops. Flip-flops are widely used in digital systems
for memory storage and synchronization.
Registers: Registers are small, fast storage elements within a processor. They temporarily
hold data during arithmetic and logical operations. For instance, the program counter (PC)
in a CPU is a type of register.
Counters: Counters are sequential circuits that increment or decrement a value based on
clock pulses. They find applications in tasks like counting events, generating timing signals,
or implementing finite state machines.
Shift Registers: These circuits allow data to be shifted in or out serially. They are used for
tasks like data serialization, parallel-to-serial conversion, and vice versa.
Analog-to-Digital Converters (ADCs): ADCs convert continuous analog signals (e.g., from
sensors) into digital values. The conversion process involves sequential steps, making them
sequential circuits.
Digital-to-Analog Converters (DACs): DACs perform the reverse operation, converting
digital values to analog signals. Like ADCs, they involve sequential processing.
Clocks: Clocks generate regular pulses (clock cycles) that synchronize various components
in a digital system. They ensure sequential execution of instructions.
These examples demonstrate how sequential circuits play a crucial role in digital systems,
even though parallel computing has gained prominence due to its efficiency and performance
advantages
…parallel computing is a powerful architecture that divides a problem into smaller tasks and
processes them concurrently. Here are some examples of its practical applications:
Supercomputers in Astronomy: Astronomers use supercomputers with parallel processing
capabilities to analyze vast amounts of data from telescopes and other instruments. These
supercomputers simulate celestial bodies, study dark matter, and search for exoplanets.
Agricultural Predictions
Parallel computing helps analyze weather data, soil conditions, and other factors to make
informed decisions in agriculture.
By processing data quickly, supercomputers can predict optimal planting times for specific
crops based on thousands of weather stations, satellite images, and soil samples.
Video Post-Production Effects:
In video post-production, tasks like 3D animation, color grading, and visual effects demand
substantial computational power.
Parallel computing accelerates these processes, allowing for efficient rendering and high-
quality effects in movies, TV shows, and animations.
Parallel computing significantly speeds up complex computations, making it essential for
various fields!
ERROR LANGUAGES: SYNTAX ANS SEMANTICS
In learning a programming language, there is need to learn about two important
aspects of the language:
(a) its syntax: The syntax of a language is the grammatical rules that govern the ways in
which words, symbols, expressions and statements may be formed and combined.
In other words, Syntax refers to the rules and regulations for writing statements in a
programming language (e.g., C++, Java, Python).
Nature: Syntax errors occur when a statement violates the grammar or structure of the
language.
Detection Time: These errors are detected during compilation.
Examples:
o Missing semicolons in C++.
o Using undeclared variables in Java.
o Incorrect indentation in Python.
Output: The program fails to compile due to syntax errors.
(b) Semantics: The semantics of a language are the rules that govern its meaning. In the case
of computer language, meaning is defined in terms of what happens when the program is
executed
Semantics refers to the meaning associated with a statement in a programming language.
Nature: Semantic errors occur when a statement is syntactically valid but does not behave as
intended.
Detection Time: These errors are encountered at runtime.
Examples:
o Writing a return statement before printing anything (e.g., in C++ or Java).
o Incorrectly calculating results.
In summary, Syntax refers to what is valid for a program to run (or compile), while
semantic is about the meaning or logic. . syntax errors relate to the structure of code, while
semantic errors involve incorrect program behavior. While syntax errors are caught during
compilation, semantic errors can be more challenging to identify and debug at runtime
COMMON FEATURES OF COMPUTER AND PROGRAMMING LANGUAGE
The main features of the computer are still visible in features of the programming language.
These features are storage, input and output, operation on data, and control.
1.3.1 STORAGE
Computers require a set of instructions and data to be stored in their memory to perform a
specific task. This stored program concept was originated ever since the invention of Charles
Babbage’s difference engine in 1822.
Identifiers
In programming languages, data are identified by name rather than by their location-address
in main-storage.
** The names that associate stored data values are called identifiers because an identifier is
the name by which the data value may be identified.
An identifier is a constant if it is always associated with the same data value and it is a
variable if its associated data value is allowed to change. Changing a variable’s value
implies changing what is stored.
Literal
When using names in programs, care must be taken to specify whether the names are literals
or identifiers. When names or letters are used literally they are called literals, and they are
distinguished from identifiers by placing them within quotation marks. So the instruction:
PRINT “N” means print the letter N, and the instruction
PRINT N means print the value associated with N.
1.3.2 DATA DECLARATION
In programming, we often need a named storage location to store the data or values. Using
variables, we can store data in our program and access it afterward. In this article, we will
learn about variables in programming, their types, declaration...
In programming, a variable is an abstract storage location paired with an associated
symbolic name. It holds a value or data that can change during program
execution. Essentially, a variable acts as a named container for a specific type of data, such
as integers, floats, or strings. Here are some key points about variables:
Declaration of Variables:
Before using a variable, its type and name must be declared. For example:
#include <iostream>
using namespace std;
int main()
{
// Syntax: datatype variable_name;
int age;
double price;
char grade;
return 0;
}
int age; // Declaration of an integer variable
double price; // Declaration of a double variable
char grade; // Declaration of a character variable
The syntax may vary slightly across programming languages, but the concept remains consistent.
Initialization of Variables:
After declaring a variable, initial value can be assigned to it.
For instance: int age = 25;
double price = 10.99;
char grade = 'A';
Variable is a symbolic name assigned to a data item by the programmer. At any particular
time, a variable will stand for one particular data, called the value of a variable, which may
change from time to time during a computing process. The value of a variable may change
many times during the execution of a program. A variable is usually given a name by the
programmer.
The variable must be declared, that is to state its data type and its Value.
A data type is a classification of data, which can store a specific type of information. Usually
include integer, real, boolean, and character or string.
They are primarily used in computer programming in which variables are created to store
data. The act of defining a variable is called data declaration. Declarations provide
information about the name and type of data objects needed during program execution. Every
language supports a set of primitive data types.
There are two types of declaration, (a) implicit declaration and (b) explicit declaration.
(a) Implicit declaration or default declaration are those declaration which is done by compiler
when no explicit declaration or user defined declaration is mentioned. Simply put, Implicit
declaration happens when the compiler determines the type of the variable.
For example in 'Perl' compiler , implicitly understands that:
$abc ='astring' is a string variable and
$abc=7; is an integer variable.
(b) In explicit declaration, user explicitly defines the variable type. For example: Float A, B;
In this example it specifies that it is of float type variable which has name A & B.
· Explicit declaration just means adding the data type before the name of the variable.
Example: int myAge = 10
1.3.3 INPUT AND OUTPUT
Programming languages have special functions for dealing with input and output.
Common names for these functions are input, read, get, accept, output, write, print, put and
display. This is illustrated using the following simple Java program:
ComputeArea.java
1 public class ComputeArea {
2 public static void main (String[] args) {
3 double radius; // Declare radius
4 double area; // Declare area
5
6 // Assign a radius
7 radius = 20; // New value is radius
8
9 // Compute area
10 area = radius * radius * 3.14159;
11
12 // Display results
13 System.out.println("The area for the circle of radius " +
14 radius + " is " + area);
15 }
16 }
Variables such as radius and area correspond to memory locations. Every variable has a
name, a type, a size, and a value.
Line 3 declares that radius can store a double value. The value is not defined until a value is
assigned. Line 7 assigns 20 into radius. Similarly, line 4 declares variable area, and line 10
assigns a value into area.
Java uses System.out to refer to the standard output device and System.in to the standard
input device. By default the output device is the display monitor, and the input device is the
keyboard.
To perform console output, you simply use the println method to display a primitive value or
a string to the console.
1.3.4 OPERATIONS ON DATA
Operations are applied to data items of various types Operations are expressed in the form of
statements. The simplest statement is the assignment statement.
Operators in programming are essential symbols that perform operations on variables and
values, enabling tasks like arithmetic calculations, logical comparisons, and bitwise
manipulations.
What are Operators in Programming?
Operators in programming are symbols or keywords that represent computations or actions
performed on operands. Operands can be variables, constants, or values, and the combination
of operators and operands form expressions. Operators play a crucial r..
In programming, operators are essential symbols that perform various tasks
on operands (which can be variables, constants, or values). Some common types of
operators are:
Arithmetic Operators:
1. + (Addition): Adds two values.
2. - (Subtraction): Subtracts the right operand from the left.
3. * (Multiplication): Multiplies two values.
4. / (Division): Divides the left operand by the right.
5. % (Modulus): Returns the remainder of division.
2.
Unary Operators:
1. ++ (Increment): Increases the value of a variable by 1.
2. -- (Decrement): Decreases the value of a variable by 1.
AssignmeOperators:
1. =: Assigns a value to a variable.
2. +=, -=: Add or subtract and assign.
3. *=, /=: Multiply or divide and assign.
4. %=: Compute modulus and assign.
Relational Operators:
1. == (Equal to)
2. != (Not equal to)
3. < (Less than)
4. > (Greater than)
5. <= (Less than or equal to)
6. >= (Greater than or equal to)
Logical Operators:
1. && (Logical AND)
2. || (Logical OR)
3. ! (Logical NOT)
Bitwise Operators:
1. & (Bitwise AND)
2. | (Bitwise OR)
3. ^ (Bitwise XOR)
4. ~ (Bitwise NOT)
5. << (Left shift)
6. >> (Right shift)
Conditional Operator (Ternary):
1. ? : (Conditional expression)
These operators allow you to manipulate data, perform calculations, and make decisions
within your programs.
BASICS OF MICROPROCESSOR –
A Microprocessor takes a bunch of instructions in machine language and executes them,
telling the processor what it has to do. Microprocessor performs three basic things while
executing the instruction:
1. It performs some basic operations like addition, subtraction, multiplication, division, and
some logical operations using its Arithmetic and Logical Unit (ALU). New
Microprocessors also perform operations on floating-point numbers also.
2. Data in microprocessors can move from one location to another.
3. It has a Program Counter (PC) register that stores the address of the next instruction based
on the value of the PC, Microprocessor jumps from one location to another and takes
decisions.
See Introduction to MicroProcessor***