0% found this document useful (0 votes)
6 views

PROGRAMMMETHODSMyNote 2

The document discusses programming methods and the history of programming languages. It explains that a program is a set of instructions that allows a computer to perform tasks, and a programming language allows humans to communicate with computers. Early programming languages included machine language and assembly language, while modern languages include imperative, functional, logic-based, object-oriented, and declarative languages. Object-oriented programming organizes programs around objects that contain both data and behaviors. The four main pillars of OOP are encapsulation, abstraction, polymorphism, and inheritance.

Uploaded by

mallam sharif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

PROGRAMMMETHODSMyNote 2

The document discusses programming methods and the history of programming languages. It explains that a program is a set of instructions that allows a computer to perform tasks, and a programming language allows humans to communicate with computers. Early programming languages included machine language and assembly language, while modern languages include imperative, functional, logic-based, object-oriented, and declarative languages. Object-oriented programming organizes programs around objects that contain both data and behaviors. The four main pillars of OOP are encapsulation, abstraction, polymorphism, and inheritance.

Uploaded by

mallam sharif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 84

PROGRAMMING

METHODS

IPMC TRAINING COLLEGE


Chapter 1
HISTORY OF PROGRAMMING
Objectives;

Explain what is meant by a program


Understand who is a programmer
Explain what programming language means
Describe the various language models
Identify and describe the generations of programming
languages and point out their differences
Identify and Describe the basic concepts of Object Oriented
Technology
Discuss

• What is a program?
• What is a programming language?
• Who is a programmer?
Program

There are many definitions of what a program is, the following are some
acceptable examples;
A program is a group of related instructions that aim to perform a task(s).
A complete set of instructions a computer can interpret and follow to
perform a task(s).
A set of instructions for a computer(s) to follow.
Complete algorithm for computer(s) to solve specific problems.
Programming Language

Like human’s languages; Computers also have the language it “understands”


which is machine language.

A programming language is the language in which computer programmes


are written.
A language which allows humans to interact with computers in order to tell
the computer what to do.
Language Models

a) Imperative languages
b) Functional Languages
c) Logic Programming
d) Object-oriented Languages
e) Declarative Languages
f) Scripting Languages
g) Parallel Languages
Language Models

a) Imperative languages: These comprise of commands and control structures e.g.


C , Pascal, Fortran and Assembly.
b) Functional Languages: Based on lambda calculus contains function definitions
and function applications
c) Logic Programming: It is made up a complete collection of statements on a
specific logic e.g. Prolog.
d) Object-oriented Languages: These are used to create objects(modules) that
interact with each other. They have the characteristics of real life objects eg Java,
Eiffel, Simula and Smalltalk-80
Language Models

e) Declarative Languages: They are used to give a general idea as how the
various parts of a program are related (variables and functions)
f) Scripting Languages: They usually work in with larger applications to
perform simple or complex tasks e.g. vbscript and javascript.
g) Parallel Languages: Structured data or processes that communicate with
each other e.g. Ada and C#
Language Generations
• First Generation(1GL): Also known as machine language is
numerical(binary) and machine dependent. Programs in 1GL
are executed fastest compared other generations. Its very
difficult writing machine code.
• Second Generation(2GL): The 2GL permitted the use of
symbolic instructions and addresses. Also known as the
assembly language it was a easier to use and understand than
machine code.
• Third Generation(3GL): These languages are machine
independent, making it easier to cross-platform programs.
This leaves time for the programmer to focus more on the
logic of the program.
Language Generations

• Fourth Generation(4GL): Non procedural programming languages that


allows programmers to focus on what he/she wants and not how to do it.
• Fifth Generation(5GL): The 5GL focuses on creating intelligent programs
such as artificial intelligence(A.I.) and fuzzy logic. It provides the
groundwork for creating programs using natural language(N.L.).
OBJECT ORIENTED PROGRAMMING

OOP simply seeks to let developers envision their programs as real


world objects which work together. As such developers construct
systems based on components rather than structures.
• Object-oriented programming (OOP) refers to a type of computer
programming (software design) in which programmers define not only the 
data type of a data structure, but also the types of operations (functions)
that can be applied to the data structure.

• In this way, the data structure becomes an object that includes both data and


functions. In addition, programmers can create relationships between one
object and another. For example, objects can inherit characteristics from
other objects.
Object

• What is an object?
• What are the characteristics of objects?
• What can an object never be?
Object

 An object can be taught of as an instance of a class.


 An object can be said to be an example of a class.
Objects have state and behaviour
State are the attributes or charateristics of the object
Behaviour are the methods or functions of the object
Class
• A class is a user-defined type that describes what a certain type
of object will look or be.

An object is a single instance of a class. You can create many objects from the


same class type.
In object-oriented programming, a class is a blueprint for creating objects
(particular data structure), providing initial values for state (member variables or
attributes), and implementations of behavior (member functions or methods). The
user-defined objects are created using the class keyword.

• A blueprint is a guide for making something. It’s also a design or


pattern that can be followed.
An Object can be;

• Some physical thing in the real world


• A representation of reality
• A tangible or visible thing.
• A thing to which action or thought can be directed.
• Passive i.e. doing nothing until activated
• Active continually monitoring until condition change
An Object can not be;

• A value
• A process
• Time
Types of Class

• Abstract class: Declare member variables and member functions e.g.


general description of a car without specific details of length, height etc.

• Concrete class: Define member variables and member functions e.g. a


house’s detailed plan including concise measurements(blueprint)
Four Main Pillars of OOP

 ENCAPSULATION

 ABSTRACTION

 POLYMORPHISM

 INHERITANCE
Encapsulation and Abstraction
 Encapsulation: This is the process of binding or wrapping data and
methods under a single unit in order to keep both safe from outside
interference and misuse of codes.

 Abstraction: This is basically only showing the necessary details to the


user of the object. For example; when you turn on your laptop, you just
push the power button and the laptop screen will lit-up; you don’t care
about the inner mechanism of what goes on to put the laptop on for use.
Polymorphism and Inheritance
 Polymorphism: This is basically the combination of two different words
which is “poly; (means many) and morph (means forms)”. It’s the ability
to perform single action in different or multiple ways.

 Inheritance: It is the most powerful feature and it basically allows


programmers to reuse codes.
Consider having an existing class and you want to build a new class that uses
the previous class’s stuff, but adds additional features.
• Interface: the languages and codes that the applications
use to communicate with each other and with the
hardware.

• Procedure: a section of a program that performs a


specific task.
The object oriented programming (OOP) is a programming

model where Programs are organized around object and data

Rather than action(methods) and logic.


 

OOP allow decomposition of a problem into a number of


entities called Object and then builds data and function around
these objects.
Messages and Operations

• Message: Objects communicate with each other through messages.

• Methods: The ability of an object to perform action is its


method(operation/function).
Relationships

a) Inheritance
b) Association
c) Multiplicity
Inheritance

• The process whereby objects inherit attributes from other objects and
classes inherit their attributes from other classes.
Types of Inheritance
 Single Inheritance
 Multi-Level Inheritance
 Hierarchical Inheritance
 Multiple Inheritance
 Hybrid Inheritance

NB: A Super class or also be known as Base or Parent class and a Child class
can also be known as Derived or Sub class.
• Single Inheritance: This is where a child class inherits from a parent class.

Parent Class

Child Class
• Multi-Level Inheritance: A child class inherits from a super class which in
turn inherits from another super class.

Super Class

Super Class

Child Class
• Hierarchical Inheritance: This is where a child class inherits from a parent
class which inherits from a grandparent and so on.

Grandparent Class

Parent Class

Child Class
• Multiple Inheritance: This is where a child class inherits from two or more
super classes.

Super Class Super Class

Child Class
• Hybrid Inheritance: This is a combination of the various types of inheritance
like single, multi-level, multiple and hierarchical inheritance.
Association

Association: It is how one object is connected or relates to another object.


Types of Association

One-to-One
One-to-Many
Many-to-Many
Multiplicity
Multiplicity: It’s a type of task in which an entity has too many kind of
relationship.
For example; an organization with more than one owning.
Summary

We learnt;
What is meant by a program
Who a programmer is
What is meant by programming language
The concept of programming language models
The idea of programming language generations
An introduction to structured programming
An introduction to object-oriented concepts, such as;
Classes
Encapsulation and Information hiding (Abstraction)
Messages and Operations (Methods/functions)
Relationships
Polymorphism
Objective Questions

1. Which of the following best explains a program?


a. instructions for users to follow b. instructions for programmers to follow c. instructions for computers to follow
2. How many language models are there?
a. 5 b. 7 c. 8 d. 9
3. What is meant by machine dependant software?
a. It needs any computer to run b. It needs a particular code to work c. It can only run on computers that have huge
memory d. It can only run on a specific computer
4.Which generation(s) of programming languages were used to create machine dependant software?
a. 3GL b. 2GL c. 1GL d. 4GL e.5GL
5. Which of the following best explain encapsulation?
a. Hiding a systems functionality from programmers b. Hiding a systems functionality from users c. Hiding a
systems functionality from computers d. Hiding a systems functionality from objects and classes
Objective Questions

6. Which of the following has to do with objects with the same name that perform operations in different
ways.
a. Association b. Classes c. Polymorphism
7. An instance of a class is known as a(n)….
a. Structure b. Property c. Object
8. …… shows how two or more classes or objects are connected (related) together.
a. Inheritance b. Association c. Multiplicity
9. ……… and ……….. classes are the two types of classes
a. Abstract b. Obstruct c. concrete d. Real
10. Using Object Oriented Programming lets programmers create reusable code.
a. True b. False c. Neither d. Both
Answers

1. c
2. b
3. d
4. b,c
5. b
6. c
7. c
8. b
9. a , c
10. a
Excercise

Form groups and research on the following topics; each group should tackle
one topic
Discuss the pros and cons of OOP
Discuss the language generations and their significance to modern
programming
Notes
 Rapid Application Development(RAD): RAD is a programming system
employed to create applications very fast and efficiently. RAD systems
provide easy to use and customisable GUIs and toolkits so
programmers can focus on logic. E.g. visual basic, visual studio, Delphi
etc.
 Tool Command Language(TCL): It is used for prototyping applications
as well as developing CGI. Its Library can be extended.
 Prototyping: A technique used in development when you make a
working version of the program and test it in its operating environment
to ascertain whether it viable. In other words it is a blue print of the
program.
 Common Gateway Interface(CGI): A specification for the transfer of
information between the word wide web(www)and a CGI program.
 Practical Extraction and Report Language(PERL): It is a programming
language for processing text.
 Algorithm: Logical finite steps taken to solve a problem.
Chapter 2
Variables, Control Structures and Calculations
Objectives;
Understand what variables are
Identify what data types are and how to use them with variables
Describe the naming conventions for variables
Identify and use arithmetic operators
Understand the importance of order of precedence
Describe control structure
Use calculations to create computer programs
Understand and apply algorithms
Understand and use flowcharts
Variables

 A variable is a placeholder for values in memory.


 A variable is a space in memory where data is stored
Data Types

• You must decide what to put into variables i.e. a bowl designated for serving
humans would not be used for serving animals.
• Data types tell the computer what kind of data the variable would contain.
This makes it possible for the computer to reserve the relevant space for the
variable
Data Types

 Integer(int): Positive and negative whole numbers e.g. 20,4,-23, etc. .


 Float/real : Positive and negative rational (fractional) numbers e.g. 20.03,4.01,-
23.00, etc. .
 Double: Like float but reserves more memory.
 Character(char) : single letters, numbers and special characters e.g. a,Y,7,etc. .
 String: A collection(array) of characters such as names e.g. Roland, church, etc. .
 Boolean(bool): True or false(1,0)
Naming Variables

Variable names
should not start with a number i.e. 3age etc. but can have numbers within
the name or at the end of name .
Should not contain a dot(.) i.e. first.name etc. .
Should not contain spaces i.e. first name etc. .
Should not contain special characters i.e. first#name, first~name, etc. .
Naming Variables

• Variable names should


• Express what it would store
• Be simple and straightforward
• Be written together as one word if the name spans more than one word e.g.
firstname.
• Be written by capitalising the first letter of each word e.g. FirstName.
Arithmetic Operators

• + means add
• - means subtract
• * means multiply
• / means divide
• % means modulo
Arithmetic Operators

Order of precedence:
I.Brackets
II.Exponents
III.Multiplication
IV.Division
V.Addition
VI.Subtraction
Assignment Operator

 Equals to(=): The assignment operator is the = symbol. It is used to give the
value of what is to its right to what is in the left for example int a; a=10;

NB: The reverse is not true


Control Structure

• A syntactic form in a language to express the flow of control.


• It basically analyzes and chooses in which direction a program flows based on
certain parameters or conditions. There are three basic types of logic, or flow of
control, known as:
1.Sequence logic, or sequential flow
2.Selection logic, or conditional flow
3.Iteration logic, or repetitive flow
Types of Control Structure

 If… (SELECTION)

if(condition){
--statement(s)--
} else{
--statement(s)--
}
Types of Control Structure

 If… else if… else (SELECTION)


if(condition1){
--statement(s)--
} else if(condition2){
--statement(s)--
} else if(condition3){
--statement(s)--
} else{
--statement(s)--
}
Types of Control Structure

 Switch case (SELECTION)


switch(choice){
choice 1:--statement(s)--
break;
choice 2:--statement(s)--
break;
choice 3:--statement(s)--
break;
default:--statement(s)--
}
Rules for switch statement:

• An expression must always execute to a result.


• Case labels must be constants and unique.
• Case labels must end with a colon ( : ).
• A break keyword must be present in each case.
• There can be only one default label.
• We can nest multiple switch statements.
Types of Control Structure

For loop(LOOP / ITERATION)


for(control value; condition; control condition){
--statement(s)--
}

Care should be taken to choose the appropriate condition to prevent infinite loops.
Types of Control Structure

 While (LOOP / ITERATION)


while(condition){
--statement(s)--
--control condition--
}
Care should be taken to choose the appropriate condition to prevent infinite
loops.
Types of Control Structure

 Do … While (LOOP / ITERATION)


do{
--statement(s)--
--control condition--
}
while(condition)

Care should be taken to choose the appropriate condition to prevent infinite


loops.
Flowchart

• A diagram used to depict the flow of logic in a program


• It is used to show the algorithm of a program
Flowchart

Start / Stop

Action/Process

• Symbols: Flow

Screen / Display /Input / Output

Decision

Connector
Summary

• We learnt;
• What variables are and how to use them
• Variable types(data types) and names
• Control structure 1 (Sequence)
• Control structure 2 (Selection)
• Control structure 3 (Loops)
• Using pseudocode
• Using flowchart
Questions

1. What is pseudocode?
2. What are the advantages of using pseudocode name four(4)?
3. In what instances do we use the sequence ?
4. In what instances do we use the selection ?
5. In what instances do we use the loops?
6. What symbol is used as the assignment operator?
Exercise 2.7

TRY:
Write the pseudocode and draw a flowchart for a program to calculate the
wages of a salesman according to the following rules.
The wage is calculated at a rate of 15% of sales. If the salesman has been
with the company more than three years, he has a loyalty bonus of 10% of
his calculated wage.
Exercise 2.7 Answer
Pseudocode
Use variables: sales, years, wage, bonus OF Type Real
name OF TYPE string
Display “Enter the name of the salesman:”
Accept name
Display “Enter the number of years with the company”
Accept years
Display “Enter the sales figures:”
Accept sales
wage=sales*15/100
If years>3
Then bonus=wage*10/100
else bonus=0
endif
wage=wage+bonus
Print name ”has sales figures of ” sales, ” a bonus of” bonus “and “ wage “wages”
End program
Exercise 2.7 Answer
Flowchart
Page 1 Page 3
Page 2
START P1 P2

Yes
Years >
3
Display “Enter
the name of Display “Enter the
sales figures” No
salesman”

Calculate
bonus = 0
Accept name Accept sales

Calculate
bonus = wage* 10/100
Display “Enter the Calculate
number of years with wage = sales*15/100
the company”
Display name “has sales
figures of “sales “ a
bonus of” bonus “and “
Accept years wage “wages”

STOP

P2 P3
Note
 Array: It is a group of related variables or a continuous
space in memory for a group of related variables declared
together
 Constant: A data item or quantity whose value does not
change.
 Pseudocode (Pseudolanguage): A design technique used
to give a general description of a software module usually
interpreted by programmers.
 Identifier: A string of characters used to name an element
of a program.
Chapter 3
Data Analysis and Problems
Objectives;
Understand the software development process
Ability to create and analyse structure diagrams for structured programs
Explain variable and fixed length records
Organise information
Understand the structure of data
Analyse problems
Program Development Process

There are many kinds of programs that are developed by different


programmers. However, they all have something in common; which is the
development it went through in some phases.

In other to create good and reliable software, we employ the software


lifecycle to guide us.
Software Development Lifecycle

• Requirements analysis: At this stage a well defined and


accurate client and user requirements are generated. The
deliverables here help guide the development team.
• Design: This stage describes how the solution (program)
would be built. It also refines the specified requirements from
the previous stage.
• Coding: At this stage the programmers write and document
the code for the solution. Coding starts only after design is
fully completed.
Software Development Lifecycle

 Testing: In this stage the solution is tested against real life scenarios. The
solution is tested by the developers (alpha test) the clients/users are given
the chance to use the program to ascertain whether it meets their
requirements (beta test).
 Implementation and support: After the solution passes every test, it is
implemented. The solution and the documentations are finalized for use
by the clients. After implementation the developers provide after sales
service such as updates, upgrades etc. .
Structure Diagrams

• Structure are diagrams programmers use to help visualise solutions they are
creating.
Data Structure

• It is a diagram used in analysing how data is organised.


• Data structure uses :
• A rectangle to depict data
• A rectangle with a * at the top right corner to depict a loop(iteration)
• A rectangle with a small circle at the top right corner to depict a
selection(choice).
Data Structure
*
Iteration
(repetition)

O
Selection
Data Structure
Module

*
Student

Student ID Name Results

*
Results
Second Name
First Name

Assignment Exam
Organising Information

• Field: It is an item of data within a record(the smallest piece of meaningful


information)
• Record: It is series of related fields which contain data concerning an entity.
• File: A collection of related records.
• Database: A group of related files.
Fixed and Variable Length Records

• Fixed Length records: A record in which the number of characters can be


predetermined.
• Variable Length records: A record in which the amount of data to be stored
in the record vary. This would make impossible to correctly predict the
necessary space required.
Analysing the Problem

 In order to fully solve a problem, you need to know what is expected at


the end of the solution.
 Hence, you need to get a well defined program specification
 It would help you understand fully what is needed in the solution .
 This would help you strategize the best way to tackle the problem.
Analysing the Problem

 Top –down development: If the program is complicated, then you need to break
it down into simpler tasks in a stepwise manner.
 Stepwise refinement: an approach in software development in which a complex
program is gradually refined through a sequence of intermediate representations
to yield a final program in some programming language.
 Modular programming: It is a programming style were a program is decomposed
into a set of components(modules). Each module is of manageable size, is well
defined and has an interface to connect with other modules.
CRC Cards

 C – Class
 R – Responsibility
 C – Collaboration

 Classes have well defined roles in the system


 Responsibilities replace the explicit attributes and operations of a class and focus
on the behaviour of class.
 Collaboration is the way in which classes interact with each other.
• The CRC Card ... CRC card approach is a design and analysis
approach to help us in analysis design phrase in software
development life cycle. 
• Class, Responsibility & Collaboration.
• The aim of using CRC is to discover the real world objects is a system and
map the collaboration among classes and their responsibilities.
Summary

We learnt;
Program development process
Structure Diagrams
Organising Information
Fixed and variable length records
Analysing the problem
Structured Programming Diagrams
CRC cards
Questions

1. Create a structure chart for a library system


2. Describe how you would apply the top-down development to create a
school management system
3. Use CRC card session to develop any system e.g. library system
The End

You might also like