summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cercle.cpp27
-rw-r--r--rectangle.cpp52
2 files changed, 79 insertions, 0 deletions
diff --git a/cercle.cpp b/cercle.cpp
new file mode 100644
index 0000000..100291b
--- /dev/null
+++ b/cercle.cpp
@@ -0,0 +1,27 @@
+#include <cmath>
+#include "forme.h"
+
+class Cercle:Forme {
+ private:
+ int Rayon;
+ public:
+
+ Cercle(int x, int y, int r):Forme(x,y),Rayon(r) {
+ Coordonnee t = {x,y};
+ setAncrage(t);
+ SetRayon(r);
+
+ };
+
+ void afficher(ostream & s);
+ int GetRayon(){return Rayon;};
+ void SetRayon(int r){Rayon=r;};
+ double aire(){return M_PI*Rayon*Rayon;};
+ double perimetre(){return 2*M_PI*Rayon;};
+};
+
+void Cercle::afficher(ostream & s) {
+ s << "Cercle (x=" << getAncrage().x
+ << ", y=" << getAncrage().y
+ << ", r=" << GetRayon() << ", aire=" << aire() << ")";
+};
diff --git a/rectangle.cpp b/rectangle.cpp
new file mode 100644
index 0000000..f719ff9
--- /dev/null
+++ b/rectangle.cpp
@@ -0,0 +1,52 @@
+#include "forme.h"
+
+class Rectangle:Forme{
+ private:
+ int Largeur;
+ int Hauteur;
+
+ public:
+
+ Rectangle(int x, int y, int l, int h):Forme(x,y),Largeur(l),Hauteur(h){
+ Coordonnee t = {x,y};
+ setAncrage(t);
+ SetHauteur(h);
+ SetLargeur(l);
+ };
+
+ int GetLargeur(){return Largeur;};
+ int GetHauteur(){return Hauteur;};
+ void SetLargeur(int l){Largeur=l;};
+ void SetHauteur(int h){Hauteur=h;};
+ double aire(){return Largeur*Hauteur;};
+ void afficher(ostream &s);
+};
+
+void Rectangle::afficher(ostream &s){
+ // Resultat: "Rectangle (x=2, y=3, h=4, l=5, aire=5)"
+ s << "Rectangle (x=" << getAncrage().x
+ << ", y=" << getAncrage().y
+ << ", h=" << GetHauteur()
+ << ", l=" << GetLargeur()
+ << ", aire=" << aire()
+ << ")\n";
+ /* << ")" << endl; */
+};
+
+class Carre:Rectangle{
+ public:
+
+ Carre(int x, int y, int c):Rectangle(x,y,c,c){};
+
+ void afficher(ostream &s);
+};
+
+Carre::afficher(osstream &s){
+ // Resultat: "Carre (x=2, y=3, c=4, aire=5)"
+ s << "Carre (x=" << getAncrage().x
+ << ", y=" << getAncrage().y
+ << ", c=" << GetHauteur()
+ << ", aire=" << aire()
+ << ")\n";
+ /* << ")" << endl; */
+};