[Cpp]
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Qiu xuewei
* Completion date: January 1, May 10, 2013
* Version: v1.0
* Input Description: None
* Problem description: The vertex is a base class and a straight line class is derived.
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
# Include <Cmath>
Using namespace std;
Class Point // defines the coordinate Point class
{
Public:
Point (): x (0), y (0 ){};
Point (double x0, double y0): x (x0), y (y0 ){};
Void PrintPoint (); // output point information
Double x, y; // data member, indicating the abscissa and ordinate of a point
};
Void Point: PrintPoint ()
{
Cout <"Point :(" <x <"," <y <")"; // output Point
}
Class Line: public Point // uses the coordinate Point class to define a Line class. The data member of the base class represents the midpoint of the Line.
{
Public:
Line (Point pt1, Point pt2); // constructor that initializes the two endpoints of a Line and the midpoint described by the base-class data members
Double Length (); // calculates and returns the Length of a straight line.
Void PrintLine (); // two endpoints of the output line and the line length
Void PrintPoint ();
Private:
Class Point pts, pte; // two endpoints of a straight line
};
// The member functions of the Line class are defined below
Line: Line (Point pt1, Point pt2)
{
Pts = pt1;
Pte = pt2;
}
Double Line: Length ()
{
Double d;
D = sqrt (pts. x-pte.x) * (pts. x-pte.x)-(pts. y-pts.y) * (pts. y-pts.y ));
Cout <"Length:" <d;
Return 0;
}
Void Line: PrintPoint ()
{
Cout <"Point :(" <(pts. x + pte. x)/2 <"," <(pts. y + pte. y)/2 <")" <endl;
}
Void Line: PrintLine ()
{
Point p1, p2;
P1 = pte;
P2 = pts;
Cout <"endpoint:" <endl;
P1.PrintPoint ();
Cout <"";
P2.PrintPoint ();
}
Int main ()
{
Point ps (-2, 5), pe (7, 9 );
Line l (ps, pe );
L. PrintLine ();
Cout <endl;
L. Length (); // output line l Information (please complete the code)
Cout <endl;
Cout <"The middle point of Line :";
L. PrintPoint (); // output the point information of the line l (complete the code)
}
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Qiu xuewei
* Completion date: January 1, May 10, 2013
* Version: v1.0
* Input Description: None
* Problem description: The vertex is a base class and a straight line class is derived.
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
# Include <Cmath>
Using namespace std;
Class Point // defines the coordinate Point class
{
Public:
Point (): x (0), y (0 ){};
Point (double x0, double y0): x (x0), y (y0 ){};
Void PrintPoint (); // output point information
Double x, y; // data member, indicating the abscissa and ordinate of a point
};
Void Point: PrintPoint ()
{
Cout <"Point :(" <x <"," <y <")"; // output Point
}
Class Line: public Point // uses the coordinate Point class to define a Line class. The data member of the base class represents the midpoint of the Line.
{
Public:
Line (Point pt1, Point pt2); // constructor that initializes the two endpoints of a Line and the midpoint described by the base-class data members
Double Length (); // calculates and returns the Length of a straight line.
Void PrintLine (); // two endpoints of the output line and the line length
Void PrintPoint ();
Private:
Class Point pts, pte; // two endpoints of a straight line
};
// The member functions of the Line class are defined below
Line: Line (Point pt1, Point pt2)
{
Pts = pt1;
Pte = pt2;
}
Double Line: Length ()
{
Double d;
D = sqrt (pts. x-pte.x) * (pts. x-pte.x)-(pts. y-pts.y) * (pts. y-pts.y ));
Cout <"Length:" <d;
Return 0;
}
Void Line: PrintPoint ()
{
Cout <"Point :(" <(pts. x + pte. x)/2 <"," <(pts. y + pte. y)/2 <")" <endl;
}
Void Line: PrintLine ()
{
Point p1, p2;
P1 = pte;
P2 = pts;
Cout <"endpoint:" <endl;
P1.PrintPoint ();
Cout <"";
P2.PrintPoint ();
}
Int main ()
{
Point ps (-2, 5), pe (7, 9 );
Line l (ps, pe );
L. PrintLine ();
Cout <endl;
L. Length (); // output line l Information (please complete the code)
Cout <endl;
Cout <"The middle point of Line :";
L. PrintPoint (); // output the point information of the line l (complete the code)
}