OBJRCT OREINTED PROGRAMING, Summaries of C programming

9IHDS8H0HU[98OJOFEQ98H8FDST DS9DS 9UDSP FDQ9UB DS9B [DUNBDSA AD NB FEQU

Typology: Summaries

2025/2026

Uploaded on 02/01/2026

ashobou-chesno
ashobou-chesno 🇬🇧

3 documents

1 / 97

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
OBJECT ORIENTED PROGRAMMING
DIGITAL NOTES
B.TECH
(
II SEM)
(201
8
-
1
9
)
DEPARTMENT OF
CSE & IT
MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY
Autonomous Institution
(
UGC, Govt. of India)
Recognized
under 2(f) and 12 (B) of UGC ACT 1956 (Affiliated to JNTUH, Hyderabad, Approved by AICTE
-
Accredited by NBA & NAAC
‘A’ Grade
-
ISO 9001:2015 Certified) Maisammaguda, Dhulapally (Post Via.
Hakimpet), Secunderabad
500100
, Telangana State, India
.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61

Partial preview of the text

Download OBJRCT OREINTED PROGRAMING and more Summaries C programming in PDF only on Docsity!

OBJECT ORIENTED PROGRAMMING

DIGITAL NOTES

B.TECH

(I YEAR – II SEM)

DEPARTMENT OF CSE & IT

MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY

( Autonomous Institution – UGC, Govt. of India)

Recognized under 2(f) and 12 (B) of UGC ACT 1956 (Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO 9001:2015 Certified) Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100 , Telangana State, India.

I Year B.Tech II SEM L T/P/D C 4 1/-/- 3

(R18A0502)OBJECT ORIENTED PROGRAMMING

Objectives To teach the student the concepts of object oriented and procedure programming To differentiate between functions, classes and objects To learn to overload functions and operators To design applications using dynamic memory management techniques To teach the student to implement generic programming and exception handling

Unit I

Introduction to Object Oriented Programming: Object oriented paradigm-Differences between Object Oriented Programming and Procedure oriented programming, Basic concepts of Object Oriented Programming, Encapsulation, Inheritance and Polymorphism, Benefits of OOP, Structure of a C++ program, namespace, Data types, C++ tokens, Identifiers, Variables, Constants, Operators, Control structures & Loops.

Unit-II

Functions, Classes and Objects: Introduction of Classes, Class Definition, Defining a Members,Objects,Access Control, Class Scope, Scope Resolution Operator, Inline functions, Memory Allocation for Objects, Static Data Members, Static Member Functions, Arrays of Objects, Objects as Function Arguments, Friend Functions.

Unit-III Constructors, Destructors, Inheritance:

Introduction to Constructors, Default Constructors, Parameterized Constructors, Copy Constructors, Multiple Constructors in a Class, Destructors. Inheritance : Introduction to inheritance, Defining Derived Classes, Single Inheritance, Multiple Inheritance, Multi level Inheritance, Hierarchical Inheritance, Hybrid Inheritance.

Unit-IV

Pointers, Virtual Functions and Polymorphism: Introduction to Memory management, new operator and delete operator, Pointers to objects, Pointers to Derived Classes, Polymorphism, Compile time polymorphism, Run time polymorphism, Virtual Functions, Overloading- Function Overloading, Operator overloading.

Unit-V

Templates and Exception handling: Introduction to Templates, Class Templates, Class Templates with Multiple Parameters, Function Templates, Function Templates with Multiple Parameters.

UNIT -

Concepts of Object Oriented programming: Object oriented paradigm-differences between Object Oriented Programming and Procedure oriented programming, Basic concepts of Object Oriented Programming,Encapsulation, Inheritance and Polymorphism. Benefits of OOP .Structure of a C++ program, namespace, Data types, C++ tokens, identifiers, variables, constants, operators, control structures & loops.

Overview of C language:

1.C language is known as structure oriented language or procedure oriented language 2.Employs top-down programming approach where a problem is viewed as a sequence of tasks to be performed. 3.All program code of c can be executed in C++ but converse many not be possible

  1. Function overloading and operator overloading are not possible.
  2. Local variables can be declared only at the beginning of the block.
  3. Program controls are through jumps and calls to subroutines. 7.Polymorphism, encapsulation and inheritance are not possible. For solving the problems, the problem is divided into a number of modules. Each module is a subprogram.
  4. Data abstraction property is not supported by procedure oriented language.
  5. Data in procedure oriented language is open and can be accessed by any function.

Overview of C++ language:

  1. C++ can be considered as an incremental version of c language which consists all programming language constructs with newly added features of object oriented programming.
  2. c++ is structure(procedure) oriented and object oriented programming language.
  3. The file extension of C++ program is “.CPP”
  4. Function overloading and operator overloading are possible.
  5. Variables can be declared in inline i.e when required 6. In c++ more emphasis is give on data rather than procedures
  6. Polymorphism, encapsulation and inheritance are possible.
  7. Data abstraction property is supported by c++.
  8. Data access is limited. It can be accessed by providing various visibility modes both for data and member functions. there by providing data security by data hiding
  9. Dymanic binding is supported by C++
  10. .It supports all features of c language
  11. It can be called as an incremental version of c language

Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP)

Procedure Oriented Programming Object Oriented Programming

program is divided into small parts called functions. program is divided into parts called objects.

Importance is not given to data but to functions as well as sequence of actions to be done.

Importance is given to the data rather than procedures or functions because it works as a real world. 3 follows Top Down approach. OOP follows Bottom Up approach.

4 It does not have any access specifier.

OOP has access specifiers named Public, Private, Protected, etc.

Data can move freely from function to function in the system.

objects can move and communicate with each other through member functions.

6 To add new data and function in POP is not so easy.

OOP provides an easy way to add new data and function.

Most function uses Global data for sharing In OOP, data can not move easily from 7 that can be accessed freely from function to function to function,it can be kept public or function in the system. private so we can control the access of data.

8 It does not have any proper way for hiding data so it is less secure.

OOP provides Data Hiding so provides more security.

In OOP, overloading is possible in the form of 9 Overloading is not possible. Function Overloading and Operator Overloading.

Example of Procedure Oriented 10 Programming are : C, VB, FORTRAN, Pascal.

Example of Object Oriented Programming are : C++, JAVA, VB.NET, C#.NET.

Principles( or features) of object oriented programming:

  1. Encapsulation
  2. Data abstraction
  3. Polymorphism
  4. Inheritance
  5. Dynamic binding
  6. Message passing Encapsulation: Wrapping of data and functions together as a single unit is known as encapsulation. By default data is not accessible to outside world and they are only accessible through the functions which are wrapped in a class. prevention of data direct access by the program is called data hiding or information hiding

Data abstraction : Abstraction refers to the act of representing essential features without including the back ground details or explanation. Classes use the concept of abstraction and are defined as a list of attributes such as size, weight, cost and functions to operate on these attributes. They encapsulate all essential

Reduced complexity of a problem: The given problem can be viewed as a collection of different objects. Each object is responsible for a specific task. The problem is solved by interfacing the objects. This technique reduces the complexity of the program design.

Easy to Maintain and Upgrade : OOP makes it easy to maintain and modify existing code as new objects  can be created with small differences to existing ones. Software complexity can be easily managed.

 (^) Message Passing: The technique of message communication between objects makes the interfacewith external systems easier.  (^) 

Modifiability: it is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only

public interface that the external world has to a class is through the use of methods.

BASIC STRUCTURE OF C++ LANGUAGE : The program written in C++ language follows this basic structure. The sequence of sections should be as they are in the basic structure. A C program should have one or more sections but the sequence of sections is to be followed.

  1. Documentation section
  2. Linking section
  3. Definition section
  4. Global declaration section & class declarations 5.Member function definition
  5. Main function section main() { Declaration section Executable section } 1. DOCUMENTATION SECTION : comes first and is used to document the use of logic or reasons in your program. It can be used to write the program's objective, developer and logic details. The documentation is done in C language with /* and */. Whatever is written between these two are called comments. 2. LINKING SECTION : This section tells the compiler to link the certain occurrences of keywords or functions in your program to the header files specified in this section. e.g. #include using namespace std;  (^) directive causes the preprocessor to add the contents of the iostream file to the program. It contains declarations  for cout and cin.  cout is a predefined object that represents the standard output stream. The operator << is an  insertion operator, causes the string in double quotes to be displayed on the screen.

Insertion Operator variable

The statement cin>>n; is an input statement and causes the program to wait for the user to type in a number. The number keyed is placed on the variable “n”. The identifier cin is a predefined object in C++ that corresponds to the standard input stream. The operator >> is known as extraction operator. It extracts the value from the keyboard and assigns it to the value variable on its right.

Object Extraction operator variable

3. DEFINITION SECTION : It is used to declare some constants and assign them some value. e.g. #define MAX 25 Here #define is a compiler directive which tells the compiler whenever MAX is found in the program replace it with 25. 4. GLOBAL DECLARATION SECTION : Here the variables and class definations which are used through out the program (including main and other functions) are declared so as to make them global(i.e accessible to all parts of program). A CLASS is a collection of data and functions that act or manipulate the data. The data components of a class are called data members and function components of a class are called member functions A class ca also termed as a blue print or prototype that defines the variable or functions common to all objects of certain kind. It is a user defined data type

e.g. int i; //this declaration is done outside and before main()

5. SUB PROGRAM OR FUNCTION SECTION : This has all the sub programs or the functions which our program needs. void display() { cout<<”C++ is better that C”; } SIMPLE „C++PROGRAM: #include using namespace std; void display() { cout<<”C++ is better that C”;

screen

cout << (^) “C++” Object

cin (^) >> 45.

Keyboard

#include This directive causes the preprocessor to add content of iostream file to the program. some old versions of C++ used iostream.h .if complier does not support ANSI (american nation standard institute) C++ then use header file iostream.h

DATA TYPES: A data type is used to indicate the type of data value stored in a variable. All C compilers support a variety of data types. This variety of data types allows the programmer to select the type appropriate to the needs of the application as well as the machine. ANSI C supports the following classes of data types: 1.Primary (fundamental) data types.

Primary data types: 1.integer data type 2.character data type 3.float point data type 4.Boolean data type 5.void data type

integer data type: - This data type is used to store whole numbers. These numbers do not contain the decimal part. The size of the integer depends upon the world length of a machine (16-bit or 32-bit). On a 16-bit machine, the range of integer values is - 32,768 to +32,767.integer variables are declared by keyword int. C provides control over range of integer values and storage space occupied by these values through the data types: short int, int, long int in both signed and unsigned forms.

Signed integers: (16-bit machine): A signed integer uses 1 bit for sign and 15 bits for the magnitude of the number

MSB(most significant bit)

=

100 (10) 00000000001100100 (2) Representation of negative number :

-100(10)= 1111111110011100 (2)

15 14 13 12 11 10 9 8 7

6 5 4 3 2 1 0

02 +02 +12 +12 +12 +02 +0*

NOTE: Signed bit (MSB BIT) : 0 represents positive integer, 1 represents negative numbers

Unsigned integers : Unsigned integers use all 16 bits to store the magnitude. Stores numbers does not have any sign & Size qualifier and range of integer data type on a 16-bit and machine are shown in the table:

MEMORY REQUIRED RANGE

DATA TYPE

OR STORAGE SIZE IN BYTES FORMAT TURBO C GCC/ COMPILERS TURBO C GCC^ SPECIER ( 16 BIT) IN^ LINUX (32 BIT)

( 16 BIT) (32 BIT)

short int - 32768 - 32768

or 2 2

To 153276715

To 32767 %hd 15 15

Double floating point data type occupies 8 bytes of memory giving 14 digits of precision. These are also known as double precision numbers. Variables are declared by keyword double long double refers to a floating point data type that is often more precise than double precision.

Boolean or logical data type is a data type, having two values (usually denoted true and false), intended to represent the truth values of logic and Boolean algebra. It is named after George Boole, who first defined an algebraic system of logic in the mid 19th century. The Boolean data type is the primary result of conditional statements, which allow different actions and change control flow depending on whether a programmer -specified Boolean condition evaluates to true or false. C99 added a Boolean (true/false) type which is defined in the header Boolean variable is defined by kkey word bool; Ex:

bool b; where b is a variable which can store true(1) of false (0)

Void type 

The void type has no values. This is usually used to specify the return type of functions. The type of the function said to be void when it does not return any value to the calling function. This is also used for declaring general purpose pointer called void pointer.

Derived data types.

Derived datatypes are Arrays , pointer and references are examples for derived data types. User- defined data types: they The data types defined by the user are known as the user-defined data types. They are structure,union,class and enumeration

C++ Tokens

IDENTIFIERS: Identifiers are the names given to various program elements such as variables, functions and arrays. These are user defined names consisting of sequence of letters and digits. Rules for declaring identifiers:   (^) The first character must be an alphabet or underscore.  (^)  (^) It must consist of only letters, digits and underscore.  (^)  (^) Identifiers may have any length but only first 31 characters are significant. (^) It must not contain white

space or blank space.  We should not use keywords as identifiers.^ Upper and lower case letters are different. Example: ab Ab aB AB are treated differently Examples of valid identifiers: a, x, n, num, SUM, fact, grand_total, sum_of_digits, sum

Boolean data type:-

Examples of Invalid identifiers : $amount, ³num´, grand-total, sum of digits, 4num. $amount : Special character is not permitted grand-total : hyphen is not permitted. sum of digits : blank spaces between the words are not allowed. 4num : should not start with a number (first character must be a letter or underscore

Note: Some compilers of C recognize only the first 8 characters only; because of this they are unable to distinguish identifiers with the words of length more than eight characters.

Variables: A named memory location is called variable. OR It is an identifier used to store the value of particular data type in the memory. Since variable name is identifier we use following rules which are same as of identifier Rules for declaring Variables names:   The first character must be an alphabet or underscore.  (^) It must consist of only letters, digits and underscore.  (^) Identifiers may have any length but only first 31 characters are significant.  (^) It must not contain white space or blank space.  (^) We should not use keywords as identifiers.

 ^ Upper and lower case letters are different.^ Variable names must be unique in the given scope  Ex:int a,b,a;//is in valid Int a,b;//is valid

Variable declaration: The declaration of variable gives the name for memory location and its size and specifies the range of value that can be stored in that location. Syntax: Data type variable name;

Ex: a 2000 int a=10;

float x=2.3; x 2.300000 5000

KEYWORDS :

There are certain words, called keywords (reserved words) that have a predefined meaning in „C++‟ language. These keywords are only to be used for their intended purpose and not as identifiers. The following table shows the standard „C++‟ keywords auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while class friend new delete this public private protected inline try throw catch template

CONSTANTS:

The magnitude (maximum value) of an integer constant can range from zero to some maximum value that varies from one computer to another. Typical maximum values for most personal computers are: (16-bit machines) Decimal integer constant: 32767 (215-1) Octal integer constant: 077777 Hexadecimal integer constant: 0X7FFF Note: The largest value that can be stored is machine dependent.

Floating point constants or Real constants : The numbers with fractional parts are called real constants. These are the numbers with base-10 which contains either a decimal part or exponent (or both). Representation: These numbers can be represented in either decimal notation or exponent notation (scientific notation). Decimal notation: 1234.56, 75.098, 0.0002, -0.00674 (valid notations) Exponent or scientific notation: General form: Mantissa e exponent Mantissa: It is a real number expressed in decimal notation or an integer notation. Exponent: It is an integer number with an optional plus (+) or minus (-) sign. E or e : The letter separating the mantissa and decimal part. Ex: (Valid notations) 3 1.23456 E+ 3 (1.23456×10 ) 1 7.5098 e+ 1 (7.5098×10 )

2 E- 4 (2×10 ) These exponential notations are useful for representing numbers that are either very large or very small. Ex: 0.00000000987 is equivalent to 9.87e-

Character constants:- Single c haracter constants : It is character(or any symbol or digit) enclosed within single quotes.

Ex: „a ‟ „1‟ „*‟ Every Character constants have integer values known as ASCII values

ASCII:- ASCII stands for American Standard Code for Information Interchange. Pronounced ask-ee, ASCII is a code for representing English characters as numbers, with each letter assigned a number from 0 to 255.Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort.A SCII codes represent text in computers, communications equipment, and other devices that use text. Most modern character-encoding schemes are based on ASCII, though they support many additional characters. Below is the ASCII character table and this includes descriptions of the first 32 non -printing characters. String constants or string literal:

String constant is a sequence of zero or more characters enclosed by double quotes. Example: “MRCET” “12345” “*)(&%” Escape Sequences or Backslash Character Constants C language supports some nonprintable characters, as well as backslash ( ** ) which can be expressed as escape sequences. An escape sequence always starts with backslash followed by one or more special characters. For example, a new line character is represented "\n" or endl These are used in formatting output screen , i.e. escape sequence are used in output functions. Some escape sequences are given below:

operator meaning

  • add
  • subtract

cout<<"a%b"<< a%b; }

OUTPUT: a+b=23 a-b= a*b= a/b=6 a% b=

2. RELATIONAL OPERATORS : We often compare two quantities and depending on their relation take certain decisions for that comparison we use relational operators. operator meaning

is less than is greater than is less than or equal to is greater than or equal to is equal to is not equal to / C program on relational operators/** #include void main() { int a,b; clrscr(); cout<<"Enter a, b values:"; cin>>a>>b; cout<<"a>b"<< a>b; cout<<"a>=b"<< a>=b; cout<<"ab: 0 //false a=a: 1 //true

a<=b: 1 //true a==b: 0 //false

a!= b: 1 //true 3 .LOGICAL OPERATORS: Logical Data: A piece of data is called logical if it conveys the idea of true or false. In C++ we use int data type to represent logical data. If the data value is zero, it is considered as false. If it is non -zero (1 or any integer other than 0) it is considered as true. C++ has three logical operators for combining logical values and creating new logical values:

Note:Below program works in compiler that support C99 standards

#include #include int main() { bool a,b; /logical and/ a=0;b=0; cout<<" a&&b "<< a&&b<