Skip to content

Instantly share code, notes, and snippets.

@manutheblacker
Created October 4, 2020 06:47
Show Gist options
  • Save manutheblacker/384c33a9513ac0ab20a88e45896fe2dd to your computer and use it in GitHub Desktop.
Save manutheblacker/384c33a9513ac0ab20a88e45896fe2dd to your computer and use it in GitHub Desktop.
Projet 8 cpp ecole
#include <iostream>
using namespace std;
class Rectangle {
private:
double longueur;
double largeur;
double perimetre;
double surface;
public:
Rectangle(double longueur = 1, double largeur = 1) {
this->setLongueur(longueur);
this->setLargeur(largeur);
this->setPerimetre();
this->setSurface();
}
double getLongueur() {
return this->longueur;
}
double getLargeur() {
return this->largeur;
}
void setLongueur(double longueur) {
this->longueur = longueur;
}
void setLargeur(double largeur) {
this->largeur = largeur;
}
void setPerimetre() {
double perimetre = this->getLongueur() + this->getLargeur() / 2;
this->perimetre = perimetre;
}
double getPerimetre() {
return this->perimetre;
}
void setSurface() {
double surface = this->getLongueur() * this->getLargeur();
this->surface = surface;
}
double getSurface() {
return this->surface;
}
};
int main() {
Rectangle ecole(100, 50);
cout << "Le périmètre correspondant aux valeurs données est : " << ecole.getPerimetre() << "m" << endl;
cout << "La surface correspondant aux valeurs données est : " << ecole.getSurface() << "m" << endl;
cout << "La longueur est : " << ecole.getLongueur() << "m" << endl;
cout << "La largeur est : " << ecole.getLargeur() << "m" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment