0% found this document useful (0 votes)
32 views

Basic Computer Engineeting - Unit 2

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

Basic Computer Engineeting - Unit 2

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

Basic

Computer
Engineering
(BT-205)
Unit-2
Prof. Mahima Jain
Department of
Computer Science and
Engineering
Contents
 Algorithm
 Flowchart
 Complexities
 Introduction to Programming
 Categories of Programming Languages
 Program Design
 Characteristics or Concepts of OOP
 Procedure Oriented Programming VS

object oriented Programming


Algorithm

An algorithm is a well-defined procedure


that allows a computer to solve a problem.
 An algorithm includes calculations,

reasoning and data processing.


characteristics of a good
algorithm are:
 Precision – the steps are precisely
stated(defined).
 Uniqueness – results of each step are
uniquely defined and only depend on the
input and the result of the preceding steps.
 Finiteness – the algorithm stops after a
finite number of instructions are executed.
 Input – the algorithm receives input.

 Output – the algorithm produces output.

 Generality – the algorithm applies to a set

of inputs.
Example 1: Print 1 to 20:

Algorithm:

 Step 1: Initialize X as 0,
 Step 2: Increment X by 1,
 Step 3: Print X,
 Step 4: If X is less than 20 then go back to

step 2 else Exit.


Example 2: Calculate the
Interest of a Bank Deposit
Algorithm:

 Step 1: Read Principle amount,


 Step 2: Read years,
 Step 3: Read rate,
 Step 4: Calculate the interest with formula
"Interest=Amount*Years*Rate/100
 Step 5: Print interest,
Flowchart

 Flowchart is a graphical representation of


an algorithm.
 Programmers often use it as a program-
planning tool to solve a problem.
 It makes use of symbols which are
connected among them to indicate the flow
of information and processing.
 The process of drawing a flowchart for an

algorithm is known as “flowcharting”.


Basic Symbols used in
Flowchart Designs

1. Terminal:
 The oval symbol indicates Start, Stop and

Halt in a program’s logic flow.


 Terminal is the first and last symbols in the

flowchart.
2. Input/Output:

 A parallelogram denotes any function of


input/output type.

 Program instructions that take input from


input devices and display output on output
devices are indicated with parallelogram in
a flowchart.
3. Processing:

 A box represents arithmetic instructions. All


arithmetic processes such as adding,
subtracting, multiplication and division are
indicated by action or process symbol.
4. Decision :

 Diamond symbol represents a decision


point.
 Decision based operations such as yes/no

question or true/false are indicated by


diamond in flowchart.
5. Connectors:

Whenever flowchart becomes complex or it


spreads over more than one page, it is useful
to use connectors to avoid any confusions. It
is represented by a circle.
6. Flow lines:
 Flow lines indicate the exact sequence in
which instructions are executed.
 Arrows represent the direction of flow of
control and relationship among different
symbols of flowchart.
Example
Draw a flowchart to
input two numbers
from user and
display the largest
of two numbers.
Complexities

 Sometimes, there are more than one way to


solve a problem.
 We need to learn how to compare the

performance different algorithms and


choose the best one to solve a particular
problem.
 While analyzing an algorithm, we mostly

consider time complexity and space


complexity.
 Space complexity
◦ How much space is required
 Time complexity
◦ How much time is required to run the algorithm

Time and space complexity depends on lots of


things like hardware, operating system,
processors, etc.
 `
 we don't consider any of these factors while
analyzing the algorithm. We will only
consider the execution time of an algorithm.
 `
Introduction to Programming

 Program: Program is a set of instruction to


perform specific task.

 programming: It is the process of


developing and implementing set of
instruction to enable a computer to do a
certain task.

 For programming we are using different


types of programming languages.
Steps for Execution of a
program
At the time
compilation we
 Create a program may have
following Error

 Save the program 1. Syntax Error

2. Logical Error
 Compile the program
3. Runtime Error
 Run the program
Categories of Programming Languages

Machine C,C++, Java


Assembly SQL AI (LISP ,
Language Etc.
Language Prolog)
Low level Language
 It is a machine friendly language.
 Low level language is high memory efficient.
 It is tough to understand.
 It is complex to debug comparatively.
 It is complex to maintain comparatively.
 It is non-portable.
 It is machine-dependent.
 It needs assembler for translation.
High Level Language
 It is programmer friendly language.
 High level language is less memory efficient.
 It is easy to understand.
 It is simple to debug.
 It is simple to maintain.
 It is portable.
 It can run on any platform.
 It needs compiler or interpreter for translation.
Programming Paradigms

 A programming paradigm is a style, or


“way,” of programming.

 Paradigm can also be termed as method to


solve some problem or do some task.
 Programming paradigm is an approach to
solve problem using some programming
language or also we can say it is a method
to solve a problem using tools and
techniques that are available to us following
some approach.

 There are lots for programming language


that are known but all of them need to
follow some strategy when they are
implemented and this
methodology/strategy is paradigms.
Procedure Oriented Programming VS object
oriented Programming
Introduction to C++
 C++ (pronounced "see plus plus") is a programming
language began as an expanded version of C.

 The C++ were first invented by Bjarne Stroustrup in


1979 at Bell Laboratories in Murray Hill, New Jersey.

 Bjarne Stroustrup initially called the new language "C


with Classes." However, in 1983 the name was
changed to C++.
Benefits of C++ over C Language

Following features of C++ makes it a stronger


language than C

 There is Stronger Type Checking in C++.

 All the OOPS features in C++ like Abstraction,


Encapsulation, Inheritance etc makes it more
worthy and useful for programmers.

 C++ supports and allows user defined


operators (i.e Operator Overloading) and
function overloading is also supported in it.
 Exception Handling is there in C++.

 The Concept of Virtual functions and also


Constructors and Destructors for Objects.

 Inline Functions in C++ instead of Macros in C


language. Inline functions make complete
function body act like Macro, safely.

 Variables can be declared anywhere in the


program in C++, but must be declared before
they are used.
Character set in C++
 Character Set is the combination of
alphabets or characters, digits, special
symbols and white spaces.

 Character Set means that the characters


and symbols that a C++ Program can
understand and accept.
There are mainly four categories of
the character set

1) Alphabets : A,B,C…,a,b,c…

2) Digits : 0-9

3) Special Symbols : @#&*^

4) White Spaces :blank space, Horizontal tab space


What is Token In C++ ??
The Smallest Individual elements or units in a program are
called as Tokens.

Types of token

I. Keywords
II. Identifiers
III. Constants
IV. Operators
V. Special symbols
 Keywords:-

Keywords are the Special word which have predefine


meaning in C++ Library.
Ex. Break, continue, do, While etc..

 Identifier:-

An identifier is a name that is assigned by the user for a


program element such as variable, type, class,
function or namespace.
Rules for Identifiers:-

 Only alphabetic characters, digits and underscores are


permitted.
 First letter must be an alphabet or underscore (_).
 Identifiers are case sensitive.
 Reserved keywords can not be used as an identifier's
name.
Example:-

Abc valid identifier

A_bc valid identifier

1Abc invalid identifier

_Abc valid identifier

Abc&* invalid identifier


Constant:

Constants refers to fixed values that do


not change during the execution of a
program.
 Operator:-
operators as symbols that help us to perform specific
mathematical and logical computations on operands. In other
words we can say that an operator operates the operands.
Ex A+B
here ,
A, B are Operand
+ is a Operator
Types of operator
Operator Precedence
Data Types
Data type Defines type of Data.

There are three types of data type

1. Primitive Data Types: These data types are built-in


or predefined data types and can be used directly by the
user to declare variables. example: int, char , float, bool
etc.
 2. Derived Data Types: The data-types that are derived

from the primitive or built-in data types are referred to


as Derived Data Types Ex. Function, Array, Pointer,
Reference
 Abstract or User-Defined Data Types: These data types
are defined by user itself. Ex. Class, Structure
Union, Enumeration
Data type in C++

Derived data User define


Built-in data type
type data type

int Array class

float Function

char

void
Program Structure
Control statement
 To control the flow of Execution of programe
we are using control flow statement
 There are three types of control statement

1. Conditional control statement


2. Loop control statement
3. Jump statement
1. If
Conditional 2.If/else
Control 3. Nested
statement
if/else
4 Switch
Control 1. While
statement Loop Control 2. Do while
Statement 3. for

1. Break
Jump
2. Continue
statement
3. Go to
 Condition control statements :-
The Condition control statements are the
decision making statements that decides
the order of execution of statements based
on the conditions.

 Loop Control Statement:-


The loops are needed to execute a block of
code many of the times.
,
 Jump statements:- Jump statements cause an
unconditional jump to another statement elsewhere in
the code. They are used primarily to interrupt
switch statements and loops. The jump statements are
the goto statement, the continue statement, the
break statement.
Array
 Array is a collection of data having same
type

 Instead of declaring individual variables,


such as number0, number1, ..., and
number99, you declare one array variable
such as numbers and use numbers[0],
numbers[1], and ..., numbers[99] to
represent individual variables.
 In array data will be store on continuous
memory location.

 A specific element in an array is accessed


by an index.
Types of Array

 One Dimensional array(1-D array)

 Two Dimensional array (2-D array)

 Multi Dimensional array (M-D array)


Declaring Arrays:

One Dimensional Array


To declare an One Dimensional Array in C++, the
programmer specifies the type of the elements and the
number of elements required by an array as follows −

datatype arrayName [ arraySize ];


Ex. Int a[5]
Representation of 1-D Array

int a[7] Index Value


Number

a[0] a[1] a[2] a[3] a[4] a[5]


a[6]
1 2 5 4 6 9 7

100 101 102 103 104 105 106

Base
address
address
Two Dimensional Array
 An array of arrays is known as 2D array. The
two dimensional (2D) array in C++
programming is also known as matrix. A
matrix can be represented as a table of
rows and columns.
Representation of 2-D
Array
Datatype arrayname [Row] [column];
Ex. Int a[3][3];

Column index

0 1 2
A[0][0] A[0][1] A[0][2]
Row index

A[1][0] A[1][1] A[1][2]

A[2][0] A[2][1] A[2][2]


Function
 A function is block of code which is used to
perform a particular task.

Syntax:
return_type function_name (parameter_list)
{
//C++ Statements
}
Why do we need functions?
 Functions help us in reducing code redundancy.
If functionality is performed at multiple places
in software, then rather than writing the same
code, again and again, we create a function
and call it everywhere. This also helps in
maintenance as we have to change at one
place if we make future changes to the
functionality.
 Functions make code modular. Consider a
big file having many lines of codes. It
becomes really simple to read and use the
code if the code is divided into functions.
 Functions provide abstraction. For example,
we can use library functions without
worrying about their internal working.
Example
Types of Function
 Default Function: no parameter are there.

 Parameterised function: parameter is


passes to the function.
Characteristics or Concepts of OOP

 Object: it is a real world entity which have


attributes.
 Class: it is combination of data member and
member function.
 Encapsulation – Binding Capacity of Data
member and member function is known as
encapsulation.
 Inheritance- When the object of one class
acquires the property another class this
phenomenon is known as inheritance.
 Polymorphism- This is the ability to exist
in various forms. For example an operator
can be overloaded so as to add two integer
numbers and two floats.

 Abstraction- The ability to represent data


at a very conceptual level without any
details.

You might also like