

























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
9IHDS8H0HU[98OJOFEQ98H8FDST DS9DS 9UDSP FDQ9UB DS9B [DUNBDSA AD NB FEQU
Typology: Summaries
1 / 97
This page cannot be seen from the preview
Don't miss anything!


























































































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
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.
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.
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
Overview 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.
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 interfacewith 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.
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)
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 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
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
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
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
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<