Initial commit

This commit is contained in:
Mark J Price 2022-02-27 19:08:52 +00:00
parent bc96ccb183
commit 18f89e91d4
62 changed files with 1661 additions and 2 deletions

View file

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,29 @@
namespace Packt.Shared;
public class Circle : Square
{
public Circle() { }
public Circle(double radius) : base(width: radius * 2) { }
public double Radius
{
get
{
return height / 2;
}
set
{
Height = value * 2;
}
}
public override double Area
{
get
{
double radius = height / 2;
return Math.PI * radius * radius;
}
}
}

View file

@ -0,0 +1,10 @@
using Packt.Shared;
Rectangle r = new(height: 3, width: 4.5);
WriteLine($"Rectangle H: {r.Height}, W: {r.Width}, Area: {r.Area}");
Square s = new(5);
WriteLine($"Square H: {s.Height}, W: {s.Width}, Area: {s.Area}");
Circle c = new(radius: 2.5);
WriteLine($"Circle H: {c.Height}, W: {c.Width}, Area: {c.Area}");

View file

@ -0,0 +1,20 @@
namespace Packt.Shared;
public class Rectangle : Shape
{
public Rectangle() { }
public Rectangle(double height, double width)
{
this.height = height;
this.width = width;
}
public override double Area
{
get
{
return height * width;
}
}
}

View file

@ -0,0 +1,37 @@
namespace Packt.Shared;
public abstract class Shape
{
// fields
protected double height;
protected double width;
// properties
public virtual double Height
{
get
{
return height;
}
set
{
height = value;
}
}
public virtual double Width
{
get
{
return width;
}
set
{
width = value;
}
}
// Area must be implemented by derived classes
// as a read-only property
public abstract double Area { get; }
}

View file

@ -0,0 +1,26 @@
namespace Packt.Shared;
public class Square : Rectangle
{
public Square() { }
public Square(double width) : base(height: width, width: width) { }
public override double Height
{
set
{
height = value;
width = value;
}
}
public override double Width
{
set
{
height = value;
width = value;
}
}
}