OOPC Part1
OOPC Part1
Number System
Binary Number System [BNS] :- Bi means 2 so BNS consist of 2 digits 0 –1. A binary number
system is any combination of digits 0 and 1.
Example: 01, 00, 11, 100010001, 11001100, 11110000
Decimal Numbe r System [ DNS] :- Deci means 10 so DNS consist of ten digits 0 – 9. A
decimal number system is any combination of digits 0 to 9.
Example: 178, 234, 908, -99876
Octal Number System [ ONS] :- Octal means 8 so ONS consist of 8 digits 0 -7. An octal
number system is any combination of digits 0 to 7.
Example: 76, 75, 11, 123
Hexadecimal Numbe r System [HNS]:- Hexa means 6 and deci means 10 so HNS consist of 16
characters. 0 –9 and A-F
A=10, B=11, C=12, D=13, E=14, F=15
Eg. 76, 11, 01, 2A, 2FBC, AB12C
128 64 32 16 8 4 2 1
0 1 0 1 0 0 0 1
Amar Nayak
Object Oriented Programming in C++
128 64 32 16 8 4 2 1
1 0 0 1 1 0 1 1
1 0 0 1 1 0 1 1 binary is 155
decimal.
Memory units
Bits: Binary digits, 0 or 1
Nibble: Group of 4 bits
Byte: Group of eight bits.
Word: Group of 16/ 32 or 64 bits.
b represents Bit and B represents Byte.
Kilo bits (Kb): 1024 bits (1kb)
Kilo Byte (KB): 1024 byte (1KB)
Mega bits(Mb): 1kb * 1kb= 1024 * 1024 bits= 1mb
Mega byte(MB): 1KB * 1KB= 1024 * 1024 byte= 1MB
Giga bits (Gb) = 1024 * 1024 * 1024 bits = 1kb * 1kb * 1kb= 1mb*1kb
Giga byte (GB) = 1024 * 1024 * 1024 byte = 1KB * 1KB * 1KB= 1MB*1KB
Tera bits (Tb) = 1024 * 1024 * 1024 * 1024 bits = 1Kb*1Kb*1Kb*1Kb=1Mb*1Mb=1Gb
Tera Byte (TB) = 1024 * 1024 * 1024 * 1024 byte = 1KB*1KB*1KB*1KB=1MB*1MB=1GB
Amar Nayak
Object Oriented Programming in C++
Programming Languages
(1) First generation: Machine Language, Low Level Language, Binary Language :- [ LLL ]
(2) Second generation: Assembly Language:- [AL]
(3) Third generation: High Level Language: - [ HLL ]: C/C++/Java/PHP/Python
(4) Fourth generation language (4GL): [ HLL]: HTML, XML, SQL
(5) Fifth generation language (5GL) [HLL]: Artificial Intelligence: Prolog, LISP
(1) Machine Language : Machine Language is the language written by using 0’s and 1’s. The
computer only understands machine language.
Advantages of machine language:-
(1) It directly communicated with the internal circuitry.
(2) It is fast.
(2) Assembly Language :- In assembly language program are written in the form of English
abbreviations (Short form) is called mnemonics. The assembly language is machine dependent.
Advantages of AL
It is easy as compared to machine language.
Disadvantages
Machine dependent
It requires assembler to convert program written in AL to LLL which may
be costly.
Amar Nayak
Object Oriented Programming in C++
(3) High Level Language :- HLL is the language written using human understandable language
like English. HLL languages are easier to learn and use. It is machine independent language.
HLL can be run on many different computers with very little or no alternation.
A program written in HLL is called source program.
Example:
COBOL [COmmon Business Oriented Language]
FORTRAN [FORmula TRANslation]
C, C++, Java, C#, VB.NET, VB, Pascal, Scala, Julia, Kotlin, PHP, Go, Swift
Advantage of HLL
Simple
Portable
Limitation
It requires compiler or interpreter which may be costly.
(4) 4GL: In 4GL we have to only specify What to do? We don’t have to specify how to do?
HTML: Hypertext markup language
XML: Extensible markup language
SQL: Structured Query Language
Example in SQL:
Select * from students;
Delete from students where eno=10;
Example in HTML:
<html>
<head><title></title></head>
<body>
<h1>Welcome</h1>
<hr>
<img src=”myphote.jpg”></img>
</body>
</html>
(5) 5GL: 5GL are used specially for developing Artificial Intelligence program.
Example: LISP: LISt Processing
Prolog
Amar Nayak
Object Oriented Programming in C++
Compiler: -
A compiler is a system software program, which converts HLL program into machine language.
It converts entire program into machine language. It is fast.
Functions of compiler:-
(1) It translates the source program into machine language.
(2) During the translation process it looks for syntax error.
(3) The compiler reserve space for variables, arrays etc.
Inte rpreter:-
An interpreter is a system software program, which converts HLL program into machine
language.
It translates one by one statement written in HLL into machine language. It is slow.
The functions of interpreter are
(1) It translates the source program into machine language.
(2) During the translation process it looks for syntax error.
(3) The compiler reserve space for variables, arrays etc.
Assembler:-
AL Assembler Machine Language
Linker: -Linker is a system program which takes object code of a source program as input and
produces an executable code. The linker combines the code you wrote with the object code
already found in the standard library. This process is called linking.
Amar Nayak
Object Oriented Programming in C++
Introduction to C
C is a (middle level) high level programming language developed by Dennis Ritchie in
1972 at AT & T Bell labs at USA. C is also called middle level language because it
combines the features of high level language and machine language. As a HLL language
it gives the better programming efficiency i.e. faster program development. As a LLL it
gives better machine efficiency i.e. faster program execution.
Uses of c:-
(1) System programming:- For developing system program.
Example. For developing Operating System Example Unix, Linux, Win 95/98/NT/2000,
Sun solaris
For developing compiler, editors, interpreter
For developing device drivers for hardware’s.
(2) Database programming:- For developing databases.
Example. Oracle, SQLServer, MySQL, Informix, Sybase.
(3) Application Programming:- For developing application software.
Example Mathematical equations, Customer bill, banking
History of c:- Before the development of c each language is used for specific purpose. For
Example COBOL (Common Business Oriented Language) for co mmercial applications and
FORTRAN (Formula Translation) for Engineering and scientific applications. At this stage
people started thinking that instead of learning and using so many languages, each for a different
purpose why not use only one language, which can perform all possible applications. So they
developed c.
C is a general-purpose language. C is a structured language. The feature of a
structure language is compartmentalization of functions and data.
C offers better interaction with hardware.
Language history
Amar Nayak
Object Oriented Programming in C++
Introduction to C++
C++ is an object oriented, high level programming language. C++ is a cross-platform
language that can be used to create high-performance applications. C++ was
developed by Bjarne Stroustrup, as an extension to the C language. C++ gives
programmers a high level of control over system resources and memory.
The language was updated 3 major times in 2011, 2014, and 2017 to C++11, C++14,
and C++17.
C++ is a general-purpose programming language that was developed as an
enhancement of the C language to include object-oriented paradigm. It is an
imperative and a compiled language.
C++ is a middle- level language rendering it the advantage of programming low- level
(drivers, kernels) and even higher-level applications (games, GUI, desktop apps etc.).
The basic syntax and code structure of both C and C++ are the same.
Some of the features & key-points to note about the programming language are as
follows:
Simple: It is a simple language in the sense that programs can be broken down into
logical units and parts, has a rich libray support and a variety of data-types.
Amar Nayak
Object Oriented Programming in C++
Applications of C++:
C++ finds varied usage in applications such as:
Operating Systems & Systems Programming. e.g. Linux-based OS (Ubuntu etc.)
Browsers (Chrome & Firefox)
Graphics & Game engines (Photoshop, Blender, Unreal- Engine)
Database Engines (MySQL, MongoDB, Redis etc.)
Cloud/Distributed Systems
Some interesting facts about C++:
Here are some awesome facts about C++ that may interest you:
The name of C++ signifies the evolutionary nature of the changes from C. “++” is
the C increment operator.
C++ is one of the predominant languages for the development of all kind of technical
and commercial software.
C++ introduces Object-Oriented Programming, not present in C. Like other things,
C++ supports the four primary features of OOP: encapsulation, polymorphism,
abstraction, and inheritance.
C++ got the OOP features from Simula67 Programming language.
A function is a minimum requirement for a C++ program to run.(at least main()
function)
Amar Nayak
Object Oriented Programming in C++
C++ Fundamentals
Communicating with a computer involved speaking the language the computer understands.
Steps in learning C++ language:-
First we have to know what alphabets, numbers and special symbols are used in C++. Then using
these alphabets numbers and symbols how to construct instructions. And using these group of
instructions how to create a program.
Identifiers:- Identifiers are the name given to various program elements such as variables,
functions, classes, objects and arrays. Identifiers consist of letters and digits in any order except
that first character must be a letter. Both uppercase and lowercase are permitted. The underscore
(_) character can also be included. The keywords cannot be used for identifiers. We cannot use
special symbol as identifiers.
Valid identifiers:- a, a12,qm_1,_am_as,ATM,area,simple
Invalid Identifier:- 1a,*am, _a+c, a#,int, float.
Amar Nayak
Object Oriented Programming in C++
Keywords:- There are certain reserved words called keywords that are standard predefined
meaning in C++. There
Example: int, float, char, long, double, if, else, do, while, for, class, struct, virtual, etc.
Data:- Data is a collection of facts and figures which can be processed to produce information.
Raw information is called data.
Data is simple value or set of values.
Information: - When data is meaningful it is called information.
12 + 5 = 17
where 12 and 7 are data and 17 is information.
Data types: - A data type defines a set of values that a variable can store along with a set of
C has five basic types of data. Integer, floating point, character, double, void
Constant:- A constant is a quantity that doesn’t changes. This quantity can be stored at locations
in the memory of the computer.
C++ has four basic types of constants, integer constant, floating point co nstant, character
constant, string constants and Boolean constants.
C constants
Bool
(true/false) Numeric Character
Single String
Integer Float Character
Integer Constant:- is an integer value number. It consists of sequence of digits. Integer constant
can be written in 3 different ways.
(1) Decimal
(2) Octal
(3) Hexadecimal
Amar Nayak
Object Oriented Programming in C++
The Exponential form of representation of real constant is usually used if value of the
constant is either too small or too large.
In exponential form of representation the real constant is represented in two parts. The
part appearing before E is called mantissa whereas the part following E is called exponent.
Amar Nayak
Object Oriented Programming in C++
Data types: - A data type defines a set of values that a variable can store along with a set of
Data Types
Data Type Description Size in Bytes Range
Amar Nayak
Object Oriented Programming in C++
Separators
In C++ there are few characters that are used as separators. The most commonly used separator
in C++ is the semicolon (;). The other separators are
Symbol Name Purpose
() Parenthesis Used to contain lists of parameters in function
definition
and invocation. Also used for defining precedence
in expressions, containing expressions in control
statements, surrounding the casts.
{} Curly braces Used to contain the values of automatically
initialized
arrays. Also used to define a
block of statements, structure, functions and local
scopes.
[] Brackets Used to declare array types. Also used when
accessing an
array.
; Semicolon Terminates statements.
, Comma Separate identifiers in a variable declaration. Also
used to
chain statements together inside a for statement.
. Period Used to separate structure variable and structure
member.
Variables
A variable is a quantity, which may changes during the program execution. Variables names are
names given to the location in the memory of the computer where different constants are stored.
These locations may contain integer, real or character constant. All variables must be declared
before they can be used. Variable is a container for constants.
Types of variables
(1) int
(2) float
(3) char
Declaration-: All variables must be declared before they can be used. The general form of a
declaration is
datatype variable_list ;
Type must be a valid data type and variable list may consist of one or more identifier names
separated by commas.
Example
Amar Nayak
Object Oriented Programming in C++
int a,a1,axz;
Explanation:- a, a1, axz are the variables which stores integer type
of data.
float x,y,z;
Explanation:- x, y, z are the variables which stores float type of
data.
char p,q,r;
Explanation:- p, q, r are the variables which stores character type
of data.
By default a variable contain garbage value. If we have to give initial value to the variable then
we must initialize it.
Initialization of variables:- Initial values can be assigned to variables with a type declaration. We
can give variables a value as we declare them by placing an equal sign and a value after the
variable name.
The general form of initialization is
Data_type variable_name = value ;
(1) Initialization of integer variable:-
int a=10,b=20; a and b are integer variables which hold 10, 20 values.
(2) Initialization of float variable:-
float x=3.14 ,y=-12.8 ; x and y are float variables which hold 3.14 , -12.8 values.
(3) Initialization of character variable:-
char p=’*’ ,q=’2’ , r=’A’; p , q and r are character variables which hold * , 2 , A
values.
Editor
Compile
r
IDE
Debugger
Preprocessor
Linker
Amar Nayak
Object Oriented Programming in C++
Flowchart
Before solving a problem with the help of a computer it is necessary to plan the solution
in a step-by-step manner. Such a planning is represented symbolically with the help of flowchart.
A flowchart is a symbolic representation of the step-by-step solution of a given problem.
Flowchart indicates the flow of entire process, the sequence of data input, operations,
computations, decisions, and results. A flowchart is useful to understanding of the logical
structure of a problem and in documenting the method used.
Two types of flowchart:
(1) System flowcharts: are used by System Analysts to describe the data flow and
operations for a data processing. A system flowchart defines the processing in the organization.
(2) Program flowcharts: are used by programmers to describe the sequence of operations
and decisions for a particular problem.
The oval shaped symbol indicates the terminal points, i.e. the beginning or end of a flowchart.
The parallelogram symbol is used for input/output of data or information from/to any device, i.e.
it indicates the operation of reading and writing.
A diamond shaped symbol is used to indicate decisions (questions). The answer is yes/no.
The next step is depends upon answer of the question.
Escape Sequence:-
Certain non printing characters as well as the double quote ( “ ) , and backslash ( \ ) can be
expressed in terms of escape sequences. An escape sequence always begins with a back slash and
followed by one or more special characters.
The commonly used escape sequences are
Escape Sequence Meaning
\a Bell
\b Backspace
\t Horizontal Tab
\v Vertical tab
\n new line
\” Quotation mark
\\ Backslash
\0 Null
ASCII: - American Standard Code for Information Interchange. Most computers make use of
ASCII character set in which each individual character is numerically e ncoded with its own
unique ASCII value. There are 256 characters from 0-255.
Characters ASCII value.
A-Z 65-90
a-z 97-122
0-9 48-57
NULL 0
$ 36
Amar Nayak
Object Oriented Programming in C++
* 42
Comments:- Comments are explanatory remarks. Comments help to understand what the
complete program is about. Comments don’t affect the program execution and they can be
placed anywhere within a program. Comments are helpful in identifying the program principle
feature or in explaining logic of various program features. Comments are non-executable part.
Two types of comments in C++
// single line comment
/* Multiline
Comment
*/
Example.
/* This is a comment */
Expressions:- An expression represents a single data item such as a number or a character. The
expression may consist of a single entity such as a constant, a variable, an array element. It may
also consist of some combination of such entities interconnected by one or more operators.
Expression can also represent logical condition that are either true or false.
Example a+b, x=y, c=a+b, a<=y , x==y , ++j
Statements:- A statement tells the computer to carry out some action. The types of statements in
c are
(1) Expression (2) Compound (3) Control
Amar Nayak
Object Oriented Programming in C++
Ope rators
An operator is a symbol that causes mathematical or relational or logical operations to be
performed. The data items that operators act upon are called operands. Some operators require
two operands they are called binary operators. Some operators require one operand they are
called unary operators.
a+b
a and b are operands and + is an operator.
(1) Arithmetic Operators: are used for arithmetic operations. There are 5 arithmetic
operators in C++.
Operator Meaning
+ For addition
- For Subtraction
* For multiplication
/ For division
% Modulus or Remainder Operator (It
gives the remainder of its operand)
Modulus or remainder operator: (%) It returns remainder of integer division. The operands acted
upon by arithmetic operators must represent numeric values. Thus the operands can be
integer quantity, floating point quantity or characters. The remainder operator (%)
requires that both operands be integers and second operand be nonzero. Similarly, the
division operator (/) requires that the second operator be nonzero though the operands
need not be integers.
Division of one integer quantity by another is referred to as integer division. This
operation always results in a truncated quotient. On the other hand if a division operation
is carried out with two floating-point numbers, or with one floating-point number, the
result will be a floating-point quotient.
Amar Nayak
Object Oriented Programming in C++
(2) Relational Operator: are used to test or compare the value between two operands. The
relational operators produce an integer result to express the condition of the comparison.
If the condition is false then false keyword is used and if the condition is true then the
true keyword isused. There are six relational operators in C++
Operator Meaning
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal
The relational and logical operators are used to form logical expressions representing
conditions that are either true or false.
(4)Assignment Operator:
Assign the value of the expression on its right side to the variable on the variable
on its left side.
= Assignment operator
int a=5,b;
b=a;
This statement assign the value of a=5 to b. So b becomes 5.
If the two operands in an assignment expression are of different data types, then
the value of the expression on the right will automatically be converting to the type of the
identifier on the left.
Rules for assigning value
(1) A floating point value may be truncated if assigned to an integer variable (identifier).
(2) A double precision value may be rounded is assign to a floating point identifier.
(3) An integer quantity may be altered if assigned to shorter integer identifier, or to a
character variable.
Ex
int i;
float a=2.3,b=3.9,c=-3.9;
Expression value
i=a; 2
i=b; 3
i=c; -3
Amar Nayak
Object Oriented Programming in C++
(5)Logical operators: are used to combine two or more relations. The logical operators
act upon operands that are themselves logical expressions. The result of logical operators
is either true or false.
Operator Meaning
Logical AND (&&): The result of a logical AND operation will be true if both operands
are true.
Logical OR (||): The result of a logical OR operation will be true if either operand is true
or if both operands are true.
Logical NOT (!): Logical NOT negates the value o f logical expression. If the value of
expression is true than ! operator convert it to false and vice versa.
true -> flase
flase -> true
Output
input 1 input2 AND (&&) OR(||)
Expression Output
(i>=6) && (j>=2) true
(i>=6) && (j>=6) false
(i<10) && (j>2) true
(i<=7) && (j>=4) true
Amar Nayak
Object Oriented Programming in C++
(6) Increment and decrement operator: The increment operators increment its operand
by one (1) where as decrement operator decreases the value of its operand by one (1).
++ Increment operator
-- Decrement operator
i=5;
i=i+1 is equivalent to i++ =6
i=5;
i=i-1 is equivalent to i-- =4
Preincrement: If the increment operator precedes the operator (ex ++i) then it is
preincrement. In preincrement the operand will be altered in the value before it is used
within the program.
Postincrement: If the increment operator follows the operator (ex i++) then it is
postincrement. In postincrement the operand will be altered in the value after it is used
within the program
Predecrement: If the decrement operator precedes the operator (ex --i) then it is
predecrement. In predecrement the operand will be altered in the value before it is used
within the program.
Postdecrement: If the decrement operator follows the operator (ex i--) then it is
postdecrement. In postdecrement the operand will be altered in the value after it is used
within the program.
Amar Nayak
Object Oriented Programming in C++
Some applications required the manipulation of individual bits. Bitwise operator operates on bits.
Bitwise operator operates only on int and char type data.
&, |, ^ operators: Each of these operators requires two integer type operands. The operations are
carried out independently on each pair of corresponding bits within the operands The LSB within
the two operands will be compared, then next LSB and so on until all of the bits have been
compared.
(1) Bitwise AND (&) expression will return a 1 if both bits have a value 1 (i.e. both bits are
true.) otherwise it will return a value 0.
(2) Bitwise OR ( | ) expression will return a 1 if one or more of the bits have a value 1 (i.e.
one or both bits are true.) otherwise it will return a value 0.
(3) Bitwise XOR ( ^ ) expression will return a 1 if one of the bits have a value 1 and the
other has a value of 0(i.e. one bit is true and one bit is false.) otherwise it will return a
value 0.
If a and b represent the corresponding bits within the first and second operands, respectively
Amar Nayak
Object Oriented Programming in C++
0 0 0 0 0 1 0 1
answer is 5
Left Shift ( <<): This operator shifts its operand to the left. The number of position to be
shifted to the left is given by second operand.
Ex.
a=21;
a<<2;
21 is represented in binary as
0 0 0 1 0 1 0 1
0 1 0 1 0 1 0 0
answer is 84
Ex
Find Compliment of 4
Amar Nayak
Object Oriented Programming in C++
0 0 0 0 0 1 0 0
0 1 1 1 1 0 1 1
1 0 0 0 0 1 0 0
+ 1
------------------------------------------------------------
[1] 0 0 0 0 1 0 1
The answer is -5 .
Example:
Sizeof(int) 2 byte
Float b;
Sizeof(b); 4 bytes
- Unary minus -a
++ Increment a++
-- Decrement a--
! Not !(a>5)
~ One’s Compliment ~2 R-L
Amar Nayak
Object Oriented Programming in C++
* Multiplication a*b
/ Division a/b L-R
% Modulus a%b
| Bitwise OR a |b
&& Logical AND a>b && a>c
|| Logical OR i>4||j<6 L-R
?: Conditional Operator a>b ? 10 : 20
Amar Nayak
Object Oriented Programming in C++
Operators in the same box have the same precedence. Associativity determines order of
evaluation for operators with the same precedence For ex a=b=c;
Is evaluated right to left as a=(b=c);
Amar Nayak