-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvirtualFunctionEx.cpp
68 lines (63 loc) · 1.02 KB
/
virtualFunctionEx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include<string>
using namespace std;
class Media
{
protected:
string title;
int price;
public:
Media(string a, int p)
{
title = a;
price = p;
cout << title << endl;
}
void virtual display()
{
cout << "In media" << endl;
}
};
class Book : public Media
{
int pages;
public:
Book(string a, int p, int pg) : Media(a,p)
{
pages = pg;
}
void display()
{
cout << "Title of the book: " << title << endl;
cout << "Price of the book: " << price << endl;
cout << "Number of pages: " << pages << endl;
}
};
class Tape : public Media
{
int duration;
public:
Tape(string a, int p, int d) : Media(a,p)
{
duration = d;
}
void display()
{
cout << "Title of the tape: " << title << endl;
cout << "Price of the tape: " << price << endl;
cout << "Duraiton of the tape: " << duration << endl;
}
};
int main()
{
Media m1("hello",34),*mptr;
mptr = &m1;
mptr->display();
Book b1("ksajdflk",23,61);
mptr = &b1;
mptr->display();
Tape t1("dksj",54,7);
mptr = &t1;
mptr->display();
return 0;
}