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

Lecture 1-Fundamentals of Computer Programming

The document provides an overview of fundamentals of computer programming including definitions of key terms like data, information, hardware, software and programming. It also discusses types of programming languages from low-level like machine code to high-level languages and describes structured and object-oriented programming approaches. Additionally, it covers concepts like classes, objects, inheritance, polymorphism and syntax rules.

Uploaded by

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

Lecture 1-Fundamentals of Computer Programming

The document provides an overview of fundamentals of computer programming including definitions of key terms like data, information, hardware, software and programming. It also discusses types of programming languages from low-level like machine code to high-level languages and describes structured and object-oriented programming approaches. Additionally, it covers concepts like classes, objects, inheritance, polymorphism and syntax rules.

Uploaded by

w55fv64q55
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Fundamentals of computer

programming
Introduction to computer programming
Terminologies
• A computer is an electronic machine, operating under the control of
instructions stored in its own memory
• It accept data, manipulate the data according to specified rules,
produce results, and store the results for future use
• Computers process data to create information
• Data is a collection of raw unprocessed facts, figures, and symbols.
• Information is data that is organized, meaningful, and useful. To
process data into information, a computer uses hardware and
software.

SM KALISHA
Cont..
• A computer program or software is the series of instructions that
tells the hardware how to perform tasks.
• is a collection of instructions that performs a specific task when
executed by a computer
• a sequence of separate small commands, one after the other
• Programming is the act of an individual writing code (a series of
instructions) that are to be interpreted and executed by a computer
or other electronic device.
• Computer programmer
-a person who writes series of instructions
- is a person who creates computer software
SM KALISHA
• Computer programming is the process of writing or editing source
code
• Editing source code involves testing, analyzing and refining the code

SM KALISHA
What is programming language
• There many definitions of what constitutes a programming language
and there is not one absolute answer
• Here are some ideas on what constitutes a programming language
A computer tool that allows a programmer to write commands in a
format that is more easily understood or remembered by a person,
and in such a way that they can be translated into codes that the
computer can understand and execute.
Allows human beings and computers to communicate Computer
programming languages enable humans to write in a form that is
more compatible with a human system of communication
SM KALISHA
The evolution of programming languages

Low-level
• First Generation
• machine-level programming language, which was written in 1s and 0s. There
is no compiler or translator required and it can be understood and used by a
CPU directly.
• Second Generation
• assembly language.
• Symbolic instructions and addresses
• the code can be read and written fairly easily by a human
• but it must be converted into a machine readable form in order to run on a
computer.
• Examples = IBM, BAL and VAX Macro

SM KALISHA
High-level
• In assembly language programmers were still forced to think in terms
of individual machine instructions.
• High level languages were designed to be closer to natural languages.
• Third Generation
• Third generation language(3GL) is a high level language designed to be easier
for a human to understand, including things like named variables.
• Fortran, ALGOL and COBOL are early examples of this sort of language. Most
"modern" languages (BASIC, C, C++,Java) are third generation. Most 3GLs
support structured programming.

SM KALISHA
• Forth Generation
• closer to human languages than typical high-level programming languages.
• Most 4GLs are used to access databases.
• Examples = SQL, Postscript

• Fifth Generation
• Appeared in the 1990s,
• based around solving problems using constraints given to the program, rather
than using an algorithm written by a programmer.
• used mainly in artificial intelligence research and fuzzy logic.
• Prolog, OPS5, and Mercury are the best known fifth-generation languages

SM KALISHA
Compiler vs Interpreter
• Compiler a program that translates high-level language into absolute
code, or sometimes into assembly language
• Interpreter a language processor that analyses a line of code and
then carries out the specified action, rather than producing a
machine-code translation to be executed later

SM KALISHA
Approaches (programming methodologies) to
programming design
1. Structured (procedural)approach.
2. Object-oriented approach.
Structured (procedural) programming:
• Dividing a problem into smaller sub problems. Each sub problem is
then analyzed, and a solution is obtained to solve the sub problem.
• The solutions to all of the sub problems are then combined to solve
the overall problem.
• Languages e.g C, Pascal, Fortran, ALGOL and Assembly

SM KALISHA
Object-oriented programming
• Object-oriented programming (OOP) refers to the creation of
reusable software objects that can be easily incorporated into
multiple programs
• Object-oriented design (OOD) is a widely used programming
methodology.
• Components called objects are identified. These objects interact with
one another

SM KALISHA
Object oriented programming uses the following concepts: -
- A system can be constructed from a set of objects – just as a house is built from
bricks, windows, doors, amongst other things.
• Adding new abilities to existing objects can expand a system.
- Creating new objects can expand a system.
- Objects built for a particular system can be used for building another system.
This reduces the development time as the existing design can be used to create
other objects.

SM KALISHA
Classes and objects
• A class is a definition/blueprint/template used for creating objects

• An object is an instance of a class or category.


- An example is a dog.
Class is the classification of objects which have the same structures
and characteristics.
- For example, a house is a class, and the types of houses, e.g.
apartment, an upstairs are instances of that class.

SM KALISHA
• Just like things in the real world, software objects have state and
behaviour.
- The object’s state is made up its properties (or attributes) which
describe aspects of the object, for example, a car might have an
engine type, a make, model number and a colour.
• Behaviours are the operations that the object carries out, for
example, a car accelerating, braking, changing gear and turning the
windscreen wipers on.

SM KALISHA
Four fundamental ideas/features in oop
• Abstraction, polymorphism, Inheritance, Encapsulation
Abstraction
-focus on essentials(ignore the irrelevant, ignore the unimportant)
Encapsulation
-information hiding mean that only an object can manipulate its data
through using its own methods or operations.
-This prevents other objects from accessing its insides, and 'prevents
accidents'.
-The idea of encapsulation is to hide your objects, attributes and methods

SM KALISHA
Inheritance
• refers to the fact that one class can inherit part or all of its structure
and behaviour from another class
• A subclass inherits everything from a superclass, and can also add
other features, as well as override some of the inherited features
Polymorphism
• Means “many forms”
e.g + sign 2+5 (add), “Hello”+”World”(concatenation)
• Polymorphism allows developers to re- use terminology and to allow
it have more than one meaning.
SM KALISHA
Syntax (syntax rules)
- the rules defining the legal sequences of symbolic elements in a
language
- syntax rules define the form of the various constructs in the
language, but say nothing about the meaning of those constructs
• Other syntax rules specify the permissible sequences of tokens and the
process of assigning meaning to these token sequences is part of semantics.
• A token is a string of characters

SM KALISHA
Keywords
• In many languages, such as C and similar environments like C++, a keyword is
a reserved word which identifies a syntactic form.
• Words used in control flow constructs, such as if, then, and else are
keywords. In these languages, keywords cannot also be used as the names of
variables or functions.
• Other examples = Repeat, Begin, End.

SM KALISHA
Comments
• a comment is a programming language construct used to embed
programmer-readable annotations (notes) in the source code of a
computer program.
• These annotations are potentially significant to programmers but
typically ignorable to compilers and interpreters
• Comments are usually added with the purpose of making the
source code easier to understand.
• The syntax and rules for comments vary and are usually defined in
a programming language specification

SM KALISHA
Comments cont…
• Comments are generally formatted as
• block comments (also called prologue comments or stream
comments) or
• line comments (also called inline comments)
• Examples
• // C line comment
• ' Visual basic line comment
• /* */ C block comment

SM KALISHA
Variables
• A variable is a symbol that represents a storage location in the
computer’s memory
• The information that is stored in that location is called the value of
the variable
• One common way for a variable to obtain a value is by an assignment
operator
• Depending on the programming language, variables may only be
able to store a specified datatype (e.g. integer or string).
• Therefore only specified actions as defined by the type can be
done on that variable i.e. multiplication of integer variables.
SM KALISHA
Identifiers
• Identifiers are names of things that appear in programs, such as
variables, constants, and functions.
• A C++ identifier consists of letters, digits, and the underscore
character (_) and must begin with a letter or underscore
• The following are legal identifiers in C++:-
payRate
counter1

SM KALISHA
Whitespaces
• Every C++ program contains whitespaces. Whitespaces include
blanks, tabs, and newline characters.
• Proper utilization of whitespaces in a program is important. They can
be used to make the program more readable.

SM KALISHA
Common programming errors
• Syntax error: - This error occurs due to the following reasons;
-Not following the grammatical rules used in declaration of identifier.
-Not terminating statement by semicolon.
-Not providing equal number of opening and closing braces.
• These errors can be rectified by the user as it is displayed while compiling
the program.
• Logical error: - This error won’t be displayed on the screen. However it will
lead to wrong results.
-Example: An infinite loop. This error lead to abnormal termination of a
program or infinite loop.

SM KALISHA
• Run-time error: - This error occurs while running a program by
displaying the message listed below;
-Division by 0
-Overflow
-Underflow

SM KALISHA
Program translation
translation from a more human-readable form of the program into
executable binary code
Consider the following C++ program

SM KALISHA
• When writing C++ programs, remember that C++ is case-sensitive
• That means that main() is different from Main()
• The safest policy is to type everything in lower-case except when you
have a compelling reason to capitalize something.

SM KALISHA
Cont..
• The first line of this source code is a preprocessor directive that tells the C++ compiler
where to find the definition of the std object that is used on the 2nd line.

• The identifier iostream is the name of a file in the Standard C++ Library.

• The expression <iostream> is called a standard header.

• The 3rd line is also required in every C++ program. It tells where the program begins.

• The identifier main is the name of a function, called the main function of the program

• Every C++ program must have one and only one main() function.

• The required parentheses that follow the word “main” indicate that it is a function

SM KALISHA
• The keyword int is the name of a data type in C++. It stands for “integer”. It is
used here to indicate the return type for the main() function.

• A program body is a sequence of program statements enclosed in braces { }

• << represents the C++ output operator

• >> the input operator

• \n represent the newline character.

-When the output device encounters that character, it advances to the


beginning of the next line of text on the screen

• Finally, note that every program statement must end with a semicolon (;)
SM KALISHA
Program translation process

SM KALISHA
Step One
• Use a text editor to create a C++ program following the rules, or
syntax of C++.
• This program is called the source code, or source program.
• The program must be saved in a text file that has the extension .cpp.
Step Two
• Preprocessor directives are processed by a program called
preprocessor.
• Preprocessor directives are statements that begin with the symbol #.
SM KALISHA
Step Three
• Verify that the program obeys the rules of the programming language.
• That is to say that the program is syntactically correct and translate the
program into the equivalent machine language.
• The compiler checks the source program for errors.
• The compiler checks the source program for syntax errors and, if no error is
found, translates the program into the equivalent machine language.
• The machine language version of the high-level language program is called
object program.

SM KALISHA
Step Four
• The object program is translated into an executable file for the computer to
execute.
• This is done by a program called a linker.
• Linker: A program that combines the object program with other programs
in the library and is used in the program to create the executable code.
Step Five
• Load the executable program into main memory for execution.
• A program called a loader accomplishes this task.
Step Six
• The final step is to execute (run) the program.

SM KALISHA
Steps in Software Development
1. Requirement gathering and analysis
2. Design
3. Implementation or coding
4. Testing
5. Deployment
6. Maintenance

SM KALISHA
Requirement gathering and analysis
• This phase is the main focus of the project managers and stake
holders. Meetings with managers, stake holders and users are held in
order to determine the requirements like;
-Who is going to use the system?
-How will they use the system?
-What data should be input into the system?
-What data should be output by the system?
• After requirement gathering these requirements are analyzed for
their validity and the possibility of incorporating the requirements in
the system to be development is also studied.

SM KALISHA
Design
• In this phase the system and software design is prepared from the
requirement specifications which were studied in the first phase.
• System Design helps in specifying hardware and system requirements
and also helps in defining overall system architecture.
• The system design specifications serve as input for the next phase of
the model

SM KALISHA
Implementation / Coding
• On receiving system design documents, the work is divided in
modules/units and actual coding is started.
• Since, in this phase the code is produced so it is the main focus for
the developer.
• This is the longest phase of the software development life cycle.

SM KALISHA
Testing
• After the code is developed it is tested against the requirements to make
sure that the product is actually solving the needs addressed and gathered
during the requirements phase.
• During this phase all types of functional testing like unit testing,
integration testing, system testing, acceptance testing are done as well as
non-functional testing are also done.
• Functionality testing: is performed to verify that a software application
performs and functions correctly according to design specifications.
• Unit testing: a method by which individual units of source code are tested
to determine if they are fit for use.
• integration testing: tests integration or interfaces between components,
interactions to different parts of the system such as an operating system,
file system and hardware or interfaces between systems.
SM KALISHA
• System testing: testing the behavior of whole system/product is
tested as defined by the scope of the development project or
product.
• Acceptance testing: Acceptance testing is basically done by the user
or customer although other stakeholders may be involved as well
• The goal of acceptance testing is to establish confidence in the
system.
• Acceptance testing is most often focused on a validation type testing.
• non-functional testing the quality characteristics of the component
or system is tested.
• Non-functional refers to aspects of the software that may not be
related to a specific function or user action such as scalability or
security. Eg. How many people can log in at once?

SM KALISHA
Deployment
• Deployment: After successful testing the product is delivered /
deployed to the customer for their use.
• As soon as the product is given to the customers they will first do the
beta testing.
• If any changes are required or if any bugs are caught, then they will
report it to the engineering team.
• Once those changes are made or the bugs(errors) are
fixed(debugged) then the final deployment will happen.

SM KALISHA
Maintenance
• Once when the customers starts using the developed system then the
actual problems comes up and needs to be solved from time to time.
• This process where the care is taken for the developed product is
known as maintenance.

SM KALISHA
Algorithms and Procedures
• Algorithm: is a finite set of instructions(step by step instructions) for
performing a computation or solving a problem
• Procedure: A method for accomplishing a result such as solving a
problem or performing a task

• When mathematical equations are used, the description is called a


formula.

SM KALISHA
Pseudo-code
• Pseudo code is one of the tools that is used to write a preliminary
plan which is developed into a computer program.
• It is not a standard language, although programmers often use terms
within it that closely resemble the actual language to be used.
• Its purpose is to describe an algorithm in a form that can easily be
understood and then translated into the actual programming code
required.

SM KALISHA
Example pseudocode-1
Begin
ACCEPT number1, number2, number3
Sum:=number1 + number2 + number3
PRINT sum
End program

SM KALISHA
Example Pseudocode – 2
Use variables: number1, number2, number3, sum OF TYPE Integer
DISPLAY “Enter three numbers”
ACCEPT number1, number2, number3
sum:= number1 + number2 + number3
PRINT“The sum is ” sum
end program

SM KALISHA
Example Pseudocode – 3
Begin
use variables: length, width, perimeter, area OF TYPE integer
DISPLAY “Enter length and width of the rectangle”
• accept length, width
• perimeter = 2 * (length + width)
• area = length * width
• DISPLAY “The perimeter is” perimeter
• DISPLAY “The area is” area
• end program

SM KALISHA
Flowchart
• Diagrams may also be used to represent an algorithm.
• A flowchart is a type of diagram that represents an algorithm,
workflow or process
• This diagrammatic representation illustrates a solution model to a
given problem.
• Flowcharts are used in analyzing, designing, documenting or
managing a process or program in various fields.

SM KALISHA
Common flowchart symbols

SM KALISHA
Solution in form of a diagram (example pseudocode-2)

SM KALISHA

You might also like