0% found this document useful (0 votes)
39 views

Class Abstract

The document defines classes for points, circles, rectangles, and shapes. The POINT class represents x,y coordinates. The CIRCLE class inherits from Shape and represents a circle with a center point and radius. It can calculate circumference and area using its radius. The RECTANGLE class inherits from Shape and represents a rectangle using two POINTs for its corners. It can calculate circumference using the distances between its points and area using their x,y differences. The Program class demonstrates creating circle and rectangle objects to output their areas and circumferences.

Uploaded by

NHULEE
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Class Abstract

The document defines classes for points, circles, rectangles, and shapes. The POINT class represents x,y coordinates. The CIRCLE class inherits from Shape and represents a circle with a center point and radius. It can calculate circumference and area using its radius. The RECTANGLE class inherits from Shape and represents a rectangle using two POINTs for its corners. It can calculate circumference using the distances between its points and area using their x,y differences. The Program class demonstrates creating circle and rectangle objects to output their areas and circumferences.

Uploaded by

NHULEE
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

class POINT { int x, y; public POINT() { x = 0; y = 0; } public POINT(int xx, int yy) { x = xx; y = yy; } public double khoangcach(POINT

p) { return Math.Sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)); } public int get_x() { return x; } public int get_y() { return y; } }

abstract class Shape { public abstract double Circumference(); public abstract double Area(); }

class CIRCLE: Shape { POINT p; double r; public CIRCLE() { p = new POINT(); r = 0; } public CIRCLE(POINT p1, double rr) {

p = p1; r = rr; } public bool inside(POINT p1) { if (p.khoangcach(p1) < r) return true; return false; } public override double Circumference() { return 2 * 3.1416 * r; } public override double Area() { return 3.1416 * r * r; } }

class RECTANGLE: Shape { POINT p1, p2; public RECTANGLE(POINT a, POINT b) { p1 = a; p2 = b; } public override double Circumference() { return 2 * (Math.Abs(p1.get_x() - p2.get_x()) + Math.Abs(p1.get_y() - p2.get_y())); } public override double Area() { return Math.Abs(p1.get_x() - p2.get_x()) * Math.Abs(p1.get_y() p2.get_y()); } }

class Program { static void Main(string[] args) { POINT p1 = new POINT(3, 3); POINT p2 = new POINT(5, 6); Shape a, b, c; a = new CIRCLE(p1,4);

b = new RECTANGLE(p1, p2); Console.WriteLine("Dien tich cua a la: {0}", a.Area()); Console.WriteLine("Dien tich cua b la: {0}", b.Area()); Console.WriteLine("Chu vi cua a la: {0}", a.Circumference()); Console.WriteLine("Chu vi cua b la: {0}", b.Circumference()); Console.ReadKey(); } }

You might also like