-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvfunc3.cpp
More file actions
71 lines (65 loc) · 1.12 KB
/
Copy pathvfunc3.cpp
File metadata and controls
71 lines (65 loc) · 1.12 KB
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
69
70
71
/*wap with base class as a number contains and integer val .A function setval() and a pure
virtual function calls show.
Three devried classes
->hextype
->dectype
->octtype
inherits number and defines the show function.The output the value of val changed in each
repective class.*/
#include<iostream>
#include<math.h>
using namespace std;
class number
{
protected: int val;
public:
void setval(int x)
{
val=x;
}
virtual void show()=0;
};
class hextype:public number
{
public:
void show()
{
cout<<"hex type "<<hex<<val<<endl;
}
};
class dectype:public number
{
public:
void show()
{
cout<<"dec type "<<dec<<val<<endl;
}
};
class octtype:public number
{
public:
void show()
{
cout<<"oct type "<<oct<<val<<endl;
}
};
int main()
{
number *p;
hextype h;
dectype d;
octtype o;
p=&h;
p->setval(100);
p->show();
p=&o;
p->setval(100);
p->show();
p=&d;
p->setval(100);
p->show();
// p=&d;
// p->setval(100);
// p->show();
return 0;
}