COMPUTER PROGRAM DEVELOPMENT-NOTES
COMPUTER PROGRAM DEVELOPMENT-NOTES
Program-A computer program is a set of coded instructions given to the computer and
represents a logical solution to a problem. It directs a computer in performing various
operations/tasks on the data supplied to it.
Computer programs may be written by the hardware manufacturers, Software houses, or a
programmer to solve user problems on the computer.
Programming is the process of designing a set of instructions (computer programs) that can be
used to perform a particular task or solve a specific problem.
It involves the use of special characters, signs, and symbols found in a particular programming
language to create computer instructions.
The programming process is quite extensive. It includes analyzing an application, designing a
solution, coding for the processor, testing to produce an operating program, and developing other
procedures to make the system function.
The program created must specify in detail the logical steps to be taken & the method of
processing the data input into the computer to carry out the specified task.
A computer program performs the following:
Source program (source code)-Refers to the program statements that the programmer enters in
the program editor window, and which have not yet been translated into machine-readable form.
Source code is the code understood by the programmer and is usually written in a high-level
language or Assembly language.
Object code (object program)- Refers to the program code that is in machine-readable (binary)
form.
Object code is the code the computer can understand and is produced by a Compiler or
Assembler after translating the Source program into a form that can be readily loaded into the
computer.
Language translators
A computer uses & stores information in binary form, and therefore, it cannot understand
programs written in either high-level or assembly languages. This means that any
program code written in Assembly language or high-level language must be translated
into Machine language before the computer can recognize & run these programs.
A Translator is special system software used to convert the Source codes (program
statements written in any of the computer programming languages) to their Object codes
(computer language equivalents).
The Translators reside in the main memory of the computer, and use the program code of
the high-level or Assembly language as input data, change the codes, and gives the output
program in machine-readable code.
Also, translators check for & identify some types of errors that may be present in the
program being translated, e.g., Syntax/grammatical errors. They will produce error
messages if there is a mistake in the code.
Types of language translators
i. Assembler
An Assembler translates programs written in Assembly language into machine
language that the computer can understand and execute.
Functions of an Assembler.
It checks whether the instructions are written are valid, and identifies any
errors in the program.
The Assembler will display these errors as well as the complete source and object
programs. If the program has no errors, the job control will let it run immediately,
or save the object program so that it may run it later without translating it again.
It assigns memory locations to the names the programmer uses.
E.g., the Assembler keeps a table of these names so that if an instruction refers to
it, the Assembler can easily tell the location to which it was assigned.
It generates the machine code equivalent to the Assembly instructions.
Usually, the Assembler generates a machine code only when no errors are
detected. Some of the errors include;
- Typing mistakes.
- Using the wrong format for instruction.
- Specifying a memory location outside the range 0 – 2047.
ii. Interpreter
An interpreter is a common kind of language processor. Instead of
producing the target program as a translation, an interpreter appears to
directly execute the operations specified in the source program on inputs
supplied by the user.
In contrast, an interpreter reads a statement from the input, converts it to
an intermediate code, executes it, then takes the next statement in
sequence.
If an error occurs, an interpreter stops execution and reports it.
iii. Compiler
A compiler translates the entire/whole source program into object code at once
and then executes it in machine language code. These machine code instructions
can then be run on the computer to perform the particular task as specified in the
high-level program.
Figure 1 compiler
The process of translating a program written in a high-level source language into machine
language using a compiler is called Compilation.
For a given machine, each language requires its Compiler. E.g., for a computer to be able
to translate a program written in FORTRAN into machine language; the program must
pass through the FORTRAN compiler (which must ‘know’ FORTRAN as well as the
Machine language of the computer).
Functions of a compiler.
A Compiler performs the following tasks during the compilation process:
It identifies the proper order of processing, to execute the process as fast as
possible & minimize the storage space required in memory.
It allocates space in memory for the storage locations defined in the program to be
executed.
It reads each line of the source program & converts it into machine language.
It checks for Syntax errors in a program (i.e., statements which do not conform
to the grammatical rules of the language). If there are no syntax errors, it
generates machine code equivalent to the given program.
i. Linker
The linker is a computer program that links and merges various object files to make
an executable file. All these files might have been compiled by the separate
assembler.
ii. Loader
The loader is a part of the operating system and is responsible for loading executable
files into memory and execute them.
It calculates the size of a program (instructions and data) and creates memory space
for it. It initializes various registers to initiate execution.
Programming approaches
Procedural
Event-driven
Object-oriented
Internet-based
i. Procedural Programming
Problem is broken down into procedures, or blocks of code that perform one task each. All
procedures taken together form the whole program. It is suitable only for small programs that
have a low level of complexity.
Example − For a calculator program that does addition, subtraction, multiplication, division,
square root and comparison, each of these operations can be developed as separate procedures.
In the main program, each procedure would be invoked based on the user’s choice.
ii. Object-oriented Programming
Here the solution revolves around entities or objects that are part of the problem. The solution
deals with how to store data related to the entities, how the entities behave and how they interact
with each other to give a cohesive solution.
Example − If we have to develop a payroll management system, we will have entities like
employees, salary structure, leave rules, etc. around which the solution must be built.
i. Event-Driven programming
Event-driven programming depends upon an event loop that is always listening for the new
incoming events. The working of event-driven programming is dependent upon events. Once
event loops, then events decide what to execute and in what order. –
Figure 2 Event-driven programming
The internet-based programming approach is also called web programming. web programming is
a set of web site development activities in WWW (World Wide Web) based on the public
network Internet. In the simplest case, each web site includes static web pages, but usually is an
aggregation of static and dynamic web pages. The later ones link under certain rules data sources
(structured and non-structured DB) and program codes (scripts), realizing some functionality.
This combination of web pages, scripts, and DB is called a web application. The web
applications are distributed (on one or more servers), working under HTTP, and available by a
browser or non-browser client application serving as a network interface. In detail, web
programming refers to writing, markup, and coding, involved in Web site building (known as
web development), which includes web content, web client and server scripting, and network
security.
ABC organization has recently employed you as a program developer expert. In preparation to
develop a program to run some operations in the company, the manager in consultation with
other ICT experts has requested you to lead a team in coming up with a detailed presentation on
some of the existing programming approaches that can be utilized.
Special instructions;
a. Using your computer, make a detailed PowerPoint presentation on the following
programming approaches
i. Procedural
ii. Event-driven
iii. Object-oriented
iv. Internet-based
b. Burn your presentation in a CD to be submitted to when required.
6.2.1.5 Self-Assessment
1. What is the meaning of the following terms:
i. Computer program.
ii. Programming.
iii. Programming language.
2. Regarding programming, distinguish between Source program and Object code.
3. What are the function(s) of Assemblers, Interpreters, and Compilers in a computer
system?
4. What is the difference between a Compiler and an Interpreter?
6.2.1.7 References
Blignaut, A. S., Hinostroza, J. E., Els, C. J., & Brun, M. (2010). ICT in education policy
and practice in developing countries: South Africa and Chile compared through SITES
2006. Computers & Education, 55(4), 1552–1563.
Nagar, T. (2019, December 3). What is software and types of software with examples?
YourStory.Com. https://yourstory.com/mystory/what-software-types-examples
Functions of a compiler
It identifies the proper order of processing, to execute the process as fast as
possible & minimize the storage space required in memory.
It allocates space in memory for the storage locations defined in the program to
be executed.
It reads each line of the source program & converts it into machine language.
It checks for Syntax errors in a program (i.e., statements which do not conform to
the grammatical rules of the language). If there are no syntax errors, it generates
machine code equivalent to the given program.
It combines the program (machine) code generated with the appropriate
subroutines from the library.
It produces a listing of the program, indicating errors if any.
Processing that must take place to convert input data into output information must
correspond with the problem definition determined in task 1.
A step-by-step logical algorithm must be determined to process the input data to output
information.
Document the program objectives, desired outputs, needed inputs, and required processing.
After these items are documented, then step 2, program design can commence.
Agile
Crystal
Rapid Application Development
Agile
https://youtu.be/rvTejAg_fbY
Crystal method
Crystal family is a collection of agile software development methodologies that can be used for
different software projects depending upon size, complexity, criticality, and the number of
people involved. It was developed by Alistair Cockburn in early 1990 while working at IBM. He
interviewed different teams working on different projects to find the best practices followed by
teams. He found that these teams did not follow the formal methodologies or not using specific
technology for delivering successful software. However, they communicated frequently to
discuss the project. On the other hand, delayed or failed project teams tried to follow formal
methods with little team collaboration. This helped him to conclude that frequent communication
among team members can improve the software success rate. According to Cockburn’s
philosophy “To the extent that you can replace the written documentation with face to face
interaction, you can reduce the reliance on written ‘promissory’ notes and improve the likelihood
of delivering the system. Crystal methods focus on people and communication among people
rather than a process to frequently deliver working software.
-The program development life cycle is a set of steps or phases that are used to develop a
program in any programming language. Generally, the program development life cycle contains
7 phases, they are as follows
i. Problem Definition
ii. Program Design
iii. Coding
iv. Debugging
v. Testing
vi. Documentation
vii. Maintenance
1. Problem Definition
2. Program Design
3. Coding
4. Debugging
5. Testing
6. Documentation
7. Maintenance
Figure 3 program development life cycle(PDLC)
i. Problem Definition:
The first step in the process of program development is the thorough understanding and
identification of the problem for which is the program or software is to be developed.
In this step, the problem has to be defined formally.
All the factors like Input/output, processing requirement, memory requirements, error
handling, interfacing with other programs have to be taken into consideration in this
stage.
The next stage is the program design. The software developer makes use of tools like
algorithms and flowcharts to develop the design of the program.
o Algorithm
o Flowchart
iii. Coding:
Once the design process is complete, the actual computer program is written, i.e. the
instructions are written in a computer language.
Coding is generally a very small part of the entire program development process and also
a less time-consuming activity in reality.
In this process all the syntax errors i.e. errors related to spelling, missing commas,
undefined labels etc. are eliminated.
For effective coding some of the guidelines which are applied are :
o Use of meaningful names and labels of variables,
o Simple and clear expressions,
o Modularity with emphasis on making modules generalized,
o Making use of comments and indenting the code properly,
o Avoiding jumps in the program to transfer control.
iv. Debugging:
At this stage, the errors in the programs are detected and corrected.
This stage of program development is an important process. Debugging is also known as
program validation.
Some common errors which might occur in the programs include:
o Un initialization of variables.
o Reversing of an order of operands.
o Confusion of numbers and characters.
o Inverting of conditions eg jumping on zero instead of on not zero.
v. Testing:
vi. Documentation:
This ensures that future modifications if required can be done easily. Also, it is required during
redesigning and maintenance.
vii. Maintenance:
Updating and correction of the program for changed conditions and field experience are
accounted for in maintenance.
Maintenance becomes essential in the following situations:
o Change in the specification,
o Change in equipment,
o Errors are found during the actual execution of the program.
Styles of programing
Types of styles programing
Functional Programming
Object-Oriented Programming
Modular programming
Functional Programming
Here the problem, or the desired solution, is broken down into functional units. Each unit
performs its task and is self-sufficient. These units are then stitched together to form the
complete solution.
Example − A payroll processing can have functional units like employee data maintenance,
basic salary calculation, gross salary calculation, leave processing, loan repayment
processing, etc.
Object-Oriented Programming
Here the solution revolves around entities or objects that are part of the problem. The
solution deals with how to store data related to the entities, how the entities behave, and how
they interact with each other to give a cohesive solution.
Example − If we have to develop a payroll management system, we will have entities like
employees, salary structure, leave rules, etc. around which the solution must be built.
Modular progrmming
Modular programming is a software design technique that emphasizes separating the
functionality of a program into independent, interchangeable modules, such that each
contains everything necessary to execute only one aspect of the desired functionality.
special instructions
6.2.2.5 Self-Assessment
-You are provided with the following questions for self -assessment, attempt them and check
your responses
1. What is PDLC?
2. Which are the Three major program development approaches used in PDLC?
3. What is the difference between Functional programming and Modular Programming?
4. Why is the Design phase important in Program Development Life Cycle?
5. Which are the five common errors that can occur in a program during program
development?
Lehmann, S., & Schweitzer, B. (2006). Apparatus, system, and method for creating
customized workflow documentation (United States Patent No. US20060059423A1).
Nagar, T. (2019, December 3). What is software and types of software with
examples? YourStory.Com. https://yourstory.com/mystory/what-software-types-
examples
1. What is PDLC?
-PDLC is an abbreviation of Program Development Life Cycle. It is a set of steps or
phases that are used to develop a program in any programming language.
2. Which are the Three major program development approaches used in PDLC
i. Agile
ii. Crystal method
iii. Rapid Application Development
3. What is the difference between Functional programming and Modular Programming
-In functional programming, the problem is broken down into functional units where
each unit performs its task and is self-sufficient. These units are then stitched together to
form the complete solution while in modular programming the functionality of a program
is separated into independent, interchangeable modules, such that each contains
everything necessary to execute only one aspect of the desired functionality.
Un initialization of variables.
Reversing of an order of operands.
Confusion of numbers and characters.
Inverting of conditions e.g. jumping on zero instead of on not zero.
6.2.3 Learning Outcome 3: Identify Program design
6.2.3.1 Introduction to the learning outcome
This learning outcome specifies the content of competencies required to design a
computer program. It entails the description of Program design, various approaches for
designing a program, and Program design tools.
Program design
The program design is the process that an organization uses to develop a program. It is most
often an iterative process involving research, consultation, initial design, testing, and redesign. A
program design is the plan of action that results from that process.
https://youtu.be/aXPIxUafbM8
Top – Down
Bottom-Up
Data-Driven
Top-Down Design Model:
Top-down programming starts by implementing the most general modules and works
toward implementing those that provide specific functionality. In the top-down model, an
overview of the system is formulated without going into detail for any part of it. Each part of it
then refined into more details, defining it in yet more details until the entire specification is
detailed enough to validate the model. if we glance at a haul as a full, it’s going to appear not
possible as a result of it’s so complicated For example: Writing a University system program,
writing a word processor. Complicated issues may be resolved victimization high down style,
conjointly referred to as Stepwise refinement where,
1. We break the problem into parts,
2. Then break the parts into parts soon and now each of the parts will be easy to do.
Bottom-Up Design Model:
In this design, individual parts of the system are specified in detail. The parts
are linked to form larger components, which are in turn linked until a complete system is
formed. Bottom-up programming implements the modules that provide specific
functionality first and then integrates them by implementing the more general modules
Data-driven approach
When doing data-driven programming, one clearly distinguishes code from the data structures
on which it acts and designs both so that one can make changes to the logic of the program by
editing not the code but the data structure.
Data-driven programming is sometimes confused with object-orientation, another style in
which data organization is supposed to be central. There are at least two differences. One is that
in data-driven programming, the data is not merely the state of some object, but defines the
control flow of the program. Where the primary concern in OO is encapsulation, the primary
concern in data-driven programming is writing as little fixed code as possible. Unix has a
stronger tradition of data-driven programming than OO.
Programming data-driven style is also sometimes confused with writing state machines. It
is, in fact, possible to express the logic of a state machine as a table or data structure, but hand-
coded state machines are usually rigid blocks of code that are far harder to modify than a table.
An important rule when doing any kind of code generation or data-driven programming is this:
always push problems upstream. Don't hack the generated code or any intermediate
representations by hand — instead, think of a way to improve or replace your translation tool.
Otherwise, you're likely to find that hand-patching bits that should have been generated correctly
by the machine will have turned into an infinite time sink.
I. Algorithm
Characteristics of an Algorithm
Example of an algorithm
II. Flowchart
A rectangle represents a
process process
A diamond indicates a
Decision decision
Advantages
The flowchart helps programmers to explain the logic of a program to others easily.
The flowchart provides documentation support.
A flowchart helps detect and remove bugs in a program in s systematic manner.
With the reference of the Flowchart, the programmer can write a program and correspond
to the program.
Disadvantages
These are structured English-like phrases that indicate the program steps to be followed to solve
a given problem.
The term “Code” usually refers to a computer program. This implies that, some of the words
used in pseudocode may be drawn from a certain programming language and then mixed with
English to form structured statements that are easily understood by non-programmers, and also
make a lot of sense to programmers. However, pseudocodes are not executable by a computer.
Decision Tables
A Decision table represents conditions and the respective actions to be taken to address
them, in a structured tabular format.
It is a powerful tool to debug and prevent errors. It helps group similar information into a
single table and then by combining tables it delivers easy and convenient decision-
making.
Creating a Decision Table
To create the decision table, the developer must follow the basic four steps:
Lehmann, S., & Schweitzer, B. (2006). Apparatus, system, and method for creating
customized workflow documentation (United States Patent No. US20060059423A1).
Nagar, T. (2019, December 3). What is software and types of software with examples?
YourStory.Com. https://yourstory.com/mystory/what-software-types-examples
5.Write a structured algorithm that would prompt the user to enter the Length and
Width of a rectangle, calculate the Area and Perimeter, then display the result.
Programming Languages
A programming language is a set of words, symbols, and codes that enables a programmer to
communicate a solution algorithm to the computer. Just as humans understand a variety of
spoken languages (English, Spanish, French, and so on), computers recognize a variety of
programming languages.
Each programming language has its own grammatical (syntax) rules, which must be obeyed in
order to write valid programs, just as a natural language has its own rules for forming sentences.
I. Low-level languages
These are the basic programming languages, which can easily be understood by the computer
directly, or which require little effort to be translated into computer understandable form.
They include:
Machine languages.
Assembly languages.
-Machine language is written using machine codes (binary digits) that consist of 0’s & 1’s.
The computer can readily understand Machine code instructions without any translation.
A programmer is required to write his program in strings of 0’s & 1’s, calculate & allocate the
Assembly languages were developed to speed up programming (i.e., to overcome the difficulties
of understanding and using machine languages).
The vocabulary of Assembly languages is close to that of machine language, and its instructions
are symbolic representations of the machine language instructions.
Assembly language programs are easier to understand, use & modify compared to
Machine language programs.
To write program statements in Assembly language, the programmer uses a set of predefined
symbols (operation codes) called Mnemonic codes.
Very few computer programs are written in a machine or Assembly language because of
the following reasons;
Low-level languages are difficult to learn, understand, and write programs in them.
Low-level language programs are difficult to debug (remove errors from).
The programs are very long; hence, writing a program in a low-level language is usually
tedious & time-consuming.
The programs are difficult to develop, maintain, and are also prone to errors (i.e., it
requires highly trained experts to develop and maintain the programs).
Low-level languages are machine-dependent (specific), hence non-portable. This implies
that they are designed for a specific machine & specific processor, and therefore, cannot
be transferred between machines with different hardware specifications.
The grammar of High-level languages is very close to the vocabulary of the natural
languages used by human beings. Hence; they can be read and understood easily even by
people who are not experts in programming.
Most high-level languages are general-purpose & problem-oriented. They allow the
programmer to concentrate on the functional details of a program rather than the details
of the hardware on which the program will run.
High-level languages are not machine-oriented; hence, they do not use the CPU
and
hardware facilities efficiently.
The languages are machine-independent and cannot be used in programming the
hardware directly.
Each high-level language statement converts into several machine code
instructions. This
means that, they use more storage space, and it also takes more time to run the
program.
Their program statements are too general; hence, they execute slowly than their
machine code program equivalents.
They have to be interpreted or compiled to machine-readable form before the
computer can execute them.
The languages cannot be used on very small computers.
The source program written in a high-level language needs a Compiler, which is
loaded into the main memory of the computer, and thus occupies much of
memory space. This greatly reduces the memory available for a source program.
Flowcharts.
A Flowchart is a diagram that demonstrates the logical sequence of events that must be
performed to solve a problem.
It is a diagrammatic or pictorial representation of a program’s algorithm.
Types of Flowcharts.
There are 2 common types of Flowcharts:
1). System flowchart.
A System flowchart is a graphical model that illustrates each basic step of a data
processing system.
-It illustrates (in summary) the sequence of events in a system, showing the
department or function responsible for each event.
2). Program flowchart.
This is a diagram that describes, in sequence, all the operations required to process
data in a computer program.
-A program flowchart graphically represents the types of instructions contained in a
computer program as well as their sequence & logic.
Data flow diagrams visually represent systems and processes that would be hard to
describe in a chunk of text. You can use these diagrams to map out an existing system
and make it better or to plan out a new system for implementation. Visualizing each
element makes it easy to identify inefficiencies and produce the best possible system.
i. You need to calculate the area of the rectangle using its length and width. Draw a
flowchart and write pseudocode that will accept the length and width and
calculate and print the area of the rectangle. (area = length width)
ii. Net salaries of employees are paid after the calculation of their deductions and
allowances. The following rates are used for calculating these allowances and
deductions. Allowances Deductions HRA 15% of Basic SS 7% of Basic DA
10% of Basic Levy 1% of Basic EA 5% of Basic TA 12% of Basic To calculate
the Gross salary the following formulas are used: Gross salary = Basic salary+
allowances Net salary = Gross salary - deductions Write pseudocode that will
prompt the user to enter the name and basic salary of an employee and output
their name, basic salary, allowances, deductions, gross salary and net salary with
appropriate labels.
6.2.4.5 Self-Assessment
You are provided with the following questions for self -assessment, attempt them
and check your responses.
a. What is a Programming language?
b. What is meant by ‘Machine language’?
c. Show the difference between Machine language and Assembly language.
d. Give two advantages & three disadvantages of Machine language
programming.
e. Give the features/characteristics of high-level programming languages.
f. List 8 factors that need to be considered when selecting a programming
language.
g. Write pseudocode that will accept 25 integers and displays the number of
positive and negative numbers.
h. Write a pseudocode algorithm that will create a conversion table to
convert degrees Celsius to degree Fahrenheit. Prompt the user to enter the
temperature in degree Celsius and display the temperature in Fahrenheit.
(Fahrenheit = 32+ (9Celcius/5)
6.2.4.6 Tools, Equipment, Supplies, and Materials
Flow charts
Data flow diagram
Decision table
Decision tree
Web Authoring tools
Notepad
Computer
Software
Digital instructional material including DVDs and CDs
6.2.4.7 References
Blignaut, A. S., Hinostroza, J. E., Els, C. J., & Brun, M. (2010). ICT in education policy
and practice in developing countries: South Africa and Chile compared through SITES
2006. Computers & Education, 55(4), 1552–1563.
Lehmann, S., & Schweitzer, B. (2006). Apparatus, system, and method for creating
customized workflow documentation (United States Patent No. US20060059423A1).
Nagar, T. (2019, December 3). What is software and types of software with examples?
YourStory.Com. https://yourstory.com/mystory/what-software-types-examples
g. Write a pseudocode algorithm that will create a conversion table to convert degrees
Celsius to degree Fahrenheit. Prompt the user to enter the temperature in degree Celsius
and display the temperature in Fahrenheit. (Fahrenheit = 32+ (9Celcius/5)
solution
Step 1: start
Step 2: write “Enter the temperature in degrees Celcius.”
Step 3: read Celsius
Step 4: Fahrenheit =32 + (9 celcius/5)
Step 5: write “The temperature in Fahrenheit is:”
Step 6: write Fahrenheit
Step 7: stop
6.2.5 Learning Outcome 5: Perform Basic Structured programming using C language.
6.2.5.1 Introduction to the learning outcome
This learning outcome specifies the content of competencies required to design a
computer program. It entails information fundamentals of C programming, Control structures in
C programming, Subprograms of C language, C language concepts, C programming
environment, description of sub programming, C program format.
C Programming Language
History of C language: -
C language has evolved from three different structured language ALGOL, BCPL, and B
Language. It uses many concepts from these languages while introduced many new concepts
such as datatypes, struct, pointer, etc. In 1988, the language was formalized by the American
National Standard Institute (ANSI). In 1990, a version of the C language was approved by
the International Standard Organisation (ISO) and that version of C is also referred to as
C89.
The idea behind creating C language was to create an easy language that requires a simple
compiler and enables programmers to efficiently interact with the machine/system, just like
machine instructions.
Characteristics of C language
C is a powerful, flexible language that provides fast program execution.
C is a Procedural Language i.e. the programmer is required to provide step-by-step
Low Level features: C's power and fast program execution come from its ability to
access low-level commands, similar to assembly language, but with high-level syntax.
Portability: C programs are portable i.e. they can run on any compiler with little or no
modification. Compiler and Preprocessor make it possible for the C program to run it on
different PC.
Bit Manipulation: C Programs can be manipulated using bits and it provides wide
Efficient Usage of Pointers: C supports the efficient use of pointers and pointers have
direct memory access.
Structure of a C program
Preprocessor directives
Global declarations
Main()
{
Local declaration Statements
}
Function 1()
{
Local declaration statements
}
Function n()
{
Local declaration statements
}
Local declaration statements
Preprocessor directives
Below is the list of preprocessor directives that the C programming language offers.
Preprocessor Syntax/Description
MACRO
Syntax: define
This macro defines constant value and can be any of the basic data types.
Example
include<stdio.h>
include<conio.h>
int add (int a, int b);
void main()
{
...…...........
}
i. include<file>variant used for system header files.(searches for a file named file in a list of
directives.
ii. include –used to paste code of a given file into the current one.
iii. define macros –a segment of code used to replace the value of a macro.
iv. undef –used to cancel the definition of a macro.
v. ifndef-checks if a macro is not defined.
vi. define const –used to define a constant
vii. include<math.h> -a preprocessor directive used to add math libraries to a program.
Input
-The process of giving something to the computer is known as input. Input is mostly given
through the keyboard. Input functions are:
Scanf ()
Gets ()
Getch ()
Getche ()
Output
The process of getting something from the computer is known as output. The output is mostly
displayed on monitors. Output functions are:
print ()
puts()
The functions used for input and output are stored in the header file stdio. h. If the programmer
uses any of the above function it is necessary to include the header file.
C keywords
They are reserved words with predefine meaning to the compiler. They include:
Table 3 C keywords
auto double int struct
break else long switch
case enum register typedef
const extern return union
char float short unsigned
continue for signed volatile
default goto size void
do if static while
Variables
Instead of remembering the complex address of that memory space where we have stored our
data, our operating system provides us with an option to create folders, name them, so that it
becomes easier for us to find it and access it.
Similarly, in C language, when we want to use some data value in our program, we can store
it in a memory space and name the memory space so that it becomes easier to access it.
Unlike constant, variables are changeable, we can change the value of a variable during
execution of a program. A programmer can choose a meaningful variable name.
Example: Height, age, are the meaningful variables that represent the purpose it is being used
for. Height variable can be used to store a height value. Age variable can be used to store the
age of a person
Datatype of Variable
Data types specify how we enter data into our programs and what type of data we enter. C
language has some predefined set of data types to handle various kinds of data that we can use in
our program. These data types have different storage capacities.
There are four data types in the C language. They are, It can be:
Table 4 C datatypes
Types Data Types
If you want to use the integer value that crosses the above limit, you can go for “long int” and
“long int” for which the limits are very high.
For example, ‘A’ can be stored using char datatype. You can’t store more than one character
using a char data type.
Please refer C – Strings topic to know how to store more than one characters in a variable.
1. float
2. double
Float:
Double:
A double data type is also the same as float data type which allows up to 10 digits after the
decimal.
The range for double datatype is from 1E–37 to 1E+37.
i. Arithmetic Operators
ii. Increment and Decrement Operators
iii. Assignment Operators
iv. Relational Operators
v. Logical Operators
vi. Conditional operators
vii. Bitwise Operators
viii. Special Operators
Arithmetic Operators
Operator Meaning of Operator
Multiplication
/ Division
++ a; //pre increment
Assignment Operators:
1. Simple Assignment
2. Compound Assignment
Simple Assignment
= Assignment Operator
e.g. x=5
5 is assigned to x
Compound Assignment
+= a += b is equivalent to a = a + b
-= a -= b is equivalent to a = a - b
= a = b is equivalent to a = a b
/= a /= b is equivalent to a = a / b
%= a %= b is equivalent to a = a % b
|= a |= b is equivalent to a = a | b
^= a ^= b is equivalent to a = a ^ b
Relational Operators:
Relational Operators are used to check the relationship between two operands. If
the relation is
true, it returns value 1 and if the relation is false, it returns value 0. Relational
operators are used
== Equal to
!= Not equal to
5 != 3 returns true or 1
Logical Operators:
logical operators:
|| Logical OR
! Logical NOT
Conditional Operator:
The conditional operator takes three operands and consists of two symbols? and.
Conditional
If c is greater than 0, the value of c will be 10 but, if c is less than 0, the value of c
will be 20.
Bitwise Operators:
A bitwise operator works on each bit of data.
| Bitwise OR
^ Bitwise Exclusive OR
C expressions
An expression is a formula in which operands are linked to each other by the use of
operators to compute a value. An operand can be a function reference, a variable, an array
element, or a constant.
Figure 6: C expressions
Types of C Expressions
Arithmetic Expressions
Example
Relational Description
Expression
x%2 = = 0 This condition is used to check whether the x is an even number or not. The
relational expression results in value 1 if x is an even number otherwise results
in value 0.
a!=b It is used to check whether a is not equal to b. This relational expression results
in 1 if a is not equal to b otherwise 0.
a+b = = x+y It is used to check whether the expression "a+b" is equal to the expression
"x+y".
a>=9 It is used to check whether the value of a is greater than or equal to 9.
Logical Expressions
Logical Description
Expressions
( x > 4 ) It is a test condition to check whether the x is greater than 4 and x is less
&& ( x < than 6. The result of the condition is true only when both conditions are
6) true.
x > 10 || y It is a test condition used to check whether x is greater than 10 or y is less
<11 than 11. The result of the test condition is true if either of the conditions
holds value.
! ( x > 10 ) It is a test condition used to check whether x is not greater than 10 and y is
&& ( y = = equal to 2. The result of the condition is true if both conditions are true.
2)
Conditional Expressions
exp1 ? exp2 : ex
Control structures
Control structures are blocks of statements that determine how program statements are to be
executed.
-Control statements deal with situations where processes are to be repeated several numbers of
There are 3 control structures used in most of the structured programming languages:
i. Sequence.
ii. Selection.
iii. Iteration (looping).
order in which they are written. In other words, the computer reads instructions from a program
file line-by-line starting from the first line sequentially towards the end of the file.
languages:
a. IF – THEN
b. IF – THEN – ELSE
c. Nested IF
d. CASE – OF
IF – THEN
IF – THEN structure is used if only one option is available, i.e., it is used to perform a
certain action if the condition is true but does nothing if the condition is false.
The general format of the IF-THEN structure is:
IF < Condition > THEN
Program statement to be executed if the condition is true;
ENDIF
If the condition is TRUE, the program executes the part following the keyword ‘THEN’.
If the condition is FALSE, the statement part of the structure is ignored, and the program
continues.
with the statements below the ENDIF.
Example
In a school, the administration may decide to reward only those students who attain a
mean mark of 80% and above.
Pseudocode
IF Mark > 80 THEN
Yes Print “ Give reward”
ENDIF
IF – THEN -ELSE
The IF-THEN-ELSE structure is suitable when there are 2 available options to select
from.
The general format of the IF-THEN-ELSE structure is:
IF < Condition > THEN
Statement 1; (called the THEN part)
ELSE
Statement 2; (called the ELSE part)
ENDIF (indicates the end of the control structure)
NESTED IF
-Nested IF structure is used where 2 or more options have to be considered to make a
selection.
The general format of the Nested IF structure is:
IF < Condition 1 > THEN
Statement 1
ELSE
IF < Condition 2 > THEN
Statement 2
ELSE
-Looping refers to the repeated execution of the same sequence of statements to process
individual data.
-The program is designed to execute the same group of statements repeatedly for a
specified number of times or until a certain condition is met/satisfied.
2). Loop control, which specifies the number of times the loop body is to be repeated.
Consider following the link below for further reading on Loop Structures
https://youtu.be/qUPXsPtWGoY
Subprograms
-Also called sub procedures – a group of statements that together perform a given task. They are:
Procedures and functions
Global variables
Local variables
Call by value
Call by reference
C program format
Structure of c language
include<stdio.h>
void main (void)
{
print (“ ”);
getch();
}
preprocessor
This symbol directs the compiler that content on this line is already processed.
include
This directive indicates that the standard library object file has to be attached to the program.
<stdio.h>
This is a header file which contains instruction for the predefined functions of the language.
Standard input/output header file contains the instruction for getting and displaying data on a
screen.
{} Delimiters
The body of the program is written in between these delimiters.
Body of program
Body of the program consists of statements or a set of statements. Each statement ends
with a semicolon (;) known as terminator which tells the compiler where one statement is
ended.
Printf(" ")
Printf() function is used to display content written in double-quotes on screen.
6.2.5.6 Self-Assessment
You are provided with the following questions for self -assessment, attempt them and
check your responses
1. What is C programming language?
2. Give five characteristics of C Programming Language
3. What do the following fundamentals mean in C programming language? Give two
examples for each
a) C keywords
b) Variables
c) C operators
d) C expressions
4. Give the difference between Sequence and Selection control structures in C
programming
5. A lady deposits 2,000 shillings in a Microfinance company at an interest rate
of 20% per annum. At the end of each year, the interest earned is added to the
deposit and the new amount becomes the deposit for that year.
Write pseudocode for a program that would track the growth of the deposits
over seven years.
6.2.5.7 Tools, Equipment, Supplies, and Materials
Flow charts
Data flow diagram
Decision table
Decision tree
Web Authoring tools
Notepad
Computer
compiler
Digital instructional material including DVDs and CDs
6.2.5.7 References
Blignaut, A. S., Hinostroza, J. E., Els, C. J., & Brun, M. (2010). ICT in education policy and
practice in developing countries: South Africa and Chile compared through SITES 2006.
Computers & Education, 55(4), 1552–1563.
Nagar, T. (2019, December 3). What is software and types of software with examples?
YourStory.Com. https://yourstory.com/mystory/what-software-types-examples
f) Variables
-A variable is a named storage location Variables which is used to store information to be
referenced and manipulated in a computer program. Example of variable include height, age
etc
g) C operators
An operator is a symbol that tells the compiler to perform specific mathematical or logical
functions. Example of C operators include arithmetic operators, assignment operators,
relational operators, logical operators etc
h) C expressions
- An expression is a formula in which operands are linked to each other by the use of
operators to compute a value. An operand can be a function reference, a variable, an array
element or a constant. Examples include arithmetic expressions, logical expressions,
conditional operators etc
In HTML (Hypertext Markup Language), tags are used to define the structure and elements of a web
page.
Here's a list of commonly used HTML tags along with their meanings:
2. \<head\> - Contains meta-information about the HTML document, such as title, links to stylesheets,
and scripts.
3. \<title\> - Defines the title of the document, displayed in the browser's title bar or tab.
5. \<h1\> to \<h6\> - Defines HTML headings where \<h1\> is the largest and \<h6\> is the smallest.
7. \<a\> - Defines a hyperlink, with attributes for specifying the target URL and link text.
8. \<img\> - Embeds an image in the document, with attributes for specifying the image source,
alternative text, and more.
13. \<span\> - Defines a section of text within another element, used for inline styling and grouping.
14. \<form\> - Defines an HTML form for user input, with attributes for specifying how the data should
be sent.
15. \<input\> - Defines an input control (e.g., text field, checkbox, radio button) within a form.
21. \<thead\>, \<tbody\>, \<tfoot\> - Defines different parts of a table (header, body, footer).
23. \<style\> - Contains CSS (Cascading Style Sheets) rules for styling the HTML document.
24. \<script\> - Embeds a client-side script such as JavaScript within the HTML document.
25. \<meta\> - Provides metadata about the HTML document, such as character set, description,
keywords, etc.
Network concepts
Web concepts
Internet addresses
Sockets
Programming network applications
Network concepts
A network is in this respect a collection of interconnected computers and/or other kinds of
equipment Terminology:
Inode, a machine that is connected to the network (computer, printer, bridge, vending
machine)
host, a fully autonomous computer connected to the network
address, each node has a unique address (several bytes)
packet, modern networks are packet-based, meaning that the information is broken down
to and sent as small chunks, each chunk of information handled separately.
protocol, rules, specifying how to perform communication.
Web services
A web application (or web app), unlike standalone application, runs over the Internet. Examples
of web apps are google, amazon, eBay, Facebook and the UCT website. A web app is typically a
3-tier (or multi-tier) client-server database application run over the Internet and it comprises five
components:
Basic Concepts
• HTTP Server: E.g., Apache HTTP Server, Apache Tomcat Server, Microsoft Internet
Information Server (IIS), Nginx, Google Web Server (GWS), and others. You will learn how to
install Apache HTTP and Tomcat web servers in the next chapter.
• HTTP Client (or Web Browser): E.g., Internet Explorer (MSIE), Firefox, Chrome, Safari,
and others.
• Client-Side Programs: could be written in HTML Form, JavaScript, VBScript, Flash, and
others.
• Server-Side Programs: could be written in Java Servlet/JSP, ASP, PHP, Perl, Python, CGI,
and others.
-Alongside the technical ”evolution”, communication between the application and also between
parts of applications residing on a different computer become more and more common
Need for applications where the participants are aware of each other:
Shared bulletin boards, whiteboards, shared word processors, control systems (eg. robots), and
(not the least) games (like RuneScape and world of warcraft).
There is support in the networks, where we will look closer on the internet
E-mail
News
Web-based databases
Client-server,
per-to-peer
Telephone
Video
Internet addresses
In 1987 – 28000,
In 1989 – 100000,
In 1990 – 300000,
IP, Internet Protocol- the network layer protocol (the reason for the name ”Internet”)
TCP, Transport Control Protocol-a connection-based protocol which ensures correct data
exchange between two nodes
UDP, User Datagram Protocol-a protocol which allows the transmission of independent packets
from one node to another with no guarantee concerning delivery or order of delivery
Sockets
A socket is one endpoint of a two-way communication link between two programs running on
the network. A socket is bound to a port number so that the TCP layer can identify the
application that data is destined to be sent to. An endpoint is a combination of an IP address and
a port number.
Server-side
The Server-side is the systems that run on the server, and the client-side is the software that runs
on a user’s web browser. The basic hosting of your files is achieved through a web server whose
responsibilities are described below.
Server-side development is much more than web hosting: it involves the use of a programming
technology like PHP or ASP.NET to create scripts that dynamically generate content.
It is important to remember that when developing server-side scripts, you are writing software,
just like a C or Java programmer would do, with the major distinction that your software runs on
a web server and uses the HTTP request-response loop for most interactions with the clients.
This distinction is significant, since it invalidates many classic software development patterns,
and requires different thinking for many seemingly simple software principles like data storage
and memory management.
Client-side
Client-side web development involves interactivity and displaying data, server-side is about
working behind the scenes to manage data. The idea of client-side scripting is an important one
in web development. It refers to the client machine (i.e., the browser) running code locally rather
than relying on the server to execute code and return the result. Many client-side languages have
come into use over the past decade including Flash, VBScript, Java, and JavaScript. Some of
these technologies only work in certain browsers, while others require plug-ins to function.
HTML
-HTML (HyperText Markup Language) a language used to develop web pages.
Hypertext means that some text in the HTML document carries a link to a different location,
which can be on the same page or another page. On clicking this 'hot spot', the viewer is
transferred to that location.
Markup means that specific portions of a document are marked up to indicate how they should
be displayed in the browser.
-HTML simply consists of tags that are placed around elements, which then changes the
properties of these enclosed elements. There are hundreds of HTML tags and some of these are
proprietary, which means that only some browsers recognize them.
<html>
<head>
<title>Internet programming</title>
</head>
<body>
</body>
</html>
For further reading on HTML,click on the link below
https://youtu.be/UB1O30fR-EE
PHP
Open source
PHP not only carries all the goodness of ASP but also is more secure and handles databases more
easily. It is a known fact that PHP on Apache Web server runs faster than ASP. PHP code is
embedded inside the HTML page and can link to databases to generate dynamic HTML content.
PHP scripts can be made to run on any operating system with little or no modification.
Pros
Can be embedded in HTML; seen as a dedicated web language.
Deceptively simple to learn.
Touted as a good beginner language.
Large array of built-in functions for everything from PDF creation to credit-card
transactions to database interaction
Available at a majority of hosting services
Relatively good integration with apache.
Cons
While the runtime services are good, the language itself is quite horrible
Encourages writing bad code ^2 {too vague}'
PHP implementation is full of bugs and might change semantics without a note, causing
constant security upgrades that break your code
PHP encourages writing web programs in an insecure manner
Not too fast (good for building database interfaces, not making calculations)
JAVASCRIPT
Javascript is a programming language that runs on a web browser. Jscript is Microsoft’s'
implementation of Javascript for Internet Explorer. Javascript is not a subset of Java, in fact,
the two languages share little in common. Javascript runs on the browser (client) and does
not require any server software. Thus, it is a client-side scripting language. Since all
execution takes place on the browser, Javascript is responsible for most of the interactivity on
a web page. Image change or text color change on mouse-over, creating mouse trails are all
possible through Javascript. The language has also been widely used for basic form
validation.
Javascript is commonly embedded inside the HTML page and is thus visible to the visitor.
Javascript can also be written to run on a server and this is based on the ASP model promoted
by Microsoft.
Pros
Most web developers familiar with language from the client-side.
Cons
Server-side standards not settled
Consider the following video links for further reading on Javascript
https://youtu.be/uDwSnnhl1Ng
https://youtu.be/2nZiB1JItbY
HTML
Tags
An HTML element is identified in the HTML document by tags. A tag consists of the element
name within angle brackets. The element name appears in both the beginning tag and the closing
tag, which contains a forward slash followed by the element’s name, again all enclosed within
angle brackets. The closing tag acts like an off-switch for the on-switch that is the start tag
Parcelling
Coding
6.2.6.4 Learning Activities
Practical activity
Instructions
In your institutions’ computer lab perform the following practicals
i. Write a basic structure of an HTML document and give a complete explanation of
each of the tags used
ii. Create your first web page which will print the text “Hello World!” on the screen.
6.2.6.5 Self-Assessment
1. What is a web programming language?
2. Give the meaning of the following Network Concepts.
i. Node
ii. Host
iii. Packet
iv. Protocol
3. What is the role of web programming language?
4. What is the difference between Client-side and Server-side web programming
approaches?
6.2.6.6 Tools, Equipment, Supplies and Materials
Flow charts
Data flow diagram
Decision table
Decision tree
Web Authoring tools
Notepad
Computer
Software
Digital instructional material including DVDs and CDs
6.2.6.7 References
Alzahrani, A. A. (2020). 4GL Code Generation: A Systematic Review. (IJACSA)
International Journal of Advanced Computer Science and Applications. 6(11). Retrieved
fromhttps://www.researchgate.net/profile/Abdullah_Alzahrani13/publication/
342652608_4GL_Code_Generation_A_Systematic_Review/links/
5f48e73892851c6cfdf046e6/4GL-Code-Generation-A-Systematic-Review.pdf.
Connolly, R. (2015). Fundamentals of web development. Pearson Education.
Kumar, H. (2019). Programming software and Computer Languages. International
journal of advance research and innovative ideas in education. 3(5).
Selby, C. (2011). Four approaches to teaching programming. Retrieved from
Shaydulin, R., & Sybrandt, J. (2017). To agile, or not too agile: A comparison of software
development methodologies. arXiv preprint arXiv:1704.07469.
4. Give the difference between Client-side and Server-side web programming approaches
--Client-side scripting generally refers to the class of computer programs on the web that
are executed client-side, by the user's web browser. Client-side scripts are often
embedded within an HTML or XHTML document (hence known as an "embedded
script"), but they may also be contained in a separate file, to which the document (or
documents) that use it make reference (hence known as an "external script") while
-server-side scripting are executed by the web server when the user requests a
document. They produce output in a format understandable by web browsers (usually
HTML), which is then sent to the user's computer.
-The user cannot see the script's source code (unless the author publishes the code
separately), and may not even be aware that a script was executed. Documents
produced by server-side scripts may, in turn, contain client-side scripts.
5. Give a brief description of the following web programming interfaces
i. Common client Interface(CCI)
ii. Common Gateway Interface (CGI)
TERMS USED
- A standard markup language used for creating web pages and web applications. It structures content
on the web by using elements represented by tags.
2. Tag:
- A code element in HTML that defines the structure and content of a web page. Tags are usually
enclosed in angle brackets, e.g., `<p>`, `<a>`, `<div>`.
3. Element:
- An individual component of an HTML document, consisting of a start tag, content, and an end tag,
e.g., `<p>This is a paragraph.</p>`.
4. Attribute:
- Additional information provided within an HTML tag to specify certain properties of an element, e.g.,
`<a href="https://www.example.com">`.
- A programming interface for web documents. It represents the page so that programs can change the
document structure, style, and content.
6. Head:
- The section of an HTML document that contains meta-information about the document, such as title,
meta tags, and links to scripts and stylesheets, e.g., `<head>`.
7. Body:
- The section of an HTML document that contains the actual content to be displayed on the web page,
e.g., `<body>`.
8. Doctype:
- A declaration at the beginning of an HTML document that specifies the version of HTML being used,
e.g., `<!DOCTYPE html>`.
9. Hyperlink:
- An HTML element that links to another web page or resource. Created using the `<a>` tag, e.g., `<a
href="https://www.example.com">Visit Example</a>`.
- A stylesheet language used for describing the presentation of a document written in HTML. It
controls the layout, colors, fonts, and other visual aspects of the web page.
11. JavaScript:
- A programming language used to create dynamic content and interactive effects on web pages. It
can manipulate the HTML and CSS of a web page.
12. Form:
- An HTML element used to collect user input. It contains form controls like text fields, checkboxes,
radio buttons, and submit buttons, e.g., `<form>`.
13. Table:
- An HTML element used to display data in a tabular format, using `<table>`, `<tr>` (table row), `<td>`
(table cell), and `<th>` (table header).
- The use of HTML tags that convey the meaning of the content, making it easier for search engines
and screen readers to understand the structure of the page, e.g., `<header>`, `<footer>`, `<article>`,
`<section>`.
16. ID:
- An attribute that assigns a unique identifier to an HTML element. It can be used for styling with CSS
or for manipulation with JavaScript, e.g., `<div id="main-content">`.
17. Class:
- An attribute that assigns a class name to an HTML element. Multiple elements can share the same
class name for styling with CSS or for manipulation with JavaScript, e.g., `<div class="highlight">`.
- An HTML element that starts on a new line and takes up the full width available, e.g., `<div>`, `<p>`,
`<h1>`.
- An HTML element that does not start on a new line and only takes up as much width as necessary,
e.g., `<span>`, `<a>`, `<img>`.
20. Viewport:
- The visible area of a web page on a device screen. The viewport meta tag helps control the layout on
mobile browsers, e.g., `<meta name="viewport" content="width=device-width, initial-scale=1.0">`.
These definitions cover a range of foundational concepts and terms used in HTML, providing a basic
understanding of how HTML is structured and how it functions within web development.
- What is HTML?
- `<!DOCTYPE html>`
- `<html>`
- `<head>`
- `<body>`
- Self-closing tags
- Basic tags
- Paragraphs (`<p>`)
- Links (`<a>`)
- Images (`<img>`)
3. Attributes
- Common attributes
- `href`
- `src`
- `alt`
- `title`
- Global attributes
- `id`
- `class`
- `style`
- `data-`
- Semantic elements
- Headers (`<header>`)
- Navigation (`<nav>`)
- Sections (`<section>`)
- Articles (`<article>`)
- Footers (`<footer>`)
5. Lists
- Hyperlinks
- Internal links
- External links
- Navigation bars
- Inserting images
8. Tables
- Creating tables
- Table attributes
- `colspan`, `rowspan`
- Table styling
- Borders, padding, spacing
9. Forms
- Form elements
- Form attributes
- Input types
- Form validation
- Required fields
- Pattern matching
- Canvas element
- Indentation
- Naming conventions
- Accessibility
- Using `alt` attributes for images
- SEO-friendly HTML
- Meta tags
- Linking CSS
- Linking JavaScript
This outline provides a structured approach to teaching HTML, starting from the basics and gradually
moving to more advanced topics.