Beruflich Dokumente
Kultur Dokumente
Introduction to C++:
High level languages like COBOL, FORTRAN and C known as Procedure
Oriented Programming (POP).
In POP problem is viewed as sequence of things to be done.
Data change may occurs during each function call so debugging is
difficult.
OOP treats data as a critical element and does not allow it to flow freely
through the program.
Programs are divided into objects and each object contains its own data
and function.
Data of one object cannot be changed by function of another object
however it can access the function of another object (Communication of
Objects through function).
Class is the collection of objects of similar types (similar to data structures
in C). E.g. fruit mango fruit=>class and mango=>object.
Wrapping of data and function into single unit (class) is encapsulation.
Inheritance is the process by which object of one class acquire the
properties of objects of another class.
Polymorphism=>Ability to take more than one form. Operator
Overloading.
Namespace defines the scope for the identifiers that are used in the
program.
If inside the main we declare student Asad then student is class and Asad
is object.
Functions which operate on the data of any class is known as member
function.
Include Files
Class Declarations
Member functions definition
Main Function Program
Data Types:
My Notes C++
Use of void=>
void *gp;
Here gp becomes generic pointer.
In C char constants are stored as ints therefore sizeof(x)=sizeof(int) in C
but in C++ sizeof(x)=sizeof(char).
Initialization of variables during run time is known as Dynamic
initialization. It is allowed in C++.
Reference Variables:
It provides Alias (Alternative name). One location two Names.
Data_type & reference_name = variable_name e.g. float & sum = total;
Data change occur for both at the same time.
& is no more address operator. Here float & is reference to float.
Application is passing arguments to a function. Void func(int &x) such
function calls are known as Call by Reference.
References can be created for built in data types as well as user defined
data types such as structures and classes.
Operators in C++:
<<
Insertion Operator
>>
Extraction Operator
::
: :*
->*
.*
Delete
My Notes C++
Setw Field Width Operator
Manipulators:
Syntax cout<<setw(width)<<variable_name<<endl;
Operator Precedence:
My Notes C++
Functions in C++:
Main () in C have no return type but for C++ it returns int to the operating
system.
At the time of declaration, only function type is necessary because
compiler only checks types and not variables (also called dummy variable)
thus float average (float) is legal.
Inline Functions:
Function take lots of time for calling thats why use of Inline function
happens.
It simply expand in the line where it is invoked.
Syntax
Inline function_header
{
Function body
}
return ( a*a*a );
}
If the functions are of bigger length then it is better to use normal function
than inline.
DEFAULT ARGUMENTS are the arguments which take the default value
when that value is missing at the time of function call. Add default value
from right to left and not in the middle