Point-derived outlet 1

Source: Internet
Author: User

[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)
}

 

 

Related Article

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.