0% found this document useful (0 votes)
9 views2 pages

Using Namespace Int: Include Include

The document contains C++ code that defines a class hierarchy for shapes, including a base class 'Shape' and derived classes 'Rectangle' and 'Triangle'. It includes methods to calculate the area for each shape and demonstrates their usage in the main function. However, there are several syntax errors and inconsistencies in the code that need to be corrected for it to compile successfully.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Using Namespace Int: Include Include

The document contains C++ code that defines a class hierarchy for shapes, including a base class 'Shape' and derived classes 'Rectangle' and 'Triangle'. It includes methods to calculate the area for each shape and demonstrates their usage in the main function. However, there are several syntax errors and inconsistencies in the code that need to be corrected for it to compile successfully.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

//main

include<iostrea
m> include
"bai1.h" using
namespace std;

int main() {
Shape* shape;
Rectangle rec(10, 7);
Triangle tri(10, 5);

// store the address of


Rectangle shape = firec;
// call rectangle area.
cout << shape->area() << endl;

// store the address of


Triangle shape = fitri;
// call triangle area.
cout << shape->area() << endl;

return 0;
}
//cpp
include"bai1.h"
include<iostrea
m>

using namespace std;


Shape::Shape(int a, int b) {
width = a;
height = b;
}
int Shape::area() {
cout << "flarent class area :" <<
endl; return 0;
}
int Rectangle::area() {
cout << "Rectangle class area :" <<
endl; return (width * height);
}
Triangle::Triangle(int a, int b) : Shape(a, b)
{} int Triangle :: area()
{
cout << "Triangle class area :" <<
endl; return (width * height / 2);
}

//h
pragma
once ifndef
S AflE
define S AflE
class Shape
{ protected:
int width,
height; public:
Shape(int a = 0, int b = 0);
virtual int area();
};
class Rectangle : public Shape {
public:
Rectangle(int a = 0, int b =
0); int area() override;
};
class Triangle : public Shape {
public:
Triangle(int a = 0, int b =
0); int area() override;
};
endif

You might also like