Print? /*
* Copyright and version Declaration of the program
* Copyright (c) 2013, a student from the computer College of Yantai University
* All rightsreserved.
* File name: object. cpp
. * Author: Yang shaoning
* Completion date: January 1, April 10, 2013
* Version: v1.0
* Input Description: None
* Problem description: design triangle and point classes.
* Program output: Output perimeter, area, and determine whether it is a right triangle or an isosceles triangle.
*/
Class CPoint // abc. h
{Private:
Double x; // abscissa
Double y; // ordinate
Public:
CPoint (double xx = 0, double yy = 0 );
Void input ();
Double Distance (CPoint p) const; // Distance between two points (one point is the current point, and the other point is the parameter p)
Void output (); // output coordinate points in the form of (x, y)
};
Class CTriangle
{
Public:
CTriangle (CPoint & X, CPoint & Y, CPoint & Z): A (X), B (Y), C (Z) {}// returns the three-point constructor.
Void setTriangle (CPoint & X, CPoint & Y, CPoint & Z );//
Float perimeter (void); // calculates the perimeter of a triangle.
Float area (void); // calculates and returns the area of the triangle.
Bool isRightTriangle (); // whether it is a right triangle
Bool isIsoscelesTriangle (); // determines whether it is an isosceles triangle.
Private:
CPoint A, B, C; // three vertices
};
// The first source file
# Include <iostream>
# Include <Cmath>
# Include "abc. h"
Using namespace std;
CPoint: CPoint (double xx, double yy)
{
X = xx;
Y = yy;
}
Void CPoint: input ()
{
Char c;
Cin> x> c> y;
If (c! = ',')
{
Cout <"input error, please enter again ";
Exit (0 );
}
}
Double CPoint: Distance (CPoint p) const // Distance between two points (one point is the current point, and the other point is the parameter p)
{
Double s;
S = sqrt (p. x-x) * (p. x-x) + (p. y-y) * (p. y-y ));
Return s;
}
Void CTriangle: setTriangle (CPoint & X, CPoint & Y, CPoint & Z )//
{
A = X;
B = Y;
C = Z;
}
Float CTriangle: perimeter (void) // calculates the triangle perimeter
{
Float a, B, c, l;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
L = a + B + c;
Return l;
}
Float CTriangle: area (void) // calculates and returns the area of the triangle.
{
Float a, B, c, p, s;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
P = (a + B + c)/2;
S = sqrt (p * (p-a) * (p-B) * (p-c ));
Return s;
}
Bool CTriangle: isRightTriangle () // whether it is a right triangle
{
Double a, B, c;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
Bool prime = false;
If (a * a + B * B = c * c) | (a * a + c * c = B * B) | (B * B + c * c = a * ))
{
Prime = true;
}
Return prime;
}
Bool CTriangle: isIsoscelesTriangle () // determines whether it is an isosceles triangle.
{
Double a, B, c;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
Bool prime = false;
If (a = B | a = c | B = c)
{
Prime = true;
}
Return prime;
}
// The second source file
# Include "abc. h"
Int main ()
{
CPoint x, y, z;
X. input ();
Y. input ();
Z. input ();
CTriangle tri (x, y, z); // copy the constructor
Cout <"the circumference of this triangle is:" <tri. perimeter () <", and the area is:" <tri. area () <endl;
Cout <"this triangle" <(tri. isRightTriangle ()? "Yes": "not") <"Cartesian triangle" <endl;
Cout <"this triangle" <(tri. isIsoscelesTriangle ()? "Yes": "no") <"isosceles triangle" <endl;
Return 0;
}
/*
* Copyright and version Declaration of the program
* Copyright (c) 2013, a student from the computer College of Yantai University
* All rightsreserved.
* File name: object. cpp
. * Author: Yang shaoning
* Completion date: January 1, April 10, 2013
* Version: v1.0
* Input Description: None
* Problem description: design triangle and point classes.
* Program output: Output perimeter, area, and determine whether it is a right triangle or an isosceles triangle.
*/
Class CPoint // abc. h
{Private:
Double x; // abscissa
Double y; // ordinate
Public:
CPoint (double xx = 0, double yy = 0 );
Void input ();
Double Distance (CPoint p) const; // Distance between two points (one point is the current point, and the other point is the parameter p)
Void output (); // output coordinate points in the form of (x, y)
};
Class CTriangle
{
Public:
CTriangle (CPoint & X, CPoint & Y, CPoint & Z): A (X), B (Y), C (Z) {}// returns the three-point constructor.
Void setTriangle (CPoint & X, CPoint & Y, CPoint & Z );//
Float perimeter (void); // calculates the perimeter of a triangle.
Float area (void); // calculates and returns the area of the triangle.
Bool isRightTriangle (); // whether it is a right triangle
Bool isIsoscelesTriangle (); // determines whether it is an isosceles triangle.
Private:
CPoint A, B, C; // three vertices
};
// The first source file
# Include <iostream>
# Include <Cmath>
# Include "abc. h"
Using namespace std;
CPoint: CPoint (double xx, double yy)
{
X = xx;
Y = yy;
}
Void CPoint: input ()
{
Char c;
Cin> x> c> y;
If (c! = ',')
{
Cout <"input error, please enter again ";
Exit (0 );
}
}
Double CPoint: Distance (CPoint p) const // Distance between two points (one point is the current point, and the other point is the parameter p)
{
Double s;
S = sqrt (p. x-x) * (p. x-x) + (p. y-y) * (p. y-y ));
Return s;
}
Void CTriangle: setTriangle (CPoint & X, CPoint & Y, CPoint & Z )//
{
A = X;
B = Y;
C = Z;
}
Float CTriangle: perimeter (void) // calculates the triangle perimeter
{
Float a, B, c, l;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
L = a + B + c;
Return l;
}
Float CTriangle: area (void) // calculates and returns the area of the triangle.
{
Float a, B, c, p, s;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
P = (a + B + c)/2;
S = sqrt (p * (p-a) * (p-B) * (p-c ));
Return s;
}
Bool CTriangle: isRightTriangle () // whether it is a right triangle
{
Double a, B, c;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
Bool prime = false;
If (a * a + B * B = c * c) | (a * a + c * c = B * B) | (B * B + c * c = a * ))
{
Prime = true;
}
Return prime;
}
Bool CTriangle: isIsoscelesTriangle () // determines whether it is an isosceles triangle.
{
Double a, B, c;
A = A. Distance (B );
B = B. Distance (C );
C = C. Distance ();
Bool prime = false;
If (a = B | a = c | B = c)
{
Prime = true;
}
Return prime;
}
// The second source file
# Include "abc. h"
Int main ()
{
CPoint x, y, z;
X. input ();
Y. input ();
Z. input ();
CTriangle tri (x, y, z); // copy the constructor
Cout <"the circumference of this triangle is:" <tri. perimeter () <", and the area is:" <tri. area () <endl;
Cout <"this triangle" <(tri. isRightTriangle ()? "Yes": "not") <"Cartesian triangle" <endl;
Cout <"this triangle" <(tri. isIsoscelesTriangle ()? "Yes": "no") <"isosceles triangle" <endl;
Return 0;
}
Feeling: review it !!!