SlideShare a Scribd company logo
Introduction to Programming
(CS1123)
By
Dr. Muhammad Aleem,
Department of Computer Science,
Mohammad Ali Jinnah University, Islamabad
Fall 2013
What is a Computer?
• A computer is a electro-mechanical device that
works semi-automatically to process input data
according to the stored set of instructions and
produces output or resultant data.
A Computer
System
Instructions
Data
Results
Components of a Computer System
Main Memory
CPU
Arithmetic and Logic Unit
Control Unit
Computer
Peripheral Devices / Connected devices
Keyboard Mouse Display CD Rom Hard Disk
Computer Instructions and Programs
• Instruction: A computer instruction is a command
or directive given to a computer to perform
specific task.
Examples: Add 2 and 5, Print “Hello World”
• Program: A program is sequence of instructions
written in programming language that directs a
computer to solve a problem
Examples: Draw a square, etc.
Computer Instructions and Programs
• Program “Draw a square”
1 – Draw a vertical line of length n inches
2 – Draw a horizontal line of n inches
3– Draw a vertical line of length n inches
4 – Draw a horizontal line of n inches
Computer Software System
Operating Systems
(Windows, Linux, MAC, Solaris)
Compilers / Libraries
(C++, C, Java)
Application Programs
(.cpp, .c, .java,)
Computer Hardware
Programming Languages
• Classification of programming languages:
1. Machine language
2. Low-level languages
3. High-level languages
1. Machine level languages
• A computer understands only sequence of bits or 1’s
and 0’s (the smallest piece of information)
• A computer program can be written using machine
languages (01001101010010010….)
• Very fast execution
• Very difficult to write and debug
• Machine specific (different codes on different
machines)
2. Low level languages
• English encrypted words instead of codes (1’s and
0’s)
• More understandable (for humans)
• Example: Assembly language
• Requires: “Translation” from Assembly code to
Machine code
compare:
cmpl #oxa,n
cgt end_of_loop
acddl #0x1,n
end_of_loop:
1001010101001101
1110010110010100
0101010111010010
0110100110111011
1101100101010101
Assembler
Assembly Code Machine Code
3. High level languages
• Mostly machine independent
• Close to natural language (English like language
keywords)
• Easy to write and understand programs
• Easy to debug and maintain code
• Requires compilers to translate to machine code
• Slower than low-level languages
3. High level languages
• Some Popular High-Level languages
– COBOL (COmmon Business Oriented Language)
– FORTRAN (FORmula TRANslation)
– BASIC (Beginner All-purpose Symbolic Instructional Code)
– Pascal (named for Blaise Pascal)
– Ada (named for Ada Lovelace)
– C (whose developer designed B first)
– Visual Basic (Basic-like visual language by Microsoft)
– C++ (an object-oriented language, based on C)
– Java
Programming Paradigms
• Programming paradigm is the fundamental
style of computer programming
1. Imperative
2. Functional
3. Logical
4. Object Oriented
Imperative Paradigm
• Machine based modes (Sequence of steps
required to compute)
• Statements executed sequentially step-wise
• Emphasis on How is to compute
• How to obtain the required results or output
• Example languages: C, Pascal, Ada, etc.
Imperative Paradigm Languages
Functional/Logical Paradigm
• Specify what is to be computed using
programming abstractions.
• Responsibility of a programmer is to specify What
is to compute
• How to compute is implementation dependent
and is managed by language compiler
• Example languages: Lisp, Scheme, Erlang, Haskell,
Scala etc.
Object-Oriented Paradigm
• Programming with Abstract Data Types, to model
real world
• Basic Program Unit: Class (a programmer defined
type)
– A entity that contains data and methods which work
on the data
• Basic Run-time Unit: Object
– Instance of a class during execution
Problem Solving Steps
1. Understand the problem
2. Plan the logic
3. Code the program
4. Test the program
5. Deploy the program into production
1. Understanding the Problem
• Problems are often described in natural language
like English.
• Users may not be able to specify needs well, and
the needs may changing frequently
• Identify the requirements
1. Inputs or given data-items
2. Required output(s) or desired results
3. Indirect inputs (may not be given directly, you
have to calculate or assume)
1. Understanding the Problem
– Example: Calculate the area of a circle having
the radius of 3 cm
• Inputs:
– Radius=3
• Output:
– Area
• Indirect Inputs:
– Pi=3.14
– Area = 3.14 * (3*3) = 28.27
2. Plan the Logic
• Identify/Outline small steps in sequence, to
achieve the goal (or desired results)
• Tools such as flowcharts and pseudocode can be
used:
1. Flowchart: a pictorial representation of the logic
steps
2. Pseudocode: English-like representation of the logic
• Walk through the logic before coding
3. Code the Program
• Code the program:
–Select the programming language
–Write the program instructions in the selected
programming language
–Use the compiler software to translate the
program into machine understandable code or
executable file
–Syntax errors (Error in program instructions) are
identified by the compiler during compilation
and can be corrected.
4. Test the Program
• Testing the program
–Execute it with sample data and check the
results
–Identify logic errors if any (undesired results
or output) and correct them
–Choose test data carefully to exercise all
branches of the logic (Important)
5. Deploy the Program
• Putting the program into production
–Do this after testing is complete and all known
errors have been corrected
Introduction to Pseudocode
• One of the popular representation based on
natural language
• Widely used
–Easy to read and write
–Allow the programmer to concentrate on the
logic of the problem
• Structured in English language (Syntax/grammar)
What is Pseudocode (continued...)
• English like statements
• Each instruction is written on a separate line
• Keywords and indentation are used to signify
particular control structures.
• Written from top to bottom, with only one
entry and one exit
• Groups of statements may be formed into
modules
Some Basic Constructs
• Print  Output is to be sent to the Printer
• Write  Output is to be written to a file
• Display  Output is to be written to the screen
• Prompt  required before an input instruction
Get, causes the message to be sent to the screen
• Compute /Calculate  Calculation performed by
computer
• Calculation operations: +, -, *, /, ()
Some Basic Constructs
• Set  Used to set inital value,
E.g., Set Marks to 0
• =  Place values from right hand-side item to left
hand side
E.g., Marks = 67
• Save  Save the variable in file or disk
E.g., Save Marks
Comparison/Selection
IF student_Marks are above 50 THEN
Result = “Pass“
ELSE
Result = “Fail“
ENDIF 
• Making decision by comparing values
•
• Keywords used:
•IF, THEN, ELSE
IF student_Marks are above 50 THEN
Result = “Pass“
ELSE
Result = “Fail“
ENDIF
Comparison/Selection
CASE of <condition-variable>
Case <valueA>
Do Step1
Case <valueB>
Do Step2
Case <valueC>
Do Step3
ENDCASE
• Case Strtucture
 Multiple banching based on value of condition
• Three keywords used:
• CASE of, Case, ENDCASE
Comparison/Selection
• Case Strtucture
 Example...
Repeat a group of Statements
DOWHILE student_total < 50
Read student record
Print student name
Add 1 to student_total
ENDDO
• Repeating set of instruction base on some condition
• Keyword used:
•DOWHILE, ENDDO
Example Pseudocode Program
• A program is required to read three
numbers, add them together and print their
total.
Inputc Processing Output
Number1
Number2
Number3
total
Solution Algorithm
Add_three_numbers
Set total to 0
Read number1
Read number2
Read number3
Total = number1 + number2 + number3
Print total
END
Repeat Until (Loop)
• Repeat-Until statement (loop)
REPEAT
Do StepA
Do StepB
UNTIL conditionN is True
- What is the Difference between (While & Repeat) ?
Example:…
Flowcharts
• “A graphic representation of a sequence of
operations to represent a computer program”
• Flowcharts show the sequence of instructions in a
single program or subroutine.
A Flowchart
• A Flowchart
– Shows logic of an algorithm or problem
– Shows individual steps and their interconnections
– E.g., control flow from one action to the next
Name Symbol Description
Oval Beginning or End of the Program
Parallelogram Input / Output Operations
Rectangle Processing for example, Addition,
Multiplication, Division, etc.
Diamond
Denotes a Decision (or branching)
for example IF-Then-Else
Arrow
Denotes the Direction of logic
flow
Flowchart Symbols
Example 1
Step 1: Input M1,M2,M3,M4
Step 2: GRADE = (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
START
Input
M1,M2,M3,M4
GRADE(M1+M2+M3+M4)/4
IS
GRADE<50
STOP
YN
Print
“FAIL”
Print
“PASS”
Example 2
• Write an algorithm and draw a flowchart to
convert the length in feet to centimeter.
Example 2
Algorithm
• Step 1: Read Lft
• Step 2: Lcm = Lft x 30
• Step 3: Print Lcm
Flowchart
START
Read Lft
Lcm = Lft x 30
STOP
Print LCM
Example 3
• Write an algorithm and draw a flowchart that will read
the two sides of a rectangle and calculate its area.
Example 3
Algorithm
• Step 1: Read W,L
• Step 2: A = L x W
• Step 3: Print A
START
Read
W, L
A  L x W
STOP
Print
A
DECISION STRUCTURES
• The expression A>B is a logical expression
• It describes a condition we want to test
• if A>B is true (if A is greater than B) we take the action
on left
• Print the value of A
• if A>B is false (if A is not greater than B) we take the
action on right
• Print the value of B
IF–THEN–ELSE STRUCTURE
• The algorithm for the flowchart is as follows:
If A>B then
print A
Else
print B
endif
is
A>B
Y N
Print A Print B
• Multiple branching based on a single condition
CASE STRUCTURE
CASE
Condition
Do Step A Do Step B Do Step C Do Step D
Relational / Logical Operators
Relational Operators
Operator Description
> Greater than
< Less than
= Equal to
 Greater than or equal to
 Less than or equal to
 Not equal to
Example 4
• Write an algorithm that reads two values, finds largest
value and then prints the largest value.
ALGORITHM
Step 1: Read VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX  VALUE1
else
MAX  VALUE2
endif
Step 3: Print “The largest value is”, MAX
-- DRAW the Flow Chart for the Program
Selection Structure
• A Selection structure can be based on
1. Dual-Alternative (two code paths)
2. Single Alternative (one code path)
is
A>B
Y N
Print A Print B
Dual Alternative Example 
Selection Structure
• Single Alternative Example
Pseudocode: IF GPA is greater than 2.0 Then
Print “Promoted ”
End IF
GPA
> 2.0
N Y
Print
“Promoted”
Loop Structure
• Repetition (WHILE structure)
– Repeats a set of actions based on the answer to a
question/condition
pseudocode: DoWHILE <Some-True-Condition>
Do Something
ENDDO
Loop Structure
• REPEAT-UNTIL structure
– Repeats a set of actions until a condition remains True
– pseudocode: REPEAT
Do-Something
UNTIL <Some True Condition>

More Related Content

What's hot

Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- Python
PriyankaC44
 
Unit 1 psp
Unit 1 pspUnit 1 psp
Unit 1 psp
Karthi Vel
 
Program Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State UniversityProgram Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State University
Reggie Niccolo Santos
 
Algorithms
AlgorithmsAlgorithms
Algorithms
Liam Dunphy
 
STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2
Bro Shola Ajayi
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to Programming
Chaffey College
 
Computer programming and utilization
Computer programming and utilizationComputer programming and utilization
Computer programming and utilization
Digvijaysinh Gohil
 
algorithm
algorithmalgorithm
algorithm
kokilabe
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1
deathful
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
praveena p
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
Online
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
Prabu U
 
Basics of python
Basics of pythonBasics of python
Basics of python
JayaShukla23
 
Ch0 computer systems overview
Ch0 computer systems overviewCh0 computer systems overview
Ch0 computer systems overview
AboubakarIbrahima
 
Flowcharts
FlowchartsFlowcharts
Flowcharts
cassandra0012345
 
Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)
Umair Younas
 
Part II: Assembly Fundamentals
Part II: Assembly FundamentalsPart II: Assembly Fundamentals
Part II: Assembly Fundamentals
Ahmed M. Abed
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
Trivuz ত্রিভুজ
 
L1
L1L1
Lecture 4
Lecture 4Lecture 4
Lecture 4
Anshumali Singh
 

What's hot (20)

Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- Python
 
Unit 1 psp
Unit 1 pspUnit 1 psp
Unit 1 psp
 
Program Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State UniversityProgram Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State University
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to Programming
 
Computer programming and utilization
Computer programming and utilizationComputer programming and utilization
Computer programming and utilization
 
algorithm
algorithmalgorithm
algorithm
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Ch0 computer systems overview
Ch0 computer systems overviewCh0 computer systems overview
Ch0 computer systems overview
 
Flowcharts
FlowchartsFlowcharts
Flowcharts
 
Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)
 
Part II: Assembly Fundamentals
Part II: Assembly FundamentalsPart II: Assembly Fundamentals
Part II: Assembly Fundamentals
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
L1
L1L1
L1
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 

Similar to Cs1123 2 comp_prog

Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
TeddyDaka
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentals
SasidharaRaoMarrapu
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
Sangheethaa Sukumaran
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
Kirti Verma
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
MIT,Imphal
 
algorithms and flow chart overview.pdf
algorithms and flow chart overview.pdfalgorithms and flow chart overview.pdf
algorithms and flow chart overview.pdf
AmanPratik11
 
Lecture-1.pptx . this is about the computer program
Lecture-1.pptx . this is about the computer programLecture-1.pptx . this is about the computer program
Lecture-1.pptx . this is about the computer program
MuhammadUsmanYaseen2
 
Programming logic &practices
Programming logic &practices Programming logic &practices
Programming logic &practices
HABEEBRAHMANKALATHIL
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptx
miansaad18
 
Lecture1
Lecture1Lecture1
Lecture1
Andrew Raj
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
TadiwaMawere
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
Chaya64047
 
UNIT-111.pptx
UNIT-111.pptxUNIT-111.pptx
UNIT-111.pptx
JALLAANITHAREDDY
 
Computer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module iComputer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module i
Ajit Nayak
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
ManoRanjani30
 
Computer Programming Computer Programming
Computer Programming Computer ProgrammingComputer Programming Computer Programming
Computer Programming Computer Programming
arifhasan88
 
AlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdfAlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdf
SusieMaestre1
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
baabtra.com - No. 1 supplier of quality freshers
 
Cse
CseCse

Similar to Cs1123 2 comp_prog (20)

Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentals
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
algorithms and flow chart overview.pdf
algorithms and flow chart overview.pdfalgorithms and flow chart overview.pdf
algorithms and flow chart overview.pdf
 
Lecture-1.pptx . this is about the computer program
Lecture-1.pptx . this is about the computer programLecture-1.pptx . this is about the computer program
Lecture-1.pptx . this is about the computer program
 
Programming logic &practices
Programming logic &practices Programming logic &practices
Programming logic &practices
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptx
 
Lecture1
Lecture1Lecture1
Lecture1
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
 
UNIT-111.pptx
UNIT-111.pptxUNIT-111.pptx
UNIT-111.pptx
 
Computer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module iComputer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module i
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
 
Computer Programming Computer Programming
Computer Programming Computer ProgrammingComputer Programming Computer Programming
Computer Programming Computer Programming
 
AlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdfAlgorithmAndFlowChart.pdf
AlgorithmAndFlowChart.pdf
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
 
Cse
CseCse
Cse
 

More from TAlha MAlik

Data file handling
Data file handlingData file handling
Data file handling
TAlha MAlik
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
TAlha MAlik
 
Cs1123 11 pointers
Cs1123 11 pointersCs1123 11 pointers
Cs1123 11 pointers
TAlha MAlik
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operations
TAlha MAlik
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
TAlha MAlik
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
TAlha MAlik
 
Cs1123 4 variables_constants
Cs1123 4 variables_constantsCs1123 4 variables_constants
Cs1123 4 variables_constants
TAlha MAlik
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
Cs1123 1 intro
Cs1123 1 introCs1123 1 intro
Cs1123 1 intro
TAlha MAlik
 
Cs1123 9 strings
Cs1123 9 stringsCs1123 9 strings
Cs1123 9 strings
TAlha MAlik
 

More from TAlha MAlik (12)

Data file handling
Data file handlingData file handling
Data file handling
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
 
Cs1123 11 pointers
Cs1123 11 pointersCs1123 11 pointers
Cs1123 11 pointers
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operations
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
 
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
 
Cs1123 7 arrays
Cs1123 7 arraysCs1123 7 arrays
Cs1123 7 arrays
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
 
Cs1123 4 variables_constants
Cs1123 4 variables_constantsCs1123 4 variables_constants
Cs1123 4 variables_constants
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Cs1123 1 intro
Cs1123 1 introCs1123 1 intro
Cs1123 1 intro
 
Cs1123 9 strings
Cs1123 9 stringsCs1123 9 strings
Cs1123 9 strings
 

Recently uploaded

GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 

Recently uploaded (20)

GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 

Cs1123 2 comp_prog

  • 1. Introduction to Programming (CS1123) By Dr. Muhammad Aleem, Department of Computer Science, Mohammad Ali Jinnah University, Islamabad Fall 2013
  • 2. What is a Computer? • A computer is a electro-mechanical device that works semi-automatically to process input data according to the stored set of instructions and produces output or resultant data. A Computer System Instructions Data Results
  • 3. Components of a Computer System Main Memory CPU Arithmetic and Logic Unit Control Unit Computer Peripheral Devices / Connected devices Keyboard Mouse Display CD Rom Hard Disk
  • 4. Computer Instructions and Programs • Instruction: A computer instruction is a command or directive given to a computer to perform specific task. Examples: Add 2 and 5, Print “Hello World” • Program: A program is sequence of instructions written in programming language that directs a computer to solve a problem Examples: Draw a square, etc.
  • 5. Computer Instructions and Programs • Program “Draw a square” 1 – Draw a vertical line of length n inches 2 – Draw a horizontal line of n inches 3– Draw a vertical line of length n inches 4 – Draw a horizontal line of n inches
  • 6. Computer Software System Operating Systems (Windows, Linux, MAC, Solaris) Compilers / Libraries (C++, C, Java) Application Programs (.cpp, .c, .java,) Computer Hardware
  • 7. Programming Languages • Classification of programming languages: 1. Machine language 2. Low-level languages 3. High-level languages
  • 8. 1. Machine level languages • A computer understands only sequence of bits or 1’s and 0’s (the smallest piece of information) • A computer program can be written using machine languages (01001101010010010….) • Very fast execution • Very difficult to write and debug • Machine specific (different codes on different machines)
  • 9. 2. Low level languages • English encrypted words instead of codes (1’s and 0’s) • More understandable (for humans) • Example: Assembly language • Requires: “Translation” from Assembly code to Machine code compare: cmpl #oxa,n cgt end_of_loop acddl #0x1,n end_of_loop: 1001010101001101 1110010110010100 0101010111010010 0110100110111011 1101100101010101 Assembler Assembly Code Machine Code
  • 10. 3. High level languages • Mostly machine independent • Close to natural language (English like language keywords) • Easy to write and understand programs • Easy to debug and maintain code • Requires compilers to translate to machine code • Slower than low-level languages
  • 11. 3. High level languages • Some Popular High-Level languages – COBOL (COmmon Business Oriented Language) – FORTRAN (FORmula TRANslation) – BASIC (Beginner All-purpose Symbolic Instructional Code) – Pascal (named for Blaise Pascal) – Ada (named for Ada Lovelace) – C (whose developer designed B first) – Visual Basic (Basic-like visual language by Microsoft) – C++ (an object-oriented language, based on C) – Java
  • 12. Programming Paradigms • Programming paradigm is the fundamental style of computer programming 1. Imperative 2. Functional 3. Logical 4. Object Oriented
  • 13. Imperative Paradigm • Machine based modes (Sequence of steps required to compute) • Statements executed sequentially step-wise • Emphasis on How is to compute • How to obtain the required results or output • Example languages: C, Pascal, Ada, etc.
  • 15. Functional/Logical Paradigm • Specify what is to be computed using programming abstractions. • Responsibility of a programmer is to specify What is to compute • How to compute is implementation dependent and is managed by language compiler • Example languages: Lisp, Scheme, Erlang, Haskell, Scala etc.
  • 16. Object-Oriented Paradigm • Programming with Abstract Data Types, to model real world • Basic Program Unit: Class (a programmer defined type) – A entity that contains data and methods which work on the data • Basic Run-time Unit: Object – Instance of a class during execution
  • 17. Problem Solving Steps 1. Understand the problem 2. Plan the logic 3. Code the program 4. Test the program 5. Deploy the program into production
  • 18. 1. Understanding the Problem • Problems are often described in natural language like English. • Users may not be able to specify needs well, and the needs may changing frequently • Identify the requirements 1. Inputs or given data-items 2. Required output(s) or desired results 3. Indirect inputs (may not be given directly, you have to calculate or assume)
  • 19. 1. Understanding the Problem – Example: Calculate the area of a circle having the radius of 3 cm • Inputs: – Radius=3 • Output: – Area • Indirect Inputs: – Pi=3.14 – Area = 3.14 * (3*3) = 28.27
  • 20. 2. Plan the Logic • Identify/Outline small steps in sequence, to achieve the goal (or desired results) • Tools such as flowcharts and pseudocode can be used: 1. Flowchart: a pictorial representation of the logic steps 2. Pseudocode: English-like representation of the logic • Walk through the logic before coding
  • 21. 3. Code the Program • Code the program: –Select the programming language –Write the program instructions in the selected programming language –Use the compiler software to translate the program into machine understandable code or executable file –Syntax errors (Error in program instructions) are identified by the compiler during compilation and can be corrected.
  • 22. 4. Test the Program • Testing the program –Execute it with sample data and check the results –Identify logic errors if any (undesired results or output) and correct them –Choose test data carefully to exercise all branches of the logic (Important)
  • 23. 5. Deploy the Program • Putting the program into production –Do this after testing is complete and all known errors have been corrected
  • 24. Introduction to Pseudocode • One of the popular representation based on natural language • Widely used –Easy to read and write –Allow the programmer to concentrate on the logic of the problem • Structured in English language (Syntax/grammar)
  • 25. What is Pseudocode (continued...) • English like statements • Each instruction is written on a separate line • Keywords and indentation are used to signify particular control structures. • Written from top to bottom, with only one entry and one exit • Groups of statements may be formed into modules
  • 26. Some Basic Constructs • Print  Output is to be sent to the Printer • Write  Output is to be written to a file • Display  Output is to be written to the screen • Prompt  required before an input instruction Get, causes the message to be sent to the screen • Compute /Calculate  Calculation performed by computer • Calculation operations: +, -, *, /, ()
  • 27. Some Basic Constructs • Set  Used to set inital value, E.g., Set Marks to 0 • =  Place values from right hand-side item to left hand side E.g., Marks = 67 • Save  Save the variable in file or disk E.g., Save Marks
  • 28. Comparison/Selection IF student_Marks are above 50 THEN Result = “Pass“ ELSE Result = “Fail“ ENDIF  • Making decision by comparing values • • Keywords used: •IF, THEN, ELSE IF student_Marks are above 50 THEN Result = “Pass“ ELSE Result = “Fail“ ENDIF
  • 29. Comparison/Selection CASE of <condition-variable> Case <valueA> Do Step1 Case <valueB> Do Step2 Case <valueC> Do Step3 ENDCASE • Case Strtucture  Multiple banching based on value of condition • Three keywords used: • CASE of, Case, ENDCASE
  • 31. Repeat a group of Statements DOWHILE student_total < 50 Read student record Print student name Add 1 to student_total ENDDO • Repeating set of instruction base on some condition • Keyword used: •DOWHILE, ENDDO
  • 32. Example Pseudocode Program • A program is required to read three numbers, add them together and print their total. Inputc Processing Output Number1 Number2 Number3 total
  • 33. Solution Algorithm Add_three_numbers Set total to 0 Read number1 Read number2 Read number3 Total = number1 + number2 + number3 Print total END
  • 34. Repeat Until (Loop) • Repeat-Until statement (loop) REPEAT Do StepA Do StepB UNTIL conditionN is True - What is the Difference between (While & Repeat) ? Example:…
  • 35. Flowcharts • “A graphic representation of a sequence of operations to represent a computer program” • Flowcharts show the sequence of instructions in a single program or subroutine.
  • 36. A Flowchart • A Flowchart – Shows logic of an algorithm or problem – Shows individual steps and their interconnections – E.g., control flow from one action to the next
  • 37. Name Symbol Description Oval Beginning or End of the Program Parallelogram Input / Output Operations Rectangle Processing for example, Addition, Multiplication, Division, etc. Diamond Denotes a Decision (or branching) for example IF-Then-Else Arrow Denotes the Direction of logic flow Flowchart Symbols
  • 38. Example 1 Step 1: Input M1,M2,M3,M4 Step 2: GRADE = (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4 IS GRADE<50 STOP YN Print “FAIL” Print “PASS”
  • 39. Example 2 • Write an algorithm and draw a flowchart to convert the length in feet to centimeter.
  • 40. Example 2 Algorithm • Step 1: Read Lft • Step 2: Lcm = Lft x 30 • Step 3: Print Lcm Flowchart START Read Lft Lcm = Lft x 30 STOP Print LCM
  • 41. Example 3 • Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area.
  • 42. Example 3 Algorithm • Step 1: Read W,L • Step 2: A = L x W • Step 3: Print A START Read W, L A  L x W STOP Print A
  • 43. DECISION STRUCTURES • The expression A>B is a logical expression • It describes a condition we want to test • if A>B is true (if A is greater than B) we take the action on left • Print the value of A • if A>B is false (if A is not greater than B) we take the action on right • Print the value of B
  • 44. IF–THEN–ELSE STRUCTURE • The algorithm for the flowchart is as follows: If A>B then print A Else print B endif is A>B Y N Print A Print B
  • 45. • Multiple branching based on a single condition CASE STRUCTURE CASE Condition Do Step A Do Step B Do Step C Do Step D
  • 46. Relational / Logical Operators Relational Operators Operator Description > Greater than < Less than = Equal to  Greater than or equal to  Less than or equal to  Not equal to
  • 47. Example 4 • Write an algorithm that reads two values, finds largest value and then prints the largest value. ALGORITHM Step 1: Read VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX  VALUE1 else MAX  VALUE2 endif Step 3: Print “The largest value is”, MAX -- DRAW the Flow Chart for the Program
  • 48. Selection Structure • A Selection structure can be based on 1. Dual-Alternative (two code paths) 2. Single Alternative (one code path) is A>B Y N Print A Print B Dual Alternative Example 
  • 49. Selection Structure • Single Alternative Example Pseudocode: IF GPA is greater than 2.0 Then Print “Promoted ” End IF GPA > 2.0 N Y Print “Promoted”
  • 50. Loop Structure • Repetition (WHILE structure) – Repeats a set of actions based on the answer to a question/condition pseudocode: DoWHILE <Some-True-Condition> Do Something ENDDO
  • 51. Loop Structure • REPEAT-UNTIL structure – Repeats a set of actions until a condition remains True – pseudocode: REPEAT Do-Something UNTIL <Some True Condition>