cercle.h

text/plain cercle.h — 2.4 KB

Contenu du fichier

/***********************************************************

    T.A.D. : Cercle

     Analyse

         Un cercle est connu par son rayon
         Les formules necessaires sont:
                 perimetre = 2<pi>r
                 surface = <pi>r2
**************************************************************/
#include <iostream>
using namespace std;

const float PI = 3.14159 ;

class Cercle
{
	float rayon ;
public:
	Cercle() ;
	Cercle(float) ;
	void lecture();
	void lecture(istream&);
	void imprime() ;
	void ecrire(ostream&) ;
	float perimetre() ;
	float surface() ;
} ;

/*****************************************************************

   Methodes pour le type Cercle
			 
*****************************************************************/
/*---------------------------------------------------------------
   Contructeurs
---------------------------------------------------------------*/

Cercle::Cercle()
{
	rayon = 0 ;
}
Cercle::Cercle(float valeur_rayon)
{
	rayon = valeur_rayon ;
}
/*---------------------------------------------------------------
   Lecture
---------------------------------------------------------------*/
// De l'entree standard (clavier)

void Cercle::lecture()
{
	cin >> rayon ;
}
// D'un stream quelconque (clavier, fichier, ...)
void Cercle::lecture(istream& in)
{
	in >> rayon ;
}
/*---------------------------------------------------------------
   Methode pour le calcul...
---------------------------------------------------------------*/

float Cercle::perimetre()
{
	return 2 * PI * rayon ;
}
float Cercle::surface()
{
	return PI * rayon * rayon ;
}
/*---------------------------------------------------------------
   Ecriture
---------------------------------------------------------------*/
// Sur la sortie standard (ecran)

void Cercle::imprime()
{
	cout << rayon ;
}
// Sur un stream quelconque (ecran, fichier, ...)
void Cercle::ecrire(ostream& out)
{
	out << rayon ;
}
/*---------------------------------------------------------------
   Redefinition de >> (pour la lecture)
---------------------------------------------------------------*/
istream& operator>>(istream& is, Cercle& rd) {
  
  rd.lecture(is);
  return is;
}
/*---------------------------------------------------------------
   Redefinition de << (pour l'ecriture)
---------------------------------------------------------------*/

ostream& operator<<(ostream& os, Cercle rd) {
 
 rd.ecrire(os);
 return os;
}