-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (60 loc) · 1.62 KB
/
Copy pathProgram.cs
File metadata and controls
61 lines (60 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
namespace Assignment6
{
class Program // Program class
{
abstract class Shape
{
public double width;
public double height;
public virtual double CalculateSurface() {
return 0;
}
}
// Rectangle class
class Rectangle : Shape
{
public override double CalculateSurface()
{
return height * width;
}
}
class Triangle : Shape
{
// Triangle class
public override double CalculateSurface()
{
return height * width / 2;
}
}
class Circle : Shape
{
// Circle class
public Circle(double radius)
{
this.height = radius;
this.width = radius;
}
// Circle class
public override double CalculateSurface()
{
return Math.PI * height * width;
}
}
static void Main(string[] args)
{
Shape[] shapes = new Shape[3];
shapes[0] = new Rectangle();
shapes[0].height = 5;
shapes[0].width = 4;
shapes[1] = new Triangle();
shapes[1].height = 5;
shapes[1].width = 4;
shapes[2] = new Circle(5);
for (int i = 0; i < 3; i++) {
Console.WriteLine("Surface: {0}", shapes[i].CalculateSurface());
}
Console.ReadLine();// Reads the console
}
}// End of Program class
}// End of namespace Assignment6 @DASLAW