apse lab
TRANSCRIPT
-
7/23/2019 APSE lab
1/23
APSE LAB
Submitted by:
Ravinder Kumar
Roll no: 1120021
Section: E1
Submitted to:
Dr.
Assistant Professor
Electrical Engineering Department
National Institute of ec!nology "uru#s!etra
August$ 201%
Page | 1
-
7/23/2019 APSE lab
2/23
SN EXPERMINENT NAME PAGE NO
1 Implementation of class and member function
by student name $ class and function for grade &
2 'se of friend function to access pri(ate data of
a class)
& Addition and multiplication of t*o comple+
number using operator o(erloading ,
) 'se of -t!is. pointer /
% ultiple and multile(el in!eritance11
, ybrid and !ierarc!ical in!eritance1%
3ate binding t!roug! (irtual function20
Page | 2
-
7/23/2019 APSE lab
3/23
1 .Implementatin ! "la## and mem$er !un"tin $% #tudent
name& "la## and !un"tin !r 'rade4include 5iostream64include 5conio7!6
4include 5stdio7!6using namespace std8
class student
9 int roll8
int n8 public:
(oid reg;
9cout55
-
7/23/2019 APSE lab
4/23
(. )#e ! !riend !un"tin t a""e## private data ! a "la##
4include5iostream7!6
4include5conio7!6
class ma!es!8
class mu#es!
9
int money8
public:
(oid getdat;
9
cout558
Page | 4
-
7/23/2019 APSE lab
5/23
class ma!es!
9
int money8
public:
(oid getdat;
9
cout558
(oid compmu#es! m1$ ma!es! m2;
9
ifm17money6m27money;
cout55
-
7/23/2019 APSE lab
6/23
compm1$m2;8
getc!;8
>
*. Additin and multipli"atin ! t+ "mple, num$er u#in'
peratr verladin'
4include5iostream6
4include 5stdio7!6
4include 5conio7!6
using namespace std8
class comple+
9
float real8
float img8
public:
comple+;9>
comple+float a$ float b;
9
real=a8
Page | 6
-
7/23/2019 APSE lab
7/23
img=b8
>
(oid s!o*;
9
ifimg60;
cout55real55
-
7/23/2019 APSE lab
8/23
returnc);8
>
int main;
9
comple+ c1%7%$)7,;8
comple+ c2,7$G/7%;8
comple+ c&8
comple+ c)8
c17s!o*;8
c27s!o*;8
c&=c1c28
c&7s!o*;8
c)=c1Hc28
c)7s!o*;8
getc!;8>
Page | 8
-
7/23/2019 APSE lab
9/23
-. )#e ! t/i#0 pinter
4include5iostream7!6
4include5conio7!6
4include5string7!6
class person
9 c!ar name&0J8
int age8
public:
person;9>8
personc!ar Hs$int age;8
(oid display;8
personB greaterperson Bp1;8
>
person::personc!ar Hs$int a;
9
strcpyname$s;8
age=a8
>
(oid person::display;
9
cout55
-
7/23/2019 APSE lab
10/23
9
ifage6p17age;
return Ht!is;8
else
return p18
>
(oid main;
9
person p
-
7/23/2019 APSE lab
11/23
>
. Multiple and multilevel in/eritan"e
A; ultiple in!eritances:
4include5iostream7!6
4include5conio7!6
class ram
9
public:
int m18
(oid getdata1int +;
9
m1=+8
Page | 11
-
7/23/2019 APSE lab
12/23
>
>8
class balram
9
public:
int m28
(oid getdata2int y;
9
m2=y8
>
>8
class total:public ram$public balram
9
int t8
public:
(oid sum;
9
t= m1 m28
>
(oid display;
9
cout558
Page | 12
-
7/23/2019 APSE lab
13/23
(oid main;
9
clrscr;8
total a8
a7getdata1)%;8
a7getdata2&%;8
a7sum;8
a7display;8
getc!;8
>
C; ultile(el in!eritances:
4include5iostream7!6
4include5conio7!6
Page | 13
-
7/23/2019 APSE lab
14/23
class student
9
protected: int rollno8
public:
(oid getnumberint a;
9
rollno=a8
>
(oid putnumber;
9
cout558
class mar#s:public student
9
public:
int s1$s28
(oid getmint a$int b;
9
s1=a8
s2=b8
>>8
class result:public mar#s
9
int total8
public:
Page | 14
-
7/23/2019 APSE lab
15/23
-
7/23/2019 APSE lab
16/23
2. 3%$rid and /ierar"/i"al in/eritan"e
A; ybrid in!eritance
4include5iostream7!6
4include5conio7!6
class student
9
public:
(oid name;
9
cout558
class mar#s:public student
9
Page | 16
-
7/23/2019 APSE lab
17/23
public:
(oid roll;
9
cout55
-
7/23/2019 APSE lab
18/23
cout558
(oid main;
9
clrscr;8
result r8
r7rs;8
r7name;8
r7mar#;8
r7medal;8
getc!;8
>
Page | 18
-
7/23/2019 APSE lab
19/23
C; ierarc!ical in!eritance
4include5iostream7!6
4include5conio7!6
class #
9
public:
int a8
(oid getnumber;
9
cout558
class b:public #
9
public:
(oid sMuare;
9
getnumber;8
cout558
class c:public #
9
Page | 19
-
7/23/2019 APSE lab
20/23
public:
(oid cube;
9
getnumber;8
cout558
(oid main;
9
clrscr;8
b b18
b17sMuare;8
c c18
c17cube;8
getc!;8
>
Page | 20
-
7/23/2019 APSE lab
21/23
4. Late $indin' t/ru'/ virtual !un"tin
4include5iostream7!6
4include5conio7!6
class base
9
public:
(irtual (oid s!o*;
9
cout55
-
7/23/2019 APSE lab
22/23
>
>8
class deri(ed:public base
9
public:
(oid s!o*;
9
cout55
-
7/23/2019 APSE lab
23/23
deri(ed d8
bptr=Bd8
bptrG6s!o*;8
bptrG6display;8
getc!;8
>
Page | 23