Information of vertices inherited from the base class indicates the midpoint of a straight line

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 11, 2013
* Version: v1.0
* Input Description: None
* Problem description: defines the vertex class and uses the vertex class as the base class to derive a straight line class. The vertex information inherited from the base class indicates the midpoint of the straight line.
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Point
{
Public:
Point (): x (0), y (0 ){};
Point (double x1, double y1)
{
X = x1;
Y = y1;
}
Double getx () {return x ;}
Double gety () {return y ;}
Void display ();
Private:
Double x, y;
};
Void Point: display ()
{
Cout <"Point :(" <x <"," <y <")" <endl;
}
Class Line: public Point
{
Public:
Line (Point p1, Point p2 );
Double Lengh ();
Void PrintLine ();
Void PrintPoint ();
Private:
Class Point pts, pte;
};
Line: Line (Point p1, Point p2)
{
Pts = p1;
Pte = p2;
 
}
Double Line: Lengh ()
{
Double x0 = pts. getx ()-pte. getx ();
Double y0 = pts. gety ()-pte. gety ();
Return sqrt (x0 * x0 + y0 * y0 );
 
}
Void Line: PrintLine ()
{
Cout <"endpoint:" <endl;
Pts. display ();
Pte. display ();
Cout <"Length:" <Lengh () <endl;
}
Void Line: PrintPoint ()
{
Cout <"(" <(pts. getx () + pte. getx ()/2 <"," <(pts. gety () + pte. gety ()/2 <")" <endl;
}
Int main ()
{
Point pt (-), pe );
Line l (pt, pe );
L. PrintLine ();
Cout <"midpoint:" <endl;
L. PrintPoint ();
Return 0;
}

/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Qiu xuewei
* Completion date: January 1, May 11, 2013
* Version: v1.0
* Input Description: None
* Problem description: defines the vertex class and uses the vertex class as the base class to derive a straight line class. The vertex information inherited from the base class indicates the midpoint of the straight line.
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Point
{
Public:
Point (): x (0), y (0 ){};
Point (double x1, double y1)
{
X = x1;
Y = y1;
}
Double getx () {return x ;}
Double gety () {return y ;}
Void display ();
Private:
Double x, y;
};
Void Point: display ()
{
Cout <"Point :(" <x <"," <y <")" <endl;
}
Class Line: public Point
{
Public:
Line (Point p1, Point p2 );
Double Lengh ();
Void PrintLine ();
Void PrintPoint ();
Private:
Class Point pts, pte;
};
Line: Line (Point p1, Point p2)
{
Pts = p1;
Pte = p2;

}
Double Line: Lengh ()
{
Double x0 = pts. getx ()-pte. getx ();
Double y0 = pts. gety ()-pte. gety ();
Return sqrt (x0 * x0 + y0 * y0 );

}
Void Line: PrintLine ()
{
Cout <"endpoint:" <endl;
Pts. display ();
Pte. display ();
Cout <"Length:" <Lengh () <endl;
}
Void Line: PrintPoint ()
{
Cout <"(" <(pts. getx () + pte. getx ()/2 <"," <(pts. gety () + pte. gety ()/2 <")" <endl;
}
Int main ()
{
Point pt (-), pe );
Line l (pt, pe );
L. PrintLine ();
Cout <"midpoint:" <endl;
L. PrintPoint ();
Return 0;
}

 


 

Experience: This was made by myself, which is quite different from the teacher's;

[Cpp]
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Qiu xuewei
* Completion date: January 1, May 11, 2013
* Version: v1.0
* Input Description: None
* Problem description: defines the vertex class and uses the vertex class as the base class to derive a straight line class. The vertex information inherited from the base class indicates the midpoint of the straight line.
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Point
{
Public:
Point (): x (0), y (0 ){};
Point (double x1, double y1)
{
X = x1;
Y = y1;
}
Double getx () {return x ;}
Double gety () {return y ;}
Void display ();
Private:
Double x, y;
};
Void Point: display ()
{
Cout <"Point :(" <x <"," <y <")" <endl;
}
Class Line: public Point
{
Public:
Line (Point p1, Point p2 );
Double Lengh ();
Void PrintLine ();
Void PrintPoint ();
Private:
Class Point pts, pte;
};
Line: Line (Point p1, Point p2): Point (p1.getx () + p2.getx ()/2, (p1.gety () + p2.gety ()/2)
{
Pts = p1;
Pte = p2;
 
}
Double Line: Lengh ()
{
Double x0 = pts. getx ()-pte. getx ();
Double y0 = pts. gety ()-pte. gety ();
Return sqrt (x0 * x0 + y0 * y0 );
 
}
Void Line: PrintLine ()
{
Cout <"endpoint:" <endl;
Pts. display ();
Pte. display ();
Cout <"Length:" <Lengh () <endl;
}
Void Line: PrintPoint ()
{
Cout <"(" <(pts. getx () + pte. getx ()/2 <"," <(pts. gety () + pte. gety ()/2 <")" <endl;
}
Int main ()
{
Point pt (-), pe );
Line l (pt, pe );
L. PrintLine ();
Cout <"\ n The middle point of Line :";
L. PrintPoint (); // outputs the point information of the line l.
Return 0;
}

/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Qiu xuewei
* Completion date: January 1, May 11, 2013
* Version: v1.0
* Input Description: None
* Problem description: defines the vertex class and uses the vertex class as the base class to derive a straight line class. The vertex information inherited from the base class indicates the midpoint of the straight line.
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
# Include <cmath>
Using namespace std;
Class Point
{
Public:
Point (): x (0), y (0 ){};
Point (double x1, double y1)
{
X = x1;
Y = y1;
}
Double getx () {return x ;}
Double gety () {return y ;}
Void display ();
Private:
Double x, y;
};
Void Point: display ()
{
Cout <"Point :(" <x <"," <y <")" <endl;
}
Class Line: public Point
{
Public:
Line (Point p1, Point p2 );
Double Lengh ();
Void PrintLine ();
Void PrintPoint ();
Private:
Class Point pts, pte;
};
Line: Line (Point p1, Point p2): Point (p1.getx () + p2.getx ()/2, (p1.gety () + p2.gety ()/2)
{
Pts = p1;
Pte = p2;

}
Double Line: Lengh ()
{
Double x0 = pts. getx ()-pte. getx ();
Double y0 = pts. gety ()-pte. gety ();
Return sqrt (x0 * x0 + y0 * y0 );

}
Void Line: PrintLine ()
{
Cout <"endpoint:" <endl;
Pts. display ();
Pte. display ();
Cout <"Length:" <Lengh () <endl;
}
Void Line: PrintPoint ()
{
Cout <"(" <(pts. getx () + pte. getx ()/2 <"," <(pts. gety () + pte. gety ()/2 <")" <endl;
}
Int main ()
{
Point pt (-), pe );
Line l (pt, pe );
L. PrintLine ();
Cout <"\ n The middle point of Line :";
L. PrintPoint (); // outputs the point information of the line l.
Return 0;
}

 

 

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.