64
SIX WEEK TRAINING PRESENTATION ON C++ PROGRAMMING FROM

Six Week Training Presentation on c++ Programming From

Embed Size (px)

Citation preview

Page 1: Six Week Training Presentation on c++ Programming From

SIX WEEK TRAINING PRESENTATION

ONC++ PROGRAMMING

FROM

Page 2: 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.

Page 3: Six Week Training Presentation on c++ Programming From

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”.

Page 4: Six Week Training Presentation on c++ Programming From

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 (1967) C language (1972)

C++ (1983)

Page 5: Six Week Training Presentation on c++ Programming From

Applications of C++ (OOP’s):

Artificial Intelligence & Expert SystemsNeural networking .Real-Time systems.Simulation & Modelling.Object oriented Databases.Office Automation SystemsCAD/ CAM systems.

Page 6: Six Week Training Presentation on c++ Programming From

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.

Page 7: Six Week Training Presentation on c++ Programming From

FEATURES of OOP’s (C++) languageObject 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.

OOP’s

Encapsu

la

tion

ObjectAbstractio

n

Class

Inheritance

Message passing & reusability

Polymorp

his

mDynamic

Binding

Page 8: Six Week Training Presentation on c++ Programming From

OBJECT & CLASSES:• Object are made up of :-

• A class is group of object that share common properties & relationships. Classes are user- define types & behave like built-in types of a programming language.

Data members

Member function

Outside World

Data 1Data 2Fxn 1Fxn 2

Data 1Data 2

Function

Data function

Object 1 Object 2

Object 3

Member of object1

Page 9: Six Week Training Presentation on c++ Programming From

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:-

PublicMembers

Private memb

ers

Abstraction(only public members)

Encapsulation(public members

+Private

members)

Page 10: Six Week Training Presentation on c++ Programming From

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 :-

2. Multiple inheritance :-

Base class (a)

Derived class (b)

Base class 1

Base class 2

Base class 3

Derived class

Page 11: Six Week Training Presentation on c++ Programming From

3. Multi-level inheritance :-

4. Hierarchical inheritance :-

5. Hybrid inheritance :-

Base class

Intermediate class

Derived class

Base class

Derived class 3

Derived class 2

Derived class 1

Base class

Intermediate class

Base class 2

Derived class

Page 12: Six Week Training Presentation on c++ Programming From

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.

TriangleArea (triangle)

Rectangle Area(rectangle

)

CircleArea( circle)

ComputeArea( )

Page 13: Six Week Training Presentation on c++ Programming From

Advantages of OOP’sData security.ReusabilityCreating new data typesAbstractionObject independenceMaintainabilityLess development timeModularityEasy to divide project work

Page 14: Six Week Training Presentation on c++ Programming From

C++ programming basicCharacter 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 the execution of a program.

constantsNumeric

constants(numbers)

Character constants

Single character constants

String constantsReal

constantsInteger

constants

Page 15: Six Week Training Presentation on c++ Programming From

Data types:- is defined as a finite set of values along with set of rules for permissible operations.

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;

Data types

User-defined types

StructureUnionClass Enum

Derived typesArray

FunctionPointer

reference

Basic types Int

CharFloat

Doublevoid

Page 16: Six Week Training Presentation on c++ Programming From

C++ program#include<iostream.h>#include<conio.h> void main() { int n; clrscr(); /*start of program cout<<“hello goog moring”; cin>>n; getch();} */ end of programs

Halt execution temporarily, after

display

getch() & clrscr() use library function

Input/output statements

Header files

Special fxn 2 tell compiler where program start.Erase content of dos

screen. erase output of previous program run

Pre-defined obj represents

standard input stream

Pre-defined obj repesents

standard output streams in c++

Comment help the header in understanding the flow of the program & what is being calculated at various stages. /* multiple text*/ or// single line//

InsertionOr

Put to operator

Extraction Or

Get from operator

Page 17: Six Week Training Presentation on c++ Programming From

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=102. Setw( ): specify the require field size for displaying an output

value. cout<<setw(8) <<5764; result:- _ _ _ _ 5 7 6

43. 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.

Page 18: Six Week Training Presentation on c++ Programming From

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:- (: :)

Page 19: Six Week Training Presentation on c++ Programming From

Control Structure or Flow• Programming constructs used to alter the flow of

control in aprogram from normal sequential execution. Control

statements

branching looping jumping

If

switch

Conditional control

Go to

continue

breakdo

while

for

if-else

Else-if Nested-

if

Simple-if

backwardforward

Page 20: Six Week Training Presentation on c++ Programming From

Functions• Function is a self-contained block of code that

performs a particular task.

Syntax:- function name() {-------------- }

Function types

User-defined function(developed by user. Example main()

Library functions (not required to be

written by user)Examples:- sqrt,cos,sin etc

Page 21: Six Week Training Presentation on c++ Programming From

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);

Page 22: Six Week Training Presentation on c++ Programming From

Parameter Passing in FunctionFunction 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 the values in the formal parameters are not reflected back into calling function.

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 .

10

10 20

20

a b Actual parameters

Formal parameters

x y

Page 23: Six Week Training Presentation on c++ Programming From

ARRAYSArray 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 into 3 categories as:2 –dimensional array:-(2 subscripts 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];

Page 24: Six Week Training Presentation on c++ Programming From

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:-

• If include single quote or double quote in string, then use with back slash(\). Example:-

• String Variable:- is an array of characters. General form of declaration of a string variable is. Example:-

• The complier automatically supplies a null character(‘\0’) at

the end of string.

“magic of string”

“helloween\’s town”

Char string_name [size];

Page 25: Six Week Training Presentation on c++ Programming From

String Functions• Standard library’s string handling functions, which contains external

declarations of string functions.• Strlen() function:-counts & returns the number of characters in a string.

The null character ‘\0’ is not counted. Form is where ‘n’ is integer variable• Strepy() function:- used to copy one string to another. form is• Stremp() function:-compares two strings & returns 0 if they are equal. It

returns a negative number 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:- used to convert a string to uppercase. Form is• Strlwr() function:- used to covert a string to lowercase. form is

#include <string.h>

n= strlen(string);

strepy(string1,string2);

Stremp(string1, string2);

strrev(string);

strupr(string);

strlwr(string);

Page 26: Six Week Training Presentation on c++ Programming From

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 { datatype member1;datatype member2;datatype member3;…………datatype member-n;};

struct student {int roll; char name[20]int ageint marks};

struct

Keyword also called tag

Page 27: Six Week Training Presentation on c++ Programming From

Declaring Variable of Structure TypeOnce a structure is define, declare variable

(s) of that type.Synatx:- Example:-

Sname var-1,var-2, …………..var-n;

Struct student{Int roll;Char name [20];Int age;Int marks;}S1,s2;

Declare s1 & s2 as structure variable representing two students

Page 28: Six Week Training Presentation on c++ Programming From

Initializing Structure• Like simple variable & arrays structure

variables are also be initialized at declaration time.

Struct student{Int roll;Char name [20];Int age;Int marks;};Student s1={100, “amit”, 18,92};

Structure is initialized . Values are enclosed within curly braces . values assigned to the members of the structure in order of their apperance.1st value is assigned 2 1st field…& so on..

Page 29: Six Week Training Presentation on c++ Programming From

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{ datatype-1 member1; ……………………………… datatype-n member-n;}union name-tag v1,v2…..vn;

example:

union student{ char grade;int rollno;float marks;double fees}union student s;

Page 30: Six Week Training Presentation on c++ Programming From

Class declarationClass declarationClass is an aggregation of data members

& data functions joined under a common class specifier. Format of declaration :-

Class <name>{Private: variable declarations; functions declaration;public: variable declaration; function declarations;};

Keyword

User defined name of the class

Visibility mode

Page 31: Six Week Training Presentation on c++ Programming From

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;@. Object-name . Function-name (actual-arguments);

Class sample{Int a,b;Public: int c; void main();};Main(){Sample x;x.c =4; //accessing the data memberx.a=4;x.sum(); //accessing member function…}

Page 32: Six Week Training Presentation on c++ Programming From

Defining Member Function in Class

Outside the class definition• 1st define prototype of function

within class & then define them outside .scope resolution operator as so:-

Inside the class definition• When functon is defined

inside class itself at place of declaration, it is treated as an inline function.

Member function may be defined in two places:

Class sample{ Int a,b;Public : Void sum();};Void sample : :sum( ){ cout<<“sum is”<<a+b;}

Class sample{ Int a,b;Public : Int s; Void sum() { cout<<“sum is”<<a+b; }};

Page 33: Six Week Training Presentation on c++ Programming From

PointersPointers are memory addresses variable i.e. the variables,

which have addresses of the variable having some value, stored in the memory.

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

Variable-name

Variable-value

Memory address

q 440 5000 P memory-variable (pointer)

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

Result:- 440 is stored address 5000

Page 34: Six Week Training Presentation on c++ Programming From

Constructor Constructor is a special number function that

execute automatically when object is created.Two things remember while creating constructor1.it’s name should be same as that of class name.2. no return type is used.

syntax:-class class-name{Private:Data-type data members;public: class name();}

example:-class student{Private:Int rn;Char name[20];public: student( ) {Rn=0;Name=“ “;}};

Constructor defined

Page 35: Six Week Training Presentation on c++ Programming From

Parameterized :Those constructor

which contains parameter .

Syntax:-Class classname{Private:Public:Classname(argument list){} // parameterized const

};

DEFAULT :Empty

constructor are default

constructors.Syntax:-

Class classname{Private:Data-type data;Public:Classname()}

Copy constructor:-Usedto initialize

value of an object by copying values of

object of same class.when compiler

has to create a temprary object of a

class object.Syntax:-

Class-name(class-name or constructor-

name & object-name);

Page 36: Six Week Training Presentation on c++ Programming From

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};

Page 37: Six Week Training Presentation on c++ Programming From

Inheritance• Inheritance is a process of creating new classes from the existing

ones i.e. base class to derived class.

Whenever defining derived class , have to specify its relationship with base class. Syntax:-

Feature A

Feature B

Feature C

Feature A

Feature B

Base class Derived class

Defined in derived class

Defined on base class but inherit from base class

Class derived_class_name : visibility_mode base_class_name { //members of derived class };

Page 38: Six Week Training Presentation on c++ Programming From

Access Specifier • Private derivation:-

• Protected derivation:-

Class b

Private

Protected

Public

(base class)

Class d: private b

Private

Protected

Public

(derived class)

Notinheritable

Class b

Private

Protected

Public

(base class)

Class d: private b

Private

Protected

Public

(derived class)

Notinheritable

Page 39: Six Week Training Presentation on c++ Programming From

Class b

Private

Protected

Public

(base class)

Class d: private b

Private

Protected

Public

(derived class)

Notinheritable

Public derivation:-

Visibility of inheritance members.

Visibility of derived class

Visibility of base class

Privatederivation

Protected derivation

Public derivation

Private --->Protected --- >Public ----- >

Not inheritedPrivateprivate

Not inheritedProtectedprotected

Not inheritedProtectedpublic

Page 40: Six Week Training Presentation on c++ Programming From

Access specifier

Accessible from own class

Accessible from derived class

Accessible from object outside class

PublicProtectedprivate

YesYesyes

YesYesNo

YesNoNo

The access control to private, protected &public of a class

Page 41: Six Week Training Presentation on c++ Programming From

C++ streamsA stream can be cnsidered to be intermediary

for i/o ,between the program & I/O devices.Input streams:-

output streams:-

Inputstream

Input device

program

outputstream

Outputdevice

program

Page 42: Six Week Training Presentation on c++ Programming From

ios

ostreamfstreamifstream

iostream

streambuf ostreamistream

STREAMS

Page 43: Six Week Training Presentation on c++ Programming From

Function in file handlingOpening files using open( ) function:Syntax:-Example:-

Closing files using close() function:Synatx:-Example:-

file-stream-class object;object.open(“filename”);

Ofstream outfile;Outfile.open(“result”);

Ifstream infile;Infile.open (“data”);

Objectname .close();

Infile.close();Outfile.close();

Page 44: Six Week Training Presentation on c++ Programming From

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()

Write ()

Infile . Read((char*) & variable , sizeof(variable));

outfile . write((char*) & variable , sizeof(variable));

Stream Object

Type casting

Address of variable

Size of variable in bytes

Page 45: Six Week Training Presentation on c++ Programming From
Page 46: Six Week Training Presentation on c++ Programming From

Airlines reservation

Passenger detail

Flight detail

Page 47: Six Week Training Presentation on c++ Programming From

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

Page 48: Six Week Training Presentation on c++ Programming From
Page 49: Six Week Training Presentation on c++ Programming From

Flight Info.

Destination

point

Fares Day of flight

Boardingpoint

Fight code

Timing (take off flight)

Page 50: Six Week Training Presentation on c++ Programming From
Page 51: Six Week Training Presentation on c++ Programming From

PASSANGER INFO.

PERSON NAME

DATE OF RES.

FIGHT CODE

AGE

GENDER

PIN CODE

ADDRESS INFO

H-NO. PIN CODE

COLONY P.O.

CITY

Page 52: Six Week Training Presentation on c++ Programming From
Page 53: Six Week Training Presentation on c++ Programming From
Page 54: Six Week Training Presentation on c++ Programming From

Enter the name of passenger.

Flight code.

Page 55: Six Week Training Presentation on c++ Programming From
Page 56: Six Week Training Presentation on c++ Programming From
Page 57: Six Week Training Presentation on c++ Programming From

Enter passenger name who did the reservation.

Flight code number.

Page 58: Six Week Training Presentation on c++ Programming From
Page 59: Six Week Training Presentation on c++ Programming From
Page 60: Six Week Training Presentation on c++ Programming From

Help direction

Page 61: Six Week Training Presentation on c++ Programming From
Page 62: Six Week Training Presentation on c++ Programming From

WORK LOAD IS REDUCE. MANITANCE OF DATA BECOMES EASILY. TIME SAVING & FASTER.

Page 63: Six Week Training Presentation on c++ Programming From

Team work by:-

•LoveleenChee

ma•Dinesh Kumar

•Rohit Kumar

•Sahil garg

(DESH BHAGAT ENGG

COLLEGE )

Computer Science Engg .

Department

MANDHI GOBINDGARH

(PUNJAB)INDIA

Page 64: Six Week Training Presentation on c++ Programming From

Thanks a lot….