0% found this document useful (0 votes)
74 views31 pages

Computer Programming: Instructor: Junaid Rashid Lab 1: Introduction To Computer Programming

Here are flowcharts for the previous examples: Example 1 (Add two numbers): Start Input number A Input number B A + B = Total Print Total End Example 2 (Calculate circle area): Start Input radius (R) Area = 3.14 * R * R Print Area End Example 3 (Sum of first 50 natural numbers): Start Sum = 0 N = 0 N <= 50? Yes Sum = Sum + N N = N + 1 No Print Sum End

Uploaded by

ahmad hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views31 pages

Computer Programming: Instructor: Junaid Rashid Lab 1: Introduction To Computer Programming

Here are flowcharts for the previous examples: Example 1 (Add two numbers): Start Input number A Input number B A + B = Total Print Total End Example 2 (Calculate circle area): Start Input radius (R) Area = 3.14 * R * R Print Area End Example 3 (Sum of first 50 natural numbers): Start Sum = 0 N = 0 N <= 50? Yes Sum = Sum + N N = N + 1 No Print Sum End

Uploaded by

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

Computer Programming

Instructor: Junaid Rashid


Lab 1: Introduction to computer Programming
What is this course about
 Introduction and Background..
 Environment and IDES.
 Types of operators and uses.
 About Variables and Constants.
 Control Statements.
 Loops
 Functions
 Structures
 Arrays.
 Pointers.
 Oop(Object Oriented Programing)
 Basic Introduction about classes.
Marks Distribution

 Total Marks 100


 Terminal 50
 Mid 30
 Assignments & Quizzes 20
Assignments 10 ( 4 assignments)
Quiz 10 ( 4 quizzes)
Agenda
 What is Computer
 Computer Organization
 Computer Programing Languages
 What is Program
 How to solve a program
 Problem Solving Techniques
 Algorithm
 Examples of Algorithm
What is a Computer?
 Computer
 Device capable of performing computations and making logical
decisions
 Computer programs
 Sets of instructions that control computer’s processing of data
 Hardware
 Various devices comprising computer
 Keyboard, screen, mouse, disks, memory, CD-ROM, processing
units, …
 Software
 Programs that run on computer
Computer Organization
 Six logical units of computer
1. Input unit
 “Receiving” section
 Obtains information from input devices
 Keyboard, mouse, microphone, scanner, networks, …

2. Output unit
 “Shipping” section
 Takes information processed by computer
 Places information on output devices
 Screen, printer, networks, …
 Information used to control other devices
 Six logical units of computer
3. Memory unit
 Rapid access, relatively low capacity “warehouse” section
 Retains information from input unit
 Immediately available for processing

 Retains processed information


 Until placed on output devices

 Memory, primary memory


4. Arithmetic and logic unit (ALU)
 “Manufacturing” section
 Performs arithmetic calculations and logic decisions
 Six logical units of computer
5. Central processing unit (CPU)
 “Administrative” section
 Supervises and coordinates other sections of computer
6. Secondary storage unit
 Long-term, high-capacity “warehouse” section
 Storage
 Inactive programs or data

 Secondary storage devices


 Disks

 Longer to access than primary memory


 Less expensive per unit than primary memory
Computer Programming Languages
 Programmers write programs/instructions in various
programming languages – some easier for the computer to
understand and some easier for the programmer to
understand.
 Machine languages
 Assembly languages
 High-level languages
1. Machine language
 Only language computer directly understands
 “Natural language” of computer
 Defined by hardware design
 Machine-dependent
 Generally consist of strings of numbers
 Ultimately 0s and 1s
 Instruct computers to perform elementary operations
 One at a time
 Cumbersome for humans
 Example:
+11000111
+1100111
2. Assembly language
 English-like abbreviations representing elementary computer
operations
 Clearer to humans
 Incomprehensible to computers
 Translator programs (assemblers)
 Convert to machine language
 Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
3. High-level languages
 Similar to everyday English, use common mathematical notations
 Single statements accomplish substantial tasks
 Assembly language requires many instructions to accomplish
simple tasks
 Translator programs (compilers)
 Convert to machine language
 Interpreter programs
 Directly execute high-level language programs
 Example:
grossPay = basePay + overTimePay
What is Program
 A computer program is a collection of
instructions that performs a specific task
when executed by a computer.
 A computer requires programs to function
and typically executes
the program's instructions in a central
processing unit.
Why we write a program

 For solving a problem.


 For example:
 Write a program to add two numbers
 So

How to solve this problem?


Solving Problem
 Problem solving is a process of identifying a
problem and finding the best solution for it.
 One problem may be solve in different ways. one
solution may be faster, less expensive and more
reliable than others.
 It is important to select the best suitable solution.
Problem Solving Techniques

 Different strategies techniques and tools are used to solve


a simple/complex problem in computer.
 Techniques are :
Algorithm

Flowchart

Program
Algorithm & Pseudo code
 Step by step procedure to solve a problem is called an algorithm
 Properties:
 The giving problem should be broken down into simple and
meaningful steps.
 The steps should be numbered sequentially.
 The steps should be descriptive and written in simple English.
 There is no standard to write a pseudo code.
 Pseudo is separating it into two main parts.
 Logic Design
 Coding
Logic Design & Coding

Logic Design:
In this part the logic of the program is designed. We specify the
different steps required to solve the problem.
 Coding
 In this part the algorithm is converted into a program.
 The steps of algorithm are translated into instructions of any
programming language.
Example:

Write an algorithm that inputs two


numbers, calculates sum and then
display the result on the screen.
Algorithm
1. Start
2. Input A
3. Input B
4. Total = A+B
5. Display Total
6. Exit
Examples 2
 Write an algorithm to take input radius
from the user and calculate the area of
circle.
(hint: Area=3.14*radius*radius)
Algorithm

  Start

 Take R (Note: R is Radius)


 Area =
 Display Area
 End
Example 3

Write an algorithm to find the


sum of first fifty natural
numbers.
Algorithm
1. Start
2. Sum=0
3. N=0
4. Repeat step 5 and 6 while(N<=50)
5. Sum = Sum + N
6. N=N+1
7. Print Sum
8. End
Assignment

 Writean algorithm to perform all mathematical


operation on two numbers
Hint: Mathematical Operations are +, -, *, /.
Flow Chart
 An organized combination of shapes, lines, and
text that graphically illustrates a process or
structure
 A pictorial representation showing all of the steps
of a process
Basic Flowchart Shapes and Definitions

Start / End Project / Task Input / Output

The start or end of a Process or action. Data: Inputs to, and outputs
workflow. from, a process.

Split Decision Document


or
Merge

Upright indicates a process split, Document or


Decision point in a report.
inverted indicates a merge of
process or workflow.
processes.

Off Page
Manual Connector
Connector
Input

Prompt for information, Connector used to connect


manually entered into a Used to connect one part one page of a flowchart to
system. of a flowchart to another. another.
What does a flowchart look like?

 The pseudo code from the previous slide would look like this as a
flowchart:

Start
Print answer
Get 2 numbers
End
Add them
Another Sample: Calculating Age
 Pseudo code:
 Start

 Get year born


 Calculate age
 Print age
 If age > 50 print OLD
 End
Another Sample: Calculating Age
Start

Get yr
 Flowchart
 Start Calc age

 Get year born


Print age
 Calculate age
 Print age
OLD Y Age>50?
 If age > 50 print OLD
N
 End
End
Assignment

 Make Flowchart of all previous Examples.

You might also like