0% found this document useful (0 votes)
11 views12 pages

C++ Concepts: Pointers, Inheritance, Polymorphism

The document provides an overview of C++ programming concepts, including pointers, virtual functions, inheritance, and polymorphism. It includes code examples demonstrating the creation of classes, function overloading, and the use of pointers in object-oriented programming. Additionally, it discusses the advantages of pointers and the syntax for defining derived classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views12 pages

C++ Concepts: Pointers, Inheritance, Polymorphism

The document provides an overview of C++ programming concepts, including pointers, virtual functions, inheritance, and polymorphism. It includes code examples demonstrating the creation of classes, function overloading, and the use of pointers in object-oriented programming. Additionally, it discusses the advantages of pointers and the syntax for defining derived classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Poge No.

MP Dote

a State Access specifie


used n 0oP
Private, public,protected

Define pointer
with example
ohich o

Pointer § A point
hold emory Addh ess
the memory
o +he
is variable

varible
Sntox :*
dataty pe pointer variablenames
.9 in+ *
ptH3

wrte any to rule fui+ual function


The func-+on must be declare by usin the

keyword virteal
vitua function must bo member of class

Define poiter opeYator add-ess of


operator with exomple
pointer operator - A poioter operateY can

bo represented why astrik tels the


complier the variable itfollows iS a

Poier.

int * ptE
Addrass of operator:
an
dcdress of operater cdln be represente
a combination of ampersend oith a
Pointer variable
eg -3e-ptr:
Teacher's Signature:.
Define l
inheritdnce.+ileveiero rehiCa)
Poge

Dote
No

mul+ileel &when one


froa n0the clasS derived
[Link]
knoon ds multleve
inheritance,
HieraYchiCal- Hn +nis +pe of
tance there is mo-e than inheri
clase
one
sinq le base claes.

tate +he advon+oges f poi+er


pointer Can Save the memory Space
memory accesS ef fFectenty weak
pointer
pointer are use for+iS file handling.

T Lrite docbJ +he sntax for creatinn the


derived class.
Sntax: class clerivedclassname: visibi
ty mod baseclassname

// bod of derived class

onlfs+ file modes sed ir 00p

Teacher's Signature:
9-1 Differentiate between comple ine
Polmorphieum f runtine polmephsur
Com pile time runtime

T+ is also caIled ds -t is also calle


Static Polymorphism a dnamic Phor
phisum
+ Compi le +inne -it Runtime polyncr
polymorphisum com- phisum uhich funes
piler defermne ohich to be call its deterr
opereation to be call ne at tuntime. Bose
bage on number type on actual object tuo
Order of argumen

3 function calls are - function calls are


stactically Binding. dynanically bindina

TYpes: - Typesi
> func+ion overload- function overridin
ing 2> virtua function.
operation overload
ing

faster execution S Smaler execution


rate rate

Tnheritance 1s not Ingolve inheritance


iovolve

Teacher's Signature:
Page No.

Dote

:
b te a Ctt progdm create a claSS
train the data members off +rain
cla sS +rain no, name accept } iSplay d

it for one object use pointer


to bject concep
# include <iostream. h

f include<coniohy
sIng nomespace std
class Traín
,
Pbie:
int train no3
cha- name
void accept C)

Cou\nenter t70 Tan no name of


Train";
CinTHain no > name;
vOid displa C)

cO"n TOino is'hTain no;


co<"ln hdme is'< n07o;

woid main c)

Train tii
tptr accept co

tpt-> dsPlay c).


etchO Teacher's Signature:
Agn N

c++ ptogram to oVe load


its a

functin to add too intege nu mbe


to tuO Float number
# include iostreamh>
#include conio
uSingnamespace Stds
void add (int a, int b)

coutknAddition o too integer no is<<Ca

float add (floate, float )


retur n Cet):
void main C)

addCIo, 0)
zi
float
Z add Cas, 4-)3
COut<1nAddtion f
<Z
tcoo float number e
getch CO

wrte a poogoo m to impemet fol losi 29


inheritance.

gtaP
code

Teacher ficcer
Subname grade
Teacher's Signature:.
include <iostream.h>
1nclude conio.h>
uSIng nameSpace stdi
class staff

Public
int code;

class Teacher :publíc staff

public:
char Su bname l,
void acceptC

COut <n
enter +he code of Teachet
Subname's
cin>> code Subnamei

cout<<in Teacher Info


cOut<<n cocle is zK cocle;
COut'\n subrde is"Subna 30;

class officeri public Staf f

public
char g-ade
Void
|I.
getdata C)

cowtK Inenter the officer code


97ade Teacher'sSignature:.

cin grade>Code
Page No.:

Dota

Vold show C

COutn
Cout<|n fficer
ofFicer
officer
n fo
code'l<
coce;
qvade '<gd
de ,
Cout <l1n
Void main C)

Teacher Ti
[Link] :
Ti. disploy c)
fficor ol
. 9etdatac:
show CO

Dqe tch C)

c++ program to over load the


Swrite a to- to negate the values
Pero

#
+
unal-
inclde<iost
include<conio
-eamh>
h

using namespaCe
claSS Sampler
public:
in+,)
Void qetdata (intP, int)

Teacher's Signature:
void operateC

-4;

void d isplayO
Cout<'lne"<ej
cOut"\ny l<,

int main C)

Sample siS
Sl- getd ata C1O20);
co< ln Before oveYIoadi ng
[Link] C;

GO}te a ctt program to declare


c0de berive
clas Oith Name
colleae
a new class as Student Oith
menber as Rollno p070 (ccert
diSplay de+ai ls of0ne stude qlOno
oith college data
college
okcode
dme
Student
Rollno
namne Teachet's Signature:..
Poge No.

Date

include Toethoam.>
+ include <conio h
Sing names pace Std,
class college

public
int c0~lege code)
char colleqe noye l j

void acce0

cautlh enter the college codef


college
name;
cin>colleqe code college name;

class student ? public college

public:
int os
Roll no
char nome L1
void gedata C)0
cOutN enter the Rol nos
ocìn Roll noCO 0ea
cout <<'n enter thename
cin ndmejb
void display c)

COut|n colle ge code is'< college co

cOut<<"1n colleae ndme is <colleg

Teacher's Sign ature:......


Poge No.:

Dote :

cOutn Rol) no ig' Rno;


cout<n name sK name;

void main C)

Student SI
S1: acceetc
Sl: ge tdata c)j
St-displo c);
getch );

Explain virtual eaee cass i+h exdmpe

ol
the

student Follno, name ing


Test eSPOrt
m)n2
resu t

The

Teacher's Signature:
Poge No.:

Dote

incl de-i0steam,>
# inlude < conioe
6In nomespace Sto;
class stucent

public :
char ndme I
class test :vituC public studen+

Int
public
mi,
:
ni
Voide qetnaks C)

Cout <<"{nenter Hhe value 0f


Cìn m>me) mi ma'

clags sport & vìrtua


public studo
public:

Void qetspots mrks c)


COut K|n ente the Sportmark"s
cin S)

class result :Public test, public


Sport

Teacher'sSianature
Poge No.

Dote

publca
int tel;
void accept O
COut<n enter t he rolnof name
cin

void

total= m+
)
tollno>namej
display

m t Sli
Coutel |n rollno i:"e rollno,
cOute"In name is namei
COu<n +a'L< tota;
Void main O

-esult RI;
Rl accept C);
R getmarks C);
Rl getsportmarks CO3
RI: display o;
gch c;

Teacher's Signature:.

You might also like