0% found this document useful (0 votes)
76 views40 pages

CO-101 Lec 1 & 2 - Introduction

The document discusses an introduction to programming fundamentals course. It covers topics like the evaluation scheme, syllabus, problem solving through algorithms and pseudocode, flowcharts and their symbols. Examples of algorithms and flowcharts for different problems are provided. Programming languages and their types - low level and high level - are also introduced.

Uploaded by

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

CO-101 Lec 1 & 2 - Introduction

The document discusses an introduction to programming fundamentals course. It covers topics like the evaluation scheme, syllabus, problem solving through algorithms and pseudocode, flowcharts and their symbols. Examples of algorithms and flowcharts for different problems are provided. Programming languages and their types - low level and high level - are also introduced.

Uploaded by

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

Introduction

UNIT 1

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Evaluation Scheme

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


About the Syllabus

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Programming Task
A typical programming task can be divided into two phases:
1. Problem solving phase
a. produce an ordered sequence of steps that describe solution of
problem
b. this sequence of steps is called an algorithm
2. Implementation phase
a. implement the program in some programming language

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Steps in Problem Solving
● First produce a general algorithm (one can use
pseudocode)
● Refine the algorithm successively to get step by step
detailed algorithm that is very close to a computer
language.
● Pseudocode is an artificial and informal language that
helps programmers develop algorithms. Pseudocode is
very similar to everyday English.
CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU
Pseudocode & Algorithm
Example 1: Write an algorithm to determine a
student’s final grade and indicate whether it is
passing or failing. The final grade is calculated as
the average of four marks.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Pseudocode & Algorithm
Pseudocode:

Input a set of 4 marks

Calculate their average by summing and dividing by 4

if average is below 50

Print “FAIL”

else

Print “PASS”

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Pseudocode & Algorithm
Detailed Algorithm
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

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


The Flowchart
A graphical representation of the sequence of operations in a program.

Program flowcharts show the sequence of instructions in a single program or


subroutine. Different symbols are used to draw each type of flowchart.

A Flowchart

● shows logic of an algorithm


● emphasizes individual steps and their interconnections
● e.g. control flow from one action to the next

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart Symbols
Basic

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Example

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Example 2
Write an algorithm and draw a flowchart to convert the length in feet to
centimeter.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Example 2
Write an algorithm and draw a flowchart to convert the length in feet to
centimeter.

Pseudocode:

● Input the length in feet (Lft)


● the length in cm (Lcm) by multiplying LFT with 30
● Print length in cm (LCM)

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Example 2
Flowchart

Algorithm

● Step 1: Input Lft


● Step 2: Lcm Lft x 30
● Step 3: Print Lcm

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Example 3
Write an algorithm and draw a flowchart that will read the two sides of a
rectangle and calculate its area.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Example 3
Write an algorithm and draw a flowchart that will read the two sides of a
rectangle and calculate its area.

Pseudocode

● Input the width (W) and Length (L) of a rectangle


● Calculate the area (A) by multiplying L with W
● Print A

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Example 3
Algorithm

Step 1: Input W,L

Step 2: A L x W

Step 3: Print A

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowcharts
● Flowcharts is a graph used to depict or show a step by step
solution using symbols which represent a task.
● The symbols used consist of geometrical shapes that are
connected by flow lines.
● It is an alternative to pseudocoding; whereas a pseudocode
description is verbal, a flowchart is graphical in nature.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart Symbols

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart Symbols cont…

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart – sequence control structure

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart – selection control structure

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart – repetition control structure

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart – example 1

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Flowchart – example 2

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Exercises: Algorithm & Flowchart
Write an algorithm and draw a flowchart that will calculate the roots of
a quadratic equation

Hint: d = sqrt ( ), and the roots are: x1 = (–b + d)/2a and


x2 = (–b – d)/2a

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Exercises: Algorithm & Flowchart
1.) Create an algorithm and a flowchart that will accept/read two numbers and
then display the bigger number.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Exercises: Algorithm & Flowchart
2.) Create an algorithm and a flowchart that will compute the area of a circle.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Exercises: Algorithm & Flowchart
3.) Create an algorithm and a flowchart that will compute the sum of two
numbers. If the sum is below or equal to twenty, two numbers will be entered
again. If the sum is above 20, it will display the sum.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Assignment 1
1. Create an algorithm and a flowchart that will output for g.c.d.
2. Create an algorithm and a flowchart that will output the factorial of a
given number.
3. Create an algorithm and a flowchart that will output the Fibonacci series
up to a given number.
4. Create an algorithm and a flowchart that will output all the prime
numbers between 2 numbers.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Introduction to Programming Languages

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Programming Language
A programming language is a formal language comprising a set of instructions
that produce various kinds of output. Programming languages are used in
computer programming to implement algorithms.

Program: A program is a set of instructions given to a computer to perform a


specific operation.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Why learn programming?
Can boost problem solving and logic skills

● Teaches us combine technical skills and creativity.


● Improves interpersonal skills.
● Can lead to software development jobs
● Helps us understand how software works

Software= program + documentation (source code/ requirement specification


documentation/ software design document, test plans, user manuals etc)

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Types of Programming Languages
There are two types of programming languages, which can be
categorized into the following ways:
1. Low level language
2. High level language

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Low level languages
a) Machine Language
● Consists of strings (combination of characters) of binary numbers (i.e. 0s and
1s)
● 011000111 1111000110
● It is the only one language, the processor directly understands.
b) Assembly Language
● Programmer requires detailed knowledge of hardware specification.
● This language uses mnemonics code in place of 0s and 1s.
● ADD,MUL, MOV, POP/PUSH.. (comp ogra, microprocessor)
● The program is converted into machine code by assembler. The resulting
program is referred to as an object code.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


High level language
Instructions of this language closely resembles to human language.
● Uses mathematical notations to perform the task.
● Easier to learn.
● Requires less time to write and is easier to maintain the errors.
● Converted into machine language by one of the two different
languages translator programs; interpreter or compiler.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Difference between Compiler and Interpreter
Compiler Interpreter
The compiler scans the whole program in one go. Translates the program one statement at a time.

As it scans the code in one go, the errors (if any) are shown Considering it scans code one line at a time, errors are
at the end together. shown line by line.

The main advantage of compilers is its execution time. Due to interpreters being slow in executing the object code,
it is preferred less.

Execution of the program takes place only after the whole Execution of the program happens after every line is
program is compiled. checked or evaluated.

Compilers more often take a large amount of time for In comparison, Interpreters take less time for analyzing the
analyzing the source code. source code.

C, C++, C#, etc are programming languages that are Python, Ruby, Perl, SNOBOL, MATLAB, etc are
compiler-based. programming languages that are interpreter-based.

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


C - Programming Language
● Created in 1972 to write operating systems (Unix in particular)
○ By Dennis Ritchie
○ Bell Labs
● Evolved from B
● Can be portable to other hardware (with careful design – use
Plauger’s The Standard C Library book)
● Built for performance and memory management – operating
systems, embedded systems, real-time systems, communication
systems

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


Later Languages
1979 C++ by Bjarn Stroustrup also at Bell

● Object orientation

1991 Java by Sun

● Partial compile to java bytecode: virtual machine code


● Write once, run anywhere
● Memory manager – garbage collection
● Many JVMs written in C / C++

CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU


CO-101 Programming Fundamentals Kavinder Singh, Assistant Professor, CSE, DTU

You might also like