Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Programming Fundamentals 1

The document outlines the fundamentals of programming, including problem-solving steps, flowcharts, and algorithms. It explains different programming languages such as machine, assembly, and high-level languages, along with the role of translators like compilers and interpreters. Additionally, it highlights the differences between compilers and interpreters in terms of their functionality and performance.

Uploaded by

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

Programming Fundamentals 1

The document outlines the fundamentals of programming, including problem-solving steps, flowcharts, and algorithms. It explains different programming languages such as machine, assembly, and high-level languages, along with the role of translators like compilers and interpreters. Additionally, it highlights the differences between compilers and interpreters in terms of their functionality and performance.

Uploaded by

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

Programming

Fundamentals
Course Code: CS-312
Instructor: Muhammad Bilal
Introduction to Problem Solving
 Problem Solving means to solve problems
 Computers are used to solve various problems
 Thereare specific steps to be carried out to
solve problems in computer programming
 There are some steps to be followed to find the
solution:
 Analysing the problem
 Developing the algorithm
 Coding
 Testing and debugging
Flowchart
 Flowchart is a diagrammatic representation of an
algorithm
 A flowchart can be helpful for both writing programs and
explaining the program to others.
 Oval Symbol
 The oval symbol represents the start and end
 Rectangle Symbol
 The rectangle symbol shows the processing step
 Diamond Symbol
 A diamond represents a decision or branching point. Lines coming out from
the diamond indicates different possible situations, leading to different sub-
processes
 Parallelogram Symbol
 It represents information entering or leaving the system (input/output)
 Flow Lines
Flowchart Examples
Flowchart for input two numbers, adding the two
numbers and print the result
Flowchart Examples
Flowchart for checking the number, whether the
number is positive or negative
Algorithm
 Analgorithm is a procedure used for solving a
problem
 Algorithm acts as list of instructions for solving
a problem
 An algorithm is a well-defined sequential
computational technique that accepts a value
as input and produces the output(s) needed to
solve a problem.
 Algorithmsare set of instructions or rules that
guide the computer in performing a particular
task.
Algorithm
 Algorithmis language-independent, we write the
steps to demonstrate the logic used for solving a
problem.
 Example 1: algorithm to multiply 2 numbers and
print the result:
Step 1: Start
Step 3: Declare a, b, c variables.
Step 4: Take input for a from the user
Step 4: Take input for b from the user
Step 5: We need to multiply a and b variables so, c = a *
b
Step 6: Here we need to print the output. So write print c
Step 7: End
Algorithm
 Example 2: Write an algorithm to find the
average of 3 subjects:

Step 1: Start the Program


Step 2: Declare and Read 3 Subject, S1, S2, S3
Step 3: Calculate the sum of all the 3 Subject values
and store result in Sum variable (Sum = S1+S2+S3)
Step 4: Divide Sum by 3 and assign it to Average
variable.
(Average = Sum/3)
Step 5: Print the value of Average of 3 Subjects
Step 6: End of Solution
Introduction to Programming
 Programmers write instructions in various
programming languages, some directly
understandable by computers and others
requiring intermediate translation steps.
 There are three general types:
• Machine languages
• Assembly languages
• High-level languages
Introduction to Programming
 Machine Languages
 Anycomputer can directly understand only its
own machine language, defined by its hardware
design. Machine languages generally consist of
1s and 0s
 that
instruct computers to perform their most
elementary operations one at a time.
 Machine languages are machine-dependent—a
particular machine language can be used on
only one type of computer.
 Such languages are difficult for humans.
Introduction to Programming
 Assembly Languages
 Programming in machine language was simply too slow and
tedious for most programmers.
 Instead of using the strings of numbers that computers could
directly understand, programmers began using English-like
abbreviations to represent elementary operations. These
abbreviations formed the basis of assembly languages.
 Translator programs called assemblers were developed to
convert assembly-language programs to machine language
 The following section of an assembly-language payroll program
also adds overtime pay to base pay and stores the result in gross
pay:
load basepay
add overpay
store grosspay
 Although such code is clearer to humans, it’s incomprehensible to
Introduction to Programming
 High-Level Languages
 To speed the programming process, high-level languages were
developed in which single statements could accomplish
substantial tasks.
 Translator programs called compilers convert high-level-
language source code into machine language
 High-level languages allow you to write instructions that look
almost like everyday English and contain common
mathematical notations.
 A payroll program written in a high-level language might
contain a single statement such as
grossPay = basePay + overTimePay
 From the programmer’s standpoint, high-level languages are
preferable to machine and assembly languages.
 C is among the world’s most widely used high-level
Introduction to Programming
 Translator

A translator is a computer program that


converts the programming instructions into
machine language codes that the computers
understand and process.
 Types of translator
 Compilers

 Interpreters

 Assemblers
Introduction to Programming
 Compiler

The language translator program that translates


the complete source code into machine code as a
whole is called compiler
C/C++ languages use compilers
 Interpreter

The language translator program that translates


the source code into machine code statement by
statement.
 Assembler

The language translator program that translates


the program written in assembly language into
Introduction to Programming
 Difference between Compiler and Interpreter
• A compiler translates code from • An interpreter translates code
a high-level programming written in a high-level
language into machine code programming language into
before the program runs. machine code line-by-line as
• A compiler takes in the entire the code runs
program and requires a lot of • An interpreter translates the
time to analyze the source code when the program is
running.
code.
• Interpreter takes a single line
• Compiled code runs faster.
of code and very little time to
• A compiler displays all errors analyze it.
after compilation. If your code • Interpreted code runs slower.
has mistakes, it will not • Interpreter displays errors of
compile. each line one by one.
• The compiler is used by • Interpreter is used by
programming languages such programming languages such
as C, C++, C# as Python, PHP
Introduction to Programming
• Difference between Compiler and Interpreter

You might also like