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