11th weekly computer task project 2

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.