Você está na página 1de 64

SIX WEEK TRAINING

PRESENTATION
ON
C++ PROGRAMMING
FROM
ABOUT HCL
• HCL Corporation (originally Hindustan Computers Limited), also
known as HCL Enterprise, is one of India's largest electronics, 
computingand information technology company
• . Based in Noida, near Delhi, the company comprises two publicly
listed Indian companies, HCL Technologies and HCL Infosystems.
• HCL was founded in 1976 by Shiv Nadar, Arjun Malhotra, 
Subhash Arora, Ajai Chowdhry, DS Puri, & Yogesh Vaidya.
• HCL was focused on addressing the IT hardware market in India
for the first two decades of its existence with some sporadic
activity in the global market.
• .6weeks training from HCL- CAREER DEVELOPMENT CENTER 17-
sec CHANDIAGARH in c++ programming landuage.
About C++
• C++ is superset of c. C++ is built on
C because of C’s suitability to system
programming , its widespread
availability & its close ties with the
UNIEX operating system.
• C++ was originally called “C with
CLASSES”.
ORIGIN of C++
• C++ is an expanded version of C. C was developed by
DENNIS RITCHIE at BELL lab & was 1st put in use in 1972.
• BJARNE STROUSTROP developed C++ in 1983 at AT & T Bell
labs, New Jersey, USA. It was 1st object oriented language
& also strong supporter of C. C++ was initially designed to
manage very large programs.
• It was named first C with CLASSES . Later in 1983 the name
was changed to C++. In the name “C++” “++” means it is
an advanced & incremented version of C.
• C++ has been revised twice, 1st time in 1985 & then in
1989.

Simula 67 C language
(1967) (1972)

C++
(OOP’s):

Artificial Intelligence & Expert Systems


Neural networking .
Real-Time systems.
Simulation & Modelling.
Object oriented Databases.
Office Automation Systems
CAD/ CAM systems.
Object-Oriented
Programming in C++
OOPs in computer science, type of high-level
computer language that is self-contained,
modular instruction sets for defining &
manipulating aspects of computer program.
There discrete , pre-defined instruction sets
are called OBJECTS and may be used to define
variable, data structures, & and procedures
for executing data operations.
In OOPs , object have built-in rules for
communicating with one another.
FEATURES of OOP’s (C++)
language
Object oriented lang does not work around single
component or unit. It uses a vocabulary more than
procedure lang. it is grouping of all the elements
or components linked with object approach.
A
a bs
u l Object tr
p s a
n ct
n ca ion io
E t

Message
Class OOP’s passing &
reusability
h is
p
In

mic or
h

a ym m
Dyn ing
er

l
Po
it

d
Bin
a nc
e
OBJECT & CLASSES:
• Object are made up of :- Data
members

Outside
Member
World
function

• A class is group of object that share common properties &


relationships. Classes are user- define types & behave like built-in
types of a programming
Object language. Object
1 2
Data 1
Data 1 Data 2
Data 2 Functio
Fxn 1 n
Fxn 2

Member of Data
object1 function

Object 3
 Data Abstraction:- means representing essential
features without including background details or explanation.
Class use the concept of abstraction & are defined as a list of
abstract data & function to operate on these data.
 Encapsulation :- wrapping up (or binding) of data &
function (that operate on the data) into a single unit (called
class). The data is not accessible to outside of class. Only
function which are inside the class can access the data.
 Data Hiding :- access to private part of an object is
restricted in the sense that functions of the object can only
access the data & can’t be altered by external changes.
 Relationship b/w encapsulation & abstraction:-

Abstraction PublicMember Encapsulation


(only public s (public members
members) Private +
memb Private
ers members)
Inheritance
 Inheritance is a method by which create new class by extending
& enhancing existing class. The existing class called “Base
class” & the new class called “Derived class”.
 Types of inheritance:-
1. Single inheritance :-
Base class (a)

Derived class (b)

2. Multiple inheritance :-
Base Base Base
class 1 class 2 class 3

Derived
class
3. Multi-level inheritanceBase
:- class

Intermediate
class

Derived class

4. Hierarchical inheritance :-class


Base

Derived Derived Derived


class 1 class 2 class 3

5. Hybrid inheritance :- class


Base

Base class
Intermediate 2
class

Derived class
POLYMORPHISM
Polymorphism means one name & many
duties. The ability of one thing to make
(poly) distinct forms (morphism).
The property by which same message is
sent to object of different classes & the
objects behave differently.
Compute
Area( )

Circle Rectangle Triangle


Area( circle) Area(rectangle) Area (triangle)
Advantages of OOP’s
Data security.
Reusability
Creating new data types
Abstraction
Object independence
Maintainability
Less development time
Modularity
Easy to divide project work
C++ programming basic
Character set :- denotes any denotes any letter or
alphabet, digit or special symbol used to form word, number &
expression.
Tokens :- are the smallest elements or atomic elements .
Following tokens:-
1. keyword:- are the words that have a standard, predefined
meanings. Known as reserved words. For example : double,
char, int, long, void etc.
2. Identifiers:- refers to the names of variables, function,
arrays, class, etc. created by the user.
3. Constants:- is a quantity that remain unchanged during
constants
Numeric
the execution of a program.
constants(numbers Character
) constants
Single String
Integer Real character constants
constants constants constants
Data types:- is defined as a finite set of values along with set
of rules for permissible operations.

Data types

Basic types Derived User-defined


Int types types
Char Array Structure
Float Function Union
Double Pointer Class
void reference Enum
Declaration of variables:-
data type V1,V2,…….Vn;
where V1,V2…..Vn are the names of variables, separated by
commas.
For example:- int number1,number2;
float sum, mean;
Header
files
C++
program Input/output
statements

#include<iostream.h> getch() & clrscr() use library


#include<conio.h> function
void main() Special fxn 2 tell compiler
{ int n; Erase content of dos where program start.
screen. erase output of Pre-defined obj
clrscr(); previous program run represents
standard input
/*start of program
stream
cout<<“hello goog moring”; Pre-defined obj
cin>>n; Halt execution repesents
temporarily, after standard output
getch();
display streams in c++
} */ end of programs
Extractio
n Or Insertion Comment help the header in
Get from Or understanding the flow of the program &
operator Put to what is being calculated at various
operator stages. /* multiple text*/ or// single line//
 Modification of the data to be displayed . These are operation used
with insertion operation “<<“ i.e. for cout statements.
 To access manipulators , file iomanip.h should be included in the
program.
1. Endl manipulator: predefined iostream manipulator. It is
equivalent to the end line character ‘\n’ and then flushing output
buffer.
cout<<“a= “<<a<<endl; result:- a=5
cout<<“b= “<<b<<endl; b=10
2. Setw( ): specify the require field size for displaying an output
value.
cout<<setw(8) <<5764; result:- ____5764
3. Setprecision( ): specify the number of digits to be displayed
after the decimal point while printing the floating-point numbers.
cout<<setprecision (3) <<3.14546789;
result:- 3.145(rounded)
4. Setfill( ): specify a charcter that is used to fill the unused portion
of a field.
cout<<setw(8)<<setfill(‘*’)<<5376<<endl;
result: * * * * 5 7 6 4.
Operators
 An operator is a symbol or letter used to indicate a specific
operation on variables in program.
1. Arithmetic operators:- (+,-,*,/.%)
2. Relational operators:- (>,<,==,<=,>=,!=)
3. Logical operators:- (&&,II,!)
4. Increment & Decrement operator:- (++,--)
two types :-
 pre increment & decrement (first inc or dec ment value than
assignment . For example c= ++a;)
 Post increment & decrement ( assigning than inc or dec ment value.
For eaxmple c=a++;)
5. Conditional operator:- a ternary operator pair “? :” is available in c+
+ to construct conditional expression of the form expression ?
Expression2 : expression3;
6. Bit wise operator:- are used to manipulate the data at bit level.
(&,I,^,~,<<,>>)
7. Scope resolution operator:- (: :)
Control Structure or Flow
• Programming constructs used to alter the
flow of control in aprogram from normal
Control
sequential execution.
stateme
nts

branching looping jumping

Condition whil contin


swit al control e ue
ch fo brea Go
If r do k to

if-
else Simple
Else -if forwa
-if Neste rd backwa
d-if rd
Functions
• Function is a self-contained block of
code that performs a particular task.
Function types

Library functions
User-defined
(not required to be
function(develope
written by user)
d by user.
Examples:-
Example main()
sqrt,cos,sin etc

Syntax:- function name()


{--------------
}
Return Statement :- a function may or may not
return any value to callig function. If it does, it is
done through return statement.
syntax:-return(expression);
Function prototyping :- helps compiler by it a
prior information to it.
1. number of arguments.
2. type of arguments
3. type of return values.
Syntax:- <data type><function-
name>(parameter list);
Example :- float sum (float a, float b);
Parameter Passing in
Function
Function that have parameters can be called in one of the following two
ways:
1.Call by value:- the call by value method copies the values of the
actual parameter into formal parameters that is the function creates
its own copy of arguments values & then uses them. Changes done to
a
the values in the formal b are not reflected
parameters back into calling
Actual
1 2
function. 0 0 parameters

10 20 Formal
parameters
x y

2. Call by reference:- this method passes the addresses or


references of the actual parameters to the called function . Thus
actual & formal parameters share the same memory locations. This is
achieved by apply an address operate (&) to the formal parameters in
the function definition .
ARRAYS
 Array are data structure which hold multiple variables of same
type.
syntax:- data-type variable-name[sizes];
 Types of array:-
1. linear array :- even known as 1 dimensional or list array.
These types are of ladder type. Only 1 subscript is used.
Syntax:- data-type array-name [size];
example :- int x[50];
2.Non-linear array:- subdivide
2 –dimensional into 3 categories
array:-(2 subscripts as:
row & coulmn)
Syntax:- data type array-name [row-size][column-size]
Example:- int a[10][10];
3-dimensional array:- (3 subscripts row, coulmn, space size)
Syntax:- data-type array-name [space-size][row-size][column-size];
Examples:- int st[5] [4] [2];

N-dimensional or multi-dimensional array:- n size of rows,column &


space & so on.
Syntax:- data-type array-name [s1] [s2] [s3]-----------[sn];
STRING
• Strings represented by arrays of characters . The end of
string is marked with a special character, null character.
• String constants:- sequence of charcters enclosed by
duble quotes. Example:-
“magic of
string”
• If include single quote or double quote in string, then use
with back slash(\). Example:-
“helloween\’s
• String Variable:- is an array of characters. General form of
town”
declaration of a string variable is. Example:-

Char
• The complier automatically string_name
supplies a null character(‘\0’)
at the end of string. [size];
String Functions
• Standard library’s string handling functions, which contains external
declarations of string functions. #include
• Strlen() function:-counts & returns the <string.h>
number of characters in a string.
The null character ‘\0’ is not counted.
Form is where ‘n’ is integer variable
n=
• Strepy() function:- used to copy one string to another.
strlen(string);
form is
strepy(string1,str
• Stremp() function:-compares two strings & returns 0 if they are equal. It
returns a negative numbering2);
if the 1st string is alphabetically less than the
2nd string or positive number if string is greater than the 2nd string.
form is
• Strrev() function :- used to reverse a string. Form is
• Strupr() function:-Stremp(string1,
used to convert a string to uppercase.
Form is string2);
strrev(string)
• Strlwr() function:- used to covert a string to lowercase. ;
form is
strupr(string)
;
strlwr(string)
;
Structure
• Structure is hetergeneous collection of related fields. Fields are
called structure members or structure elements. Every field has
different type-specifier (data-type).
• General format of structure definition is:-
struct name Keyword also
called tag
{
struct
struc student
datatype
member1; t
{
datatype
int roll;
member2;
char name[20]
datatype
int age
member3;
int marks
……
};
……
datatype member-
n;
};
Declaring Variable of
Structure Type
Once a structure is define, declare variable (s)
of that type.
Synatx:- Sname var-1,var-2,
…………..var-n;
Example:-

Struct student
{
Int roll;
Char name
[20]; Declare s1 & s2 as
Int age; structure variable
Int marks; representing two
} students
S1,s2;
Initializing Structure
• Like simple variable & arrays
structure variables are also be
initialized at declaration time.

Struct student
{ Structure is initialized . Values
Int roll; are enclosed within curly
Char name [20]; braces . values assigned to the
Int age; members of the structure in
Int marks; order of their apperance.1st
}; value is assigned 2 1st field…&
Student s1={100, “amit”, so on..
18,92};
 Union is a variable that declares set of multiple
variables ( called members or elements having
different data-types)sharing the same memory
area. Compiler allocates sufficient memory to
hold the largest variable of union
syntax:

union name-tag example:


{
datatype-1 union student
member1; {
char grade;
……………………………… int rollno;
datatype-n float marks;
member-n; double fees
} }
union name-tag union student s;
v1,v2…..vn;
Class declaration
Class is an aggregation of data members
& data functions joined under a common
class specifier. Format of declaration :-
Keyword

Class <name>
{
Private: User defined name of the class
variable
declarations;
functions
declaration; Visibility mode
public:
variable
declaration;
function
declarations;
};
Accessing Class Members
• Class members that are declared to be public can be
accessed from outside . Access them using following
syntax:-
@. Object-name . Member-name;
Class sample
@. Object-name . Function-name (actual-arguments);
{
Int a,b;
Public:
int c;
void main();
};
Main()
{
Sample x;
x.c =4; //accessing the data
member
x.a=4;
x.sum(); //accessing member
function

Defining Member Function
in Class
Member function may be defined in two places:

Outside the class definition Inside the class definition


• 1st define prototype of • When functon is
function within class & defined inside class
then define them
outside .scope resolution
itself at place of
operator as so:- declaration, it is
Class sample Class sample
treated as an inline
{ {
Int a,b; function.
Int a,b;
Public : Public :
Void sum(); Int s;
}; Void sum()
Void sample : :sum( ) {
{ cout<<“sum
cout<<“sum is”<<a+b;
is”<<a+b; }
} };
Pointers
 Pointers are memory addresses variable i.e. the variables, which
have addresses of the variable having some value, stored in the
memory.
Variable- Variable- Memory
name value address
q 440 5000  P memory-variable (pointer)

 Syntax :- data-type *pointer-variable;


int *p,q;
 Example:-
q=440;
p=&q;
Cout<<q<<“is stored address”<<p;

Result:- 440 is stored address 5000


Constructor
Constructor is a special number function that
execute automatically when object is created.
Two things remember while creating constructor
1.it’s name should be same as that of class name.
2. no return type is used. example:-
class student
{
syntax:- Private:
class class-name Int rn;
{ Constructor defined Char name[20];
Private: public:
Data-type data student( )
members; {
public: Rn=0;
class name(); Name=“ “;
} }
};
Parameterized :
Those constructor DEFAULT : Copy constructor:-
which contains Empty Usedto initialize value
parameter . constructor are of an object by
Syntax:- default copying values of
Class classname constructors. object of same
{ Syntax:- class.when compiler
Private: Class has to create a
Public: classname temprary object of a
Classname(argument { class object.
list) Private: Syntax:-
{ Data-type data; Class-name(class-
} // parameterized Public: name or constructor-
const Classname() name & object-
} name);
};
Destructor
 Destructor is a special member function that member function
that executes automatically when the object is destroyed.
 Two things to remember:-
1. it’s name should be same as that of class accepted i.e. 1st
character is (~) tilde.
2. no return type is used.
• Syntax:- ~ constructor-name (); or ~class-name();
• Example:- Class student
{
private:
Int rn;
Char name [10];
public:
student() // constructor defined
{

Rn =0;
Name=“ “;
}
~student (); //destructor defined
};
Inheritance
• Inheritance is a process of creating new classes from
the existing ones i.e. base class to derived class.

Featur Featur Defined in derived


eA eC class
Featur
Feature eA
B Featur Defined on base
eB class but inherit from
base class
Base class Derived class
Whenever defining derived class , have to specify its
relationship with base class. Syntax:-
Class derived_class_name : visibility_mode base_class_name
{
//members of derived class
};
Access Specifier
• Private derivation:-
Class b Not Class d: private b
Private inheritable Private
Protected Protected
Public Public
(base class) (derived class)

• Protected derivation:-
Class b Not Class d: private b
Private inheritable Private
Protected Protected
Public Public
(base class) (derived class)
Public derivation:-
Class b Not Class d: private b
Private inheritable Private
Protected Protected
Public Public
(base class) (derived class)

Visibility of inheritance members.


Visibility of derived class

Visibility of Private Protected Public


base class derivation derivation derivation
Private ---> Not inherited Not inherited Not inherited
Protected --- > Private Protected Protected
Public ----- private protected public
>
The access control to private, protected
&public of a class

Access Accessible Accessible Accessible


specifier from own class from derived from object
class outside class
Public Yes Yes Yes
Protected Yes Yes No
private yes No No
C++ streams
A stream can be cnsidered to be intermediary
for i/o ,between the program & I/O devices.
Input streams:-

Input Input
program
device stream
 output streams:-

Output output
program
device stream
STREAMS
ios

istream streambuf ostream

iostream

ifstream fstream ostream


Function in file handling
Opening files using open( ) function:
file-stream-class object;
Syntax:- object.open(“filename”);
Example:- Ofstream outfile; Ifstream infile;
Outfile.open(“result”); Infile.open (“data”);

Closing files using close() function:


Synatx:-
Objectname .close();
Example:-
Infile.close();
Outfile.close();
Write() & read() functions
 1st argument of the function read() is the
address of the variables & 2nd is the size or
length of that variable is byte. Syntax :-
Read()
Infile . Read((char*) & variable , sizeof(variable));

Stream Type
Object Address of Size of variable in bytes
casting
variable
Write ()
outfile . write((char*) & variable , sizeof(variable));
Airlines reservation

Passenger Flight
detail detail
 TURBO C++ software.
 Passengers related info..
 Flight related info..
 Cancellation required in case by passenger.
 Help if so requires my passenger
 Queries regarding reservation .
Flight
Info.

Destination Timing (take


point off flight)

Day of flight
Fares

Boarding
Fight code
point
PASSANGER
INFO.

FIGHT CODE GENDER

PIN CODE
PERSON NAME
AGE

ADDRESS INFO DATE OF RES.

H-NO. PIN CODE

CITY
COLONY
P.O.
Enter the name of passenger.
Flight code.
 Enter passenger name who did the
reservation.
 Flight code number.
Help direction
 WORK LOAD IS REDUCE.
 MANITANCE OF DATA BECOMES EASILY.
 TIME SAVING & FASTER.
rk b y : -
a m w o
Te C h e e
e l e e n
•Lov
ma K u m a r
n e s h
•Di m a r
i t K u
•Roh rg
h il g a
•Sa BHAGAT ENGG
(DESH E ) n gg .
G E
COLLE er Science
omp ut
C e nt RH
a r t m DG A
Dep I G O B IN
Thanks a lot….

Você também pode gostar