-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritence2.cpp
More file actions
69 lines (67 loc) · 1.24 KB
/
inheritence2.cpp
File metadata and controls
69 lines (67 loc) · 1.24 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
//Program that shows inheritance with virtual methods
#include<iostream>
#include<cstring>
using namespace std;
class movie
{
char* name;
char* category;
public:
movie();
movie(char[],char[]);
~movie();
virtual void display();
};
movie::movie()
{
name=new char[10];
category=new char[10];
name="no name";
category="bolly";
cout<<"default constructor called"<<endl;
}
movie::movie(char a[10],char b[10])
{
name=new char[strlen(a)];
category=new char[strlen(b)];
strcpy(name,a);
strcpy(category,b);
cout<<"Parametrized constructor called"<<endl;
}
movie::~movie()
{
delete[]name;
delete[]category;
cout<<"Destructor called"<<endl;
}
void movie::display()
{
cout<<"name"<<name<<endl;
cout<<"category"<<category<<endl;
}
class bolly:public movie
{
int ratings;
public:
bolly();
bolly(char[],char[],int);
void display();
};
bolly::bolly()
{
ratings=0;
}
bolly::bolly(char c[10],char d[10],int ratings):movie(c,d)
{
this->ratings=ratings;
}
void bolly::display()
{
movie::display();
cout<<"ratings"<<ratings<<endl;
}
int main()
{
movie *m1=new bolly("lol","jok",3);
m1->display();
}