You are on page 1of 43

Programming Fundamental

Muhammad Zia Ul Haq


Course Outline
1. Introduction to Programming
2. Algorithms and Pseudo code (With Practice)
3. Flowcharts (With Practice)
4. Program Development Process
5. Programming Languages types
6. Types of code
7. Language Processors
8. Programming Techniques
9. Use of Tools(TC, VS Code, Visual Studio)
10. Programming in C++
11. Standards of Input & Output
12. Conditional Structure
13. Looping Structure
14. Arrays
15. Structures
16. Functions
17. Pointers (Basic Introduction)
18. String Handling (Basic Introduction)
Semester Evaluation
• Quiz (Oral + Written)
• Class/ Lab Activity
• Assignments
• Mid Exam
• Presentations
• Practical Exam
• Viva
• Final Exam
Major Objective this course
The objective of this course are to make the student understand
programming language, programming, concepts of loops,
reading a set of data, stepwise refinement, Function, Control
structures, Arrays. After completion of this course the student
is expected to analyze the real life problem and write a
program in ‘C/C++’ language to solve the problem.

The main emphases of the course will on problem solving aspect,


i,e., developing proper algorithms.

At the end of the course the students will be able to:


 Develop efficient algorithms for solving a problem.
 Use the various constructs of a programming language viz.,
conditional, iteration and recursion.
 Implement the algorithm in ‘C/C++’ language.
Introduction to Programming
General Concepts

A good program should have the following


characteristics:
1. Readability
2. Efficiency
3. Reliability
4. Meaningfulness
5. Portability
6. User-friendly.
Problem Solving
Problem solving is a process of identifying a problem and
finding the best solution for it.
Problem solving is a skill that can be developed by
following a well organized approach. We solve different
problems every day. Every problem is different in its
nature. Some problems are very difficult and require more
attention to identify the solution. A problem may be
solved in different ways.
 Program Algorithm
 Flowchart
 Program
etc
Program
A set of instructions that tells a computer what
to do is called program.
A computer works according to the given
instructions in the program. Computer programs
are written in programming languages.
A person who develops a program is called
programmer.
Programmer uses programming languages or
tools to write programs.
Advantages of Computer Program
Different advantages of computer program are as follows:
1. A computer program can solve many problems by
giving instructions to computer.
2. A computer program can be used to perform a task
repeatedly and quickly.
3. A program can process a large amount of data easily.
4. It can display the results in different styles.
5. The processing of a program is more efficient and less
time consuming.
6. Different types of programs are used in different fields
to perform certain tasks.
Algorithms & Pseudo Code
• An algorithm is a step-by-step procedure to solve
a problem.
• The process of solving a problem becomes
simpler and easier with help of algorithm. It is
better to write algorithm before writing the
actual computer program.
Examples of Algorithms & Pseudo Code
Example#1
Write a C++ algorithm to write a program to add
two numbers.
Solution:
• Start
• Accept num1, num 2
• Sum= num1+ num2
• Display sum
• Stop
Examples of Algorithms & Pseudo Code
Example#02
The following algorithm inputs radius from the user
and calculates the area of circle.
(Hint: Area = 3.14 * radius * radius)
Solution:
1.Start
2.Input radius in r
3. area = 3.14 *r*r
4.Print area
5. End
Advantage of Algorithm
1. Reduce Complexity
2. Increase Flexibility
3. Easy to Understand
Assignment # 01
(Part-1)
Assignment # 01
Question # 01:
Write an algorithm calculates the distance covered by a car
moving at an average speed of V m/s in time T. It should
input average speed v and time t.
(Hint: s= vt where s is the distance traveled).
Question # 02:
Write an algorithm finds the sum of first fifty natural numbers.
Due Date: 17-02-2023
Time: During Next Lecture
Medium: Printed form
Tool: MS Word
Flow Chart
Flowchart is combination of two words flow and chart.

A chart consists of different symbols to display information about any


program.

Flow indicates the direction of processing that takes place in the


program.

Flowchart is a graphical representation of an algorithm. It is a way of


visually presenting the flow of data, operations performed on data and
sequence of these operations.

Similarly, a programmer prefers to design the flowchart before writing


the program. Flowchart is designed according to the defined rules.
Flowchart Symbol
Understand This?
Example # 01
Draw the flowchart that represents the steps for adding
two numbers.
Assignment # 01
(Part-2)
Question # 03:
Draw the flowchart that represents the steps of
an algorithm that inputs marks of a student. If
marks are 40 or more, it displays "Pass".
Otherwise it displays "Fail".
Question # 04:
Draw the flowchart that finds the sum of first 50
natural numbers.
Due Date: 17-02-2023 (Next Lecture)
Time: During Next Lecture
Medium: Printed form
Tool: MS Word
Program Development Process
1. Defining and Analyzing Problem
2. Designing the Algorithm
3. Coding or Writing the Program
4. Testing Program
5. Final Documentation
Defining and Analyzing Problem
In this step, a programmer studies the problem. He
decides the best way to solve this problem. Studying a
problem is necessary because it helps a programmer to
following things.

 The facts and figures which are necessary for developing


the program.
 The way in which the program will be designed.
 The language in which the program will be most suitable.
 What is the desired output and in which form it is
needed, etc.
Designing the Algorithm
An algorithm is a sequence of steps that must be
carried out before a programmer starts
preparing his program. The programmer designs
an algorithm to help visualize possible
alternatives in a program.
Coding or Writing the Program
The process of writing a program is a very
important step in program development. In this
step, an algorithm is converted into program.
The program consists of different steps given in
the algorithm. A large number of programming
languages are available to write programs. A
programmer selects programming language
according to the nature of problem.
Testing Program
A program must be tested in the process of program
development. This process verifies the accuracy of a
program. The program is tested by executing it again
and again. Different values are given as input and
output is checked. The program may not give
required results if it contains any error. The errors
must be detected and corrected if the output is not
correct. All bugs in the program are detected and
removed during program testing. It ensures that the
program gives desired results and the problem is
solved correctly.
Final Documentation
When the program is finalized, its documentation
is prepared. Final documentation is provided to
the user. It guides the user how to use the
program in the most efficient way. Another
purpose of documentation is to allow some other
programmer to modify the code if necessary.
Documentation should be done in each step
during development of a program.
Programming Languages
A set of words, symbols and codes used to write programs is
called program language. Different programming languages
are available for writing different types of programs. Some
languages are specially used for writing business programs,
other are used for writing scientific programs etc.

There are two type of languages


1. Low Level Languages
1.1 Machine Language
1.2 Assembly Language
2. High Level Languages
2.1 Procedural Language
2.2 Object Oriented Language
2.3 Non-Procedural Language
Low Level Language
These languages are near to computer hardware
and far from human languages. Computer can
understand these languages easily. Writing a
program in low-level languages requires a deep
knowledge of the internal structure of computer
hardware.
Two low-level languages are machine language
and assembly language.
Machine Language
A type of language in which instructions are written in
binary form is called machine language. It is the only
language that is directly understood by the fundamental
language of the computer. It is the computer. It
Program written in machine language can be executed
very fast by the computer. Programs written in machine
language are machine-dependent. Every computer has
its own machine language. Machine language is difficult
to understand. Writing and modifying program in
machine language takes a lot of time. Machine language
is also known as first generation language.
Assembly Language
Assembly language is a low-level language. It is one
step higher than machine language. In assembly
language, symbols are used instead of binary code.
These symbols are called mnemonics. Assembly
language is also called symbolic language.
Programs written in assembly language are easier
to write and modify than machine language.
Assembly language is mostly used for writing
system software. Assembly language is also known
as second generation language.
High Level Language
A type of language that is close to human languages is
called high level language. High-level languages are easy to
understand. Instructions of these languages are written in
English-like words such as input and print etc. A program
written in high-level language is easier to write and modify.

High-level languages are further divided into following


categories:
1. Procedural Languages
2. Object-Oriented Languages
3. Non-Procedural Languages
Procedural Languages
Procedural languages are also known as third-
generation languages or 3GL. In these
languages, program is a predefined set of
instructions. Computer executes these
instructions in the same sequence in which the
instructions are written. Each instruction in this
language tells the computer what to do and how
to do.
Some most popular procedural languages
1. FORTRAN
FORTRAN stands for FORmula TRANslation. It is mainly used
for engineering application and scientific use.
2. BASIC
BASIC stands for Beginner All Purpose Symbolic Instruction
Code. It was created in the late 1960. It was used mainly by
students to use the computer for solving simple problems. It is
easy to understand. It is widely used for education purpose.
3. COBOL
COBOL stands for Common Business Oriented Language. It is
specially designed for business application. It was developed in
early 1960s. The programs written in COBOL are lengthy but
easy to read, write and maintain.
Some most popular procedural languages
4. PASCAL
This language is used for both scientific and business
applications. Its name was assigned in the honor of a
French mathematician Pascal.
5. C
C language is a popular high-level language. It was
developed by Dennis Ritchie at AT&T Bell
Laboratories in 1972. It was written as part of UNIX
operating system. It is also known as middle-level
language because it provides the facilities to write
application software as well as system software.
Object-Oriented Languages(OOP)
OOP is a technique in which programs are
written on the basis of objects.
An object is a collection of data and functions.
Object may represent a person, thing or place in
real world.
Object oriented programs are easier to learn and
modify. C++ & Java are popular object-oriented
languages.
C++
C++ is an object-oriented language. It was
developed in 1980 at Bell Laboratories. It is an
improved version of C language. It provides the
facility of working with objects and classes. It is
very powerful language and is used to develop a
variety of programs.
Java
Java is a high-level language. It was designed by
Sun Microsystems. It provides powerful
capabilities of network programming, Internet
applications and user interface (GUI).
Features of OOP
Objects: OOP provides the facility of programming based on
objects. Object is an entity that consists of data and
functions.
Classes: Classes are designs to create objects. OOP provides
facility to design classes to create different objects.
Properties and functions of objects are specified in classes.
Reusability: OOP provides ways to reuse data and code.
Inheritance is a technique that allows a programmer to use
code of existing program to create new programs.
Information Hiding: OOP allows the programmer to hide
important data from the user. It is performed by
encapsulation.
Polymorphism: Polymorphism is an ability of an object to
behave in multiple ways.
Non-Procedural Languages
Non-procedural languages are also known as
fourth generation languages or 4GL.
In non-procedural languages, user only needs to
tell the computer "what to do" not "how to do".
It is also known as an applicative or functional
language.
SQL
SQL stands for Structured Query Language. It is
the most popular database query language. SQL
was developed by IBM.
It is a national standard by the American
National Standards Institute (ANSI). SQL works
with database programs like MS Access,
DB2,Informix, MS SQL Server, Oracle, Sybase,
etc.
RPG
RPG stands for Report Program Generator. It
was developed in early 1960s by IBM. It is used
to generate business reports. It is a
nonprocedural language. It is mostly used with
IBM mid-range computers.
End of Lecture

You might also like