Skip to content

Commit

Permalink
060319 - poly version 5 - build done
Browse files Browse the repository at this point in the history
  • Loading branch information
quanhuynh2007 committed Mar 5, 2019
1 parent 6da7c56 commit df89e00
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 0 deletions.
1 change: 1 addition & 0 deletions c4GenSpecPoly/complileCPP.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
./polyV2RectangleSquare/complileCPP.sh
./polyV3RectangleSquare/complileCPP.sh
./polyV4RectangleSquare/complileCPP.sh
./polyV5RectangleSquare/complileCPP.sh
8 changes: 8 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Circle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "Circle.h"
Circle::Circle(float r): Ellipse(r, r) {}

void Circle::Input(istream& inDev)
{
inDev >> Ra;
Rb = Ra;
}
10 changes: 10 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Circle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _CIRCLE_
#define _CIRCLE_
#include "Ellipse.h"
class Circle: public Ellipse
{
public:
Circle(float r = 0);
virtual void Input(istream& inDev);
};
#endif
13 changes: 13 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Ellipse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Ellipse.h"
Ellipse::Ellipse(float a, float b)
{
Ra = a; Rb = b;
}
void Ellipse::Input(istream& inDev)
{
inDev >> Ra >> Rb;
}
float Ellipse::Area()
{
return PI * Ra * Rb;
}
15 changes: 15 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Ellipse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef _ELLIPSE_H
#define _ELLIPSE_H
#define PI (float)3.14159
#include "Figure.h"

class Ellipse : public Figure
{
protected:
float Ra, Rb;
public:
Ellipse(float a = 0, float b = 0);
virtual void Input(istream& inDev);
virtual float Area();
};
#endif
12 changes: 12 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Figure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _Figure_h
#define _Figure_h
#include <iostream>
using namespace std;

class Figure
{
public:
virtual void Input(istream& inDev) = 0;
virtual float Area() = 0;
};
#endif
39 changes: 39 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/MainProgRecSqua.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "Figure.h"
#include "Square.h"
#include "Circle.h"
#include "Triangle.h"

Figure* figMaxArea(Figure* figs[], int nFig)
{
Figure* figMax = NULL;
cout << endl << "figMaxArea: " << figs[0]->Area();
if (nFig > 0)
{
figMax = figs[0];
for (int i = 1; i < nFig; i++)
{
cout << " " << figs[i]->Area();
if (figMax->Area() < figs[i]->Area())
{
figMax = figs[i];
}
}
}
return figMax;
}
int main()
{
cout << endl << "polyV5RectangleSquare MainProgRecSqua.cpp Triangle.cpp Circle.cpp Ellipse.cpp Square.cpp Rectangle.cpp" << endl;

Figure* Figs[] = { new Rectangle(9.3F, 9.7F), new Circle(4.5F),
new Ellipse(9.24, 4.7F), new Square(9.5F),
new Triangle(10.7F, 6.4F), new Ellipse(3.7F, 7.8F)
};
int nFig = sizeof(Figs)/sizeof(Figure*);
Figure* aFig = figMaxArea(Figs, nFig);
if (aFig != NULL)
{
cout << endl << "Max = " << aFig->Area() << endl;
}
return 0;
}
14 changes: 14 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Rectangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Rectangle.h"

Rectangle::Rectangle(float w, float h)
{
width = w; height = h;
}
void Rectangle::Input(istream& inDev)
{
inDev >> width >> height;
}
float Rectangle::Area()
{
return width * height;
}
13 changes: 13 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Rectangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _Rectangle_h
#define _Rectangle_h
#include "Figure.h"
class Rectangle: public Figure
{
protected:
float width, height;
public:
Rectangle(float w = 0, float h = 0);
virtual float Area();
virtual void Input(istream& inDevice);
};
#endif
11 changes: 11 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Square.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Square.h"

Square::Square(float a)
{
width = height = a;
}
void Square::Input(istream& inDev)
{
inDev >> width;
height = width;
}
12 changes: 12 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Square.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _Square_h
#define _Square_h
#include "Rectangle.h"

class Square : public Rectangle
{
public:
Square(float a = 0);
virtual void Input(istream& inDevice);
};

#endif
13 changes: 13 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Triangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Triangle.h"
Triangle::Triangle(float a, float h)
{
basesize = 0; height = h;
}
void Triangle::Input(istream& inDev)
{
inDev >> basesize >> height;
}
float Triangle::Area()
{
return basesize * height / 2;
}
13 changes: 13 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/Triangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _Triangle_h
#define _Triangle_h
#include "Figure.h"
class Triangle: public Figure
{
protected:
float basesize, height;
public:
Triangle(float a = 0, float h = 0);
virtual float Area();
virtual void Input(istream& inDev);
};
#endif
3 changes: 3 additions & 0 deletions c4GenSpecPoly/polyV5RectangleSquare/complileCPP.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd polyV5RectangleSquare/
g++ MainProgRecSqua.cpp Triangle.cpp Circle.cpp Ellipse.cpp Square.cpp Rectangle.cpp; ./a.out
cd ..

0 comments on commit df89e00

Please sign in to comment.