OJ Problem 3485 接口实例（C#,IShape）

题目描述

using System;
namespace Myinterface
{
public interface IShape
{
double Perimeter();
double Area();
}
class Circle : IShape
{
public double Radius { get; set; }
public Circle(double r)
{
}
public double Area()
{
}
public double Perimeter()
{
return 2 * Math.PI * Radius;
}
}
class Rectangle : IShape
{
/////////////////////////////////////////////////////////////////
//请填写代码，实现输出矩形的面积和周长
/////////////////////////////////////////////////////////////////
}
class Program
{
static void Main(string[] args)
{
double w, h;
Rectangle r = new Rectangle(w, h);
Console.WriteLine("area={0},Perimeter={1}",r.Area(), r.Perimeter());
}
}

10
3

输出

area=30,Perimeter=26

10
3

样例输出

area=30,Perimeter=26

提示

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
public interface IShape
{
double Perimeter();
double Area();
}
class Circle : IShape
{
public double Radius { get; set; }
public Circle(double r)
{
}
public double Area()
{
}
public double Perimeter()
{
return 2 * Math.PI * Radius;
}
}
class Rectangle : IShape
{
public double Height { get; set; }
public double Length { get; set; }
public Rectangle(double l,double h)
{
Height = h;
Length = l;
}
public double Area()
{
if (Height <= 0 || Length <= 0)
{
return 0;
}
return Height * Length;
}
public double Perimeter()
{
if (Height <= 0 || Length <= 0)
{
return 0;
}
return (Height + Length) * 2;
}

}
class Program
{
static void Main(string[] args)
{
double w, h;
Rectangle r = new Rectangle(w, h);
Console.WriteLine("area={0},Perimeter={1}", r.Area(), r.Perimeter());
}
}
}

©️2019 CSDN 皮肤主题: 技术工厂 设计师: CSDN官方博客