Académique Documents
Professionnel Documents
Culture Documents
#include <iostream>
#include <cmath>
class Point {
public:
float x;
float y;
Point(float a = 0, float b = 0){ // constructeur par défaut avec des valeurs par défaut
x = a;
y = b;
};
class Rectangle {
public:
Point p;
float longueur;
float largeur;
public:
Rectangle(Point p, float longueur, float largeur); // constructeur avec tous les attributs
};
Rectangle::Rectangle(){
longueur=0;
largeur=0;
Rectangle::Rectangle(Point k){
p = k;
this->longueur = r;
this->largeur = l;
p = k;
longueur = r;
largeur = l;
}
float Rectangle::surface() const{
void Rectangle::doublerDim(){
longueur *= 2;
largeur *= 2;
p.x += a;
p.y += b;
int main(){
Rectangle r1;
cout << "Rectangle r1 : longueur = " << r1.longueur << ", largeur = " << r1.largeur << ", p = (" <<
r1.p.x << ", " << r1.p.y << ")" << endl;
cout << "Rectangle r2 : longueur = " << r2.longueur << ", largeur = " << r2.largeur << ", p = (" <<
r2.p.x << ", " << r2.p.y << ")" << endl;
cout << "Rectangle r3 : longueur = " << r3.longueur << ", largeur = " << r3.largeur << ", p = (" <<
r3.p.x << ", " << r3.p.y << ")" << endl;
Rectangle r4(Point(1, 1), 3, 4);
cout << "Rectangle r4 : longueur = " << r4.longueur << ", largeur = " << r4.largeur << ", p = (" <<
r4.p.x << ", " << r4.p.y << ")" << endl;
cout << "Le périmètre de r4 est : " << r4.perimetre() << endl;
cout << "La surface de r4 est : " << r4.surface() << endl;
return 0 ;
}///////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cmath>
class Point {
private:
float x;
float y;
float z;
public:
~Point();
void affiche();
};
class Segment {
private:
Point p1;
Point p2;
public:
~Segment();
float longueur() const;
};
x = a;
y = b;
z = k;
Point::~Point() {
void Point::affiche() {
cout << "(" << x << ", " << y << ", " << z << ")";
Segment::Segment(Point a, Point b) {
p1 = a;
p2 = b;
Segment::~Segment() {
return x >= minX && x <= maxX && y >= minY && y <= maxY;
p1.affiche();
p2.affiche();
int main() {
s.affiche();
cout << "Le point (7, 0) appartient au segment : " << boolalpha << s.appartient(7, 0) << endl;
t.affiche();
cout << "Le point (0, 1) appartient au segment : " << boolalpha << t.appartient(0, 1) << endl;
return 0;
/////////////////////////////////////////////////////
#include <iostream>
#include <cmath>
class Point {
private :
float x;
float y;
float z;
public :
~Point(); // destructeur
void affiche();
static int getNombre(); // méthode statique pour obtenir le nombre d'objets créés
};
int Point::nb_points = 0;
y = b;
z = k;
Point::~Point() {
void Point::affiche() {
cout << "Les coordonnées sont : (" << x << ", " << y << ", " << z << ")" << endl;
cout << "Nombre d'objets Point créés : " << nb_points << endl;
int Point::getNombre() {
return nb_points;
int main() {
p1.affiche();
p2.affiche();
Point p4;
p4.affiche();
p5.affiche();
Point p6(5.6);
p6.affiche();
cout << "Nombre total d'objets Point créés : " << Point::getNombre() << endl;
return 0;