/** Copyright (c) 2013, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Yang Chen * completion date: October 0 * version: v1.0 ** input Description: none * Problem description: * program output: * Problem Analysis: * Algorithm Design: slightly */# include <iostream> # include <Cmath> using namespace std; class Point // defines the coordinate class {public: Point (): x (0 ), y (0) {}; Point (double x0, double y0): x (x0), y (y0) {}; void PrintPoint (); // output vertex information double x, y; // data member, indicating the abscissa and ordinate of the vertex}; void Point: PrintPoint () {cout <"Point :(" <x <"," <y <")"; // output Point} 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 {public: Line (Point pt1, Point pt2): pt1 (pt1 ), pt2 (pt2) {}// constructor, initialize the two endpoints of a straight line and the midpoint double Length () described by the base class data members (); // calculate and return the line length void PrintLine (); // the two ends of the output line and the line length private: class Point pt1, pt2; // the two ends of the line }; // The following defines the Line class member function double Line: Length () {return sqrt (pt1.x-pt2.x) * (pt1.x-pt2.x) + (pt1.y-pt2.y) * (pt1.y-pt2.y);} void Line: PrintLine () {Point ptm; ptm. x = (pt1.x + pt2.x)/2; ptm. y = (pt1.y + pt2.y)/2; cout <"(" <ptm. x <"," <ptm. y <")" <endl;} int main () {Point ps (-), pe (); Line l (ps, pe ); cout <"\ n The length of Line:"; cout <l. length () <endl; // output Line l Information (please complete The Code) cout <"\ n The middle point of Line:"; l. printLine (); // output the point information of the line l (please complete the Code) return 0 ;}
Output result: