Triangle appelant point.h
Bonjour
Je suis nouveau en C++ et j'ai un souci. J'ai du dans un premier temps creer un header file nommé point.h et un fichier point.cpp pour creer un point
Mon point.h contient cela notamment:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
// header file for this class point
#include <cstdlib>
#include <iostream>
#ifndef POINT_H
#define POINT_H
#include <cmath>
using namespace std;
const double X_MAX=100.0; //declaration of the constant X_MAX
const double Y_MAX=100.0; //declaration of the constant Y_MAX
//Class Point represents points in the Cartesian coordinate
class point
{
private:
double x_coord, y_coord; //coordinates of the point
double dx, dy; //for the translation over (dx,dy)
double x1,x2,y1,y2; //require for translate
public:
//pre: -X_MAX < x < X_MAX and -Y_MAX < y < Y_MAX
//post: construct a Point object with x_coord = x and y_coord=y
point(double, double); |
--------------
Mon fichier point.cpp contient:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// definition file for this class point
#include <iostream>
#include <cstdlib>
#include "point.h"
using namespace std;
point::point(double x, double y){
x_coord=x;
y_coord=y;
} |
--------
Pour appeler mon point, j'ai juste à faire:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
#include <cstdlib>
#include <iostream>
#include "triangle.h"
int main()
{
//we start with a point equal with x_coord = 20 and y_coord = 20
// point p=point(20,20);
// cout << "The contents of the object are: " ;
// p.write(); |
Mais maintenant je dois creer un triangle utilisant ce fichier point.h et là je suis perdu ..
J'ai créer un fichier triangle.h où j'ai écrit:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
// header file for this class point
#include <cstdlib>
#include <iostream>
#include "point.h"
#ifndef TRIANGLE_H
#define TRIANGLE_H
#include <cmath>
using namespace std;
//Class Triangle represents a triangle
class triangle
{
private:
const point p1_coord;
const point p2_coord;
const point p3_coord;
public:
//post:constructs a triangle object containing p1, p2 and p3
triangle(const point, const point, const point);
}:
#endif |
--------------------
Pour le fichier triangle.cpp j'ai écrit
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// definition file for this class point
#include <iostream>
#include <cstdlib>
#include "triangle.h"
using namespace std;
triangle::triangle(const point p1, const point p2,const point p3){
p1_coord=p1;
p2_coord=p2;
p3_coord=p3;
} |
-------------
et pour appeler, j'ai créer main2.cpp où j'ai écrit
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <cstdlib>
#include <iostream>
#include "triangle.h"
int main()
{ cout << "The contents of the triangle is: ";
point p1=point(20,20);
point p2=point(-10,-10);
point p3=point(-10,30);
triangle T=triangle(p1,p2,p3);
system("PAUSE");
} |
Naturellement, ça ne marche pas. Pourriez vous svp m'aider à créer ce triangle en utilsant point.h?