[Csharp]
/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: defines a CPoint class that describes coordinate points, derives a line class Cline, derives a rectangle class CRect, and calculates the distance between two points and the area and perimeter of the rectangle.
* Author: Lei hengxin
* Completion date: January 1, September 22, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace Four _ week
{
Class Program
{
Static void Main (string [] args)
{
CPoint c1 = new CPoint ();
CPoint c2 = new CPoint ();
CPoint c3 = new CPoint ();
C1.setpoint (1, 1 );
C2.setpoint (4, 5 );
C3.setpoint (4, 1 );
Cline m = new Cline ();
Console. WriteLine ("the distance between two points is: {0}", m. distence (c1, c2 ));
Cline m1 = new Cline ();
M. set_length (c3, c2 );
M1.set _ length (c1, c3 );
CRect CR = new CRect ();
Console. WriteLine ("the circumference of the rectangle is {0}", CR. perimeter (m, m1 ));
Console. WriteLine ("rectangular area: {0}", CR. area (m, m1 ));
Console. ReadKey (true );
}
}
Class CPoint
{
Private int x;
Private int y;
Public CPoint (int x1, int y2)
{
X = x1;
Y = y2;
}
Public CPoint ()
{
X = 60;
Y = 75;
}
Public void display ()
{
Console. WriteLine ("x = {0} y = {1}", x, y );
}
Public void setpoint (int x1, int y1)
{
X = x1;
Y = y1;
}
Public int get_x ()
{
Return x;
}
Public int get_y ()
{
Return y;
}
}
Class Cline: CPoint
{
Public double;
Public Cline (int a1)
{
A = a1;
}
Public Cline ()
{
A = 0;
}
Public double distence (CPoint c1, CPoint c2)
{
Return a = Math. sqrt (Math. pow (c1.get _ x ()-c2.get _ x (), 2) + Math. pow (c1.get _ y ()-c2.get _ y (), 2 )));
}
Public double get_length ()
{
Return;
}
Public void set_length (CPoint c1, CPoint c2)
{
A = distence (c1, c2 );
}
}
Class CRect: Cline
{
Public double m;
Public double n;
Public CRect (double a1, double b1)
{
M = a1;
N = b1;
}
Public CRect ()
{
M = 0;
N = 0;
}
Public double perimeter (Cline c1, Cline c2)
{
Return m = 2 * (c1.get _ length () + c2.get _ length ());
}
Public double area (Cline c1, Cline c2)
{
Return n = c1.get _ length () * c2.get _ length ();
}
}
}
Running result:
Experience Accumulation
1. The above program is still a little incomplete, mainly the block of the constructor of the derived class, because it involves the Base, so that we can continue to improve it after learning the difference between Base and This.
2. The feeling is similar to that of C ++.