0% found this document useful (0 votes)
35 views27 pages

CF0810 17102024 034051pm

Uploaded by

hammadgaming09
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)
35 views27 pages

CF0810 17102024 034051pm

Uploaded by

hammadgaming09
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/ 27

Programming Languages

• A programming language is a set of commands, instructions, and other


syntax use
to create a software program.
• Languages that programmers use to write code are called "high-level
languages."
• This code can be compiled into a "low-level language," which is recognized
directly by the computer hardware.
• High-level languages are designed to be easy to read and understand. Eg C+
+, Java, Perl, and PHP.
• Low-level languages include assembly and machine languages.
• An assembler can be used to translate the assembly code into machine code.
The
machine code, or machine language, contains a series of binary codes that
are
understood directly by a computer's CPU.
• Machine language is not designed to be human readable.
11/16/2024 Computing Fundamentals and C++ Programming 1
Translator Programs
• converts code from one computer language into another
• Converts to high level language to low level language
• Different types of translators are
Compiler-converts high level programming language to low level
programming language and stores in memory
Interpreter- Compiler-converts high level programming language to
low level programming language
Assembler- translate assembly language(low-level) into machine
language (lower level),translates low level language to lower level
language

11/16/2024 Computing Fundamentals and C++ Programming 2


• Difference between translator programs
Compiler Interpreter Assembler

• convert high-level • used to convert high-level • Translate assembly


programming language to programming language to language into machine
low-level programming low-level programming language
language language • Difficult to understand
• converts the whole • converts the program one • Low level language to lower
program in one session and line of code at a time and language level
reports errors detected reports errors when
after the conversion detected
• processor-dependent and • Interpreter is faster than a
platform-dependent. compiler as it immediately
• Takes time for conversion executes the code upon
reading the code.
• a debugging tool for
software development as it
can execute a single line of
code at a time
• Processor independent
11/16/2024 • Portable
Computing thanand
Fundamentals compiler
C++ Programming 3
Problem Solving Techniques
• Computer is used to solve the problem because it takes less
time than humans.
• Following are the steps to solve a problem
Analyze the problem
Divide the process in a series of elementary tasks
Formulate the algorithm to solve the problem
Express the algorithm in the form of program
Feed it in to computer
CPU interprets the given program, process the data and generates
the result.
Send the generated result to the output unit
• Algorithms and Flowcharts are the two problem solving
techniques.
11/16/2024 Computing Fundamentals and C++ Programming 4
Algorithms

Topdown
flowcharts approach of
algorithms
Problem
Solving
Techniques

Efficiency of
Program
an
verification
algorithm

11/16/2024 Computing Fundamentals and C++ Programming 5


Program
Planning
• To write a correct program, a
programmer must write each and
every instruction in the correct
sequence
• i.e. it should be ensured
that the instructions are
– Appropriate for the program &
– In the correct sequence

CFCP / Module I / AKN / 6


Representation of
Algo.
• As flowcharts
– Pictorial representation of an algorithm
• As Pseudo code
– Is an imitation of actual computer instruction. i.e. it
written in English language, but looks like a
program.
• As Program
– Represented in the form of a programming
language

CFCP / Module I / AKN / 7


Algorithm-
• Is a complete ,detailed, and precise step by step procedure to
solve a problem independently of the software or hardware of
the computer.
• It instructs the computer what specific steps need to perform
to solve a problem.

11/16/2024 Computing Fundamentals and C++ Programming 8


Algorithm 1: Add two numbers entered by the user
• Step 1: Start
• Step 2: Declare variables num1, num2 and sum.
• Step 3: Read values num1 and num2.
• Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
• Step 5: Display sum
• Step 6: Stop

11/16/2024 Computing Fundamentals and C++ Programming 9


Algorithm 2: Find the largest number among three numbers
• Step 1: Start
• Step 2: Declare variables a,b and c.
• Step 3: Read variables a,b and c.
• Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else If b > c
Display b is the largest number.
Else
Display c is the greatest number.
• Step 5: Stop
11/16/2024 Computing Fundamentals and C++ Programming 10
Top-down approach of algorithms-
• Also called as divide and conquer method.
• The problem is divided in to more sub problems and each of
which resembles the original problem.
• The solution of the sub problem is taken out independently
and combined together
• Eg Binary Search

11/16/2024 Computing Fundamentals and C++ Programming 11


Suppose we wish to search 38 in the array.
• Step 1: Find the middle element of the array.
• index(Middle) = index(low) + index(high – low)/2.
• Here, middle = 0 + (9-0)/2 = 4 i.e. the element at
the 4th index i.e. 25.

11/16/2024 Computing Fundamentals and C++ Programming 12


Step 2: Compare 38 with the middle element. 38 > 25 So, discard the
first half.
Step 3: Select the send half of the array. For the second half, low =
middle+1 as shown:

11/16/2024 Computing Fundamentals and C++ Programming 13


• Step 4: Find the middle element of this smaller array which
comes out to 32. Compare 38 with 32. 38 > 32 Thus, discard
the first half of this array.
• Step 5: Select the remaining half of the array by doing low =
middle+1 as shown:

• Finally, we have found 38 and thus the algorithm will halt


here.
11/16/2024 Computing Fundamentals and C++ Programming 14
Program Verification-
• Writing a program to perform a task and testing the program with different
examples.
• If the program gives correct result then it is verified that program is correct.

Efficiency of an algorithm-
• How fast the program produces the correct result
• It depends upon the two factors
• Time Complexity-running time of the program
• Space Complexity-memory taken by the program
• Space Complexity defines the amount of memory required by the
algorithm for the execution and generation of the output.
• Time Complexity refers to the amount of computer time required by an
algorithm for its execution.
• It includes both compile and runtime.
11/16/2024 Computing Fundamentals and C++ Programming 15
Analysis of algorithm-
• Determines the amount of resources such as time and memory(space) required for the
execution.
• Algorithm analysis provides theoretical estimates required by an algorithm to solve a
problem.
Asymptotic Analysis
• Performance of the algorithm based on the input size
• Relation between the running time and the input size
• Time and Space factor
Worst, Average and Best Cases
• Divided into three different cases
 Best Case(Ω) − minimum time taken to execute the program.
 Average Case(θ) − average time taken to execute the program.
 Worst Case(O) − maximum time taken to execute the program.
Asymptotic Notations
• Asymptotic notations are mathematical tools to represent the time complexity of algorithms for asymptotic
analysis.
 Ο (Big O) Notation
 Ω (Omega)Notation
 θ (Theta) Notation
11/16/2024 Computing Fundamentals and C++ Programming 16
Flowchart
Termina
sInput /
Processing
l
Output
Flow Lines
Decision

• Terminal Connectors
– Start or stop
• Processing
– Operations like add subtract etc.
• Flow ines
– Flow / sequence of operation.
• Connectors
– Required if the chart spreads over multiple
pages
Flowchart-
• Pictorial representation of the algorithm depicting the flow of
the various steps.
• Visualize the working of an algorithm

11/16/2024 Computing Fundamentals and C++ Programming 18


11/16/2024 Computing Fundamentals and C++ Programming 19
Example
Decision
Is I=10? No
A<B Compare A>B
A&B
Yes
Two – way A=B
Branching Three – way
I=? Branching

=0 =1 =2 =3 =4 = . . .
5
Multi – way
Branching
Example
(1)
• Find the % mark secured by a student, given all
marks
Start
Read mark
details
Add marks of all
subjects giving
total
Percentage =
total /
totalSubject
Print
percentage
Stop
Example
(2)
• Find the % mark secured by 50 students, given
all marks
Start
Counter = 1
Print
Read mark details percentage
of one student
Add 1 to
Add marks of all Counter
subjects giving
total NO
Is Counter > 50
Percentage =
total / yes
Stop
totalSubject
Flowchart
Guidelines
• Chart the main logic, then incorporate
detail
• Do not chart everything in the
chart. A consistent level of detail to
be maintained
• Names used should be prob.
Specific
• Crossing of flow lines may be
avoided
• Connectors may be leveled
Flowchart
advantages
• Better communication
• Proper program
documentation
• Efficient coding
• Systematic debugging
• Systematic testing
Flowchart
disadvantages
• Very time consuming and laborious to
draw
• Difficult to incorporate changes
• No standards available
determining the amount of detail
to be produced
Pseudoco
• deis written in an
Program logic
ordinary natural language
• Also called “Program Design
Language” (PDL)
• Basic Logic (control) Structure
– Sequence
• Sequence of execution
– Selection
• Decision (branching)
– Iteration
• Repetition (loop)
Pseudocode
• example
Counter =0
• Read first student record
• DO WHILE counter < 50
– Calculate totalMark
– percentage = totalMark /
totalSubject
– Print percentage
– Counter = counter + 1
– IF counter < 49
• Read next student record
– END IF
• ENDDO

You might also like