01. /* 02. * copyright and version Declaration of the program part 03. * copyright (c) 2013, Yantai University Computer college student 04. * All rightsreserved. 05. * file name: Point. CPP 06. * Prepared by: Zhao guanzhe 07 * completion date: May 9, 2013 08. * version: V1.0 09. * input Description: 10. * Problem description: 11. */# include <iostream> # include <cmath> using namespace STD; Class Point // defines the coordinate class {public: Double X, Y; // point () {x = 0; y = 0;} Point (double x0, double y0) {x = x0; y = y0 ;} void printp () {cout <"Point :(" <x <"," <Y <")" ;}}; class line: public point // uses the coordinate point class to define the line class. The data member of the base class represents the midpoint of the line {PRIVATE: Class Point pt1, pt2; // The two endpoints of the line are public: line (point pts, point PTE); // constructor double dx () {return pt2.x-pt1.x;} double DY () {return pt2.y-pt1.y;} double length (); // calculate the length of a straight line void printl (); // two endpoints and straight line lengths of the Output Straight Line}; // constructor, initialize the corresponding endpoint with parameters and the line: Line (point pts, point PTE): Point (PTS. X + Pte. x)/2, (PTS. Y + Pte. y)/2) {pt1 = PTS; pt2 = PTE;} double line: length () {return SQRT (dx () * dx () + dy () * DY ();} // calculate the line length void line: printl () {cout <"1st"; pt1.printp (); cout <"\ N 2nd"; pt2.printp (); cout <"\ n the middle point of line:"; printp (); cout <"\ n the length of line:" <length () <Endl; // call length () to output the length of a straight line} int main () {point PS (-), PE (); line L (Ps, PE); L. printl (); // output line l Information L. printp (); // outputs the point information of the line L. cout <Endl; return 0 ;}
Running result: