Skip to content

Commit 487b3be

Browse files
committed
add: cpp-programming-questions 13_virtual_abstract 00
1 parent c5f19e1 commit 487b3be

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

13_virtual_function_and_abstract_class/01_shape_rectangle_triangle.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ class Shape
2323
}
2424

2525
// instance member function to display the area
26-
virtual void displayArea()
26+
virtual void displayArea() const
2727
{
28+
cout << "\nNot Implemented this for class Shape...";
2829
}
2930
};
3031

@@ -33,7 +34,7 @@ class Triangle : public Shape
3334
{
3435
public:
3536
// instance member function to display the area
36-
void displayArea()
37+
void displayArea() const override
3738
{
3839
cout << "\nArea of Triangle => " << 0.5 * d1 * d2;
3940
}
@@ -44,22 +45,24 @@ class Rectangle : public Shape
4445
{
4546
public:
4647
// instance member function to display the area
47-
void displayArea()
48+
void displayArea() const override
4849
{
4950
cout << "\nArea of Rectangle => " << d1 * d2;
5051
}
5152
};
5253

5354
int main()
5455
{
55-
Rectangle r1;
56-
r1.setData(4, 5);
57-
r1.displayArea();
58-
56+
// // create an instance of Triangle
5957
Triangle t1;
6058
t1.setData(4, 3);
6159
t1.displayArea();
6260

61+
// // create an instance of Rectangle
62+
Rectangle r1;
63+
r1.setData(4, 5);
64+
r1.displayArea();
65+
6366
cout << endl; // Add new line
6467
getch();
6568
return 0;

0 commit comments

Comments
 (0)