« Programmation C++/Les structures/Exercices » : différence entre les versions

Contenu supprimé Contenu ajouté
Ligne 225 :
struct point
{
double x,y;
};
 
Ligne 232 :
double distance(point a, point b);
void milieu(point a, point b, point &m);
 
#endif
</source>
Ligne 238 ⟶ 239 :
#include "point.h"
#include <iostream>
using namespace std;
#include <cmath>
 
using namespace std;
 
void saisir_point(point &p)
{
cout << "Tapez l'abscisse du point : "; cin >> p.x;
cout << "Tapez l'ordonnée du point : "; cin >> p.y;
}
 
void afficher_point(point p)
{
cout << "Abscisse du point : " << p.x << endl;
cout << "Ordonnée du point : " << p.y << endl;
}
 
double distance(point a, point b)
{
double dx,dy;
dx = a.x - b.x;
dy = a.y - b.y;
return sqrt( dx*dx + dy*dy );
}
 
void milieu(point a, point b, point &m)
{
m.x = (a.x + b.x) /2;
m.y = (a.y + b.y) /2;
}
</source>
'''Fichier main.cpp)'''
<source lang="cpp">
#include "point.h"
#include <iostream>
 
using namespace std;
 
int main()
{
point X,Y,Z;
double d;
 
cout << "SAISIE DE X" << endl;
saisir_point(X);
cout<<"SAISIE DE Y"<<endl;
 
saisir_point(Y); d=distance(X,Y);
cout<<"La distance de X àcout Y<< est"SAISIE :DE Y" <<d<< endl;
saisir_point(Y);
milieu(X,Y,Z);
 
cout<<"AFFICHAGE DU POINT Z" <<endl;afficher_point(Z);
saisir_point(Y); d = distance(X,Y);
return 0;
cout << "La distance de X à Y est : " << d << endl;
 
milieu(X,Y,Z);
cout << "AFFICHAGE DU POINT Z" << endl;afficher_point(Z);
afficher_point(Z);
 
return 0;
}
</source>