打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
矩形
using System;
class Rectangle
{
 private float length=1.0f;
 private float width=1.0f;
 public float SetLength(float length)
 {
  this.length=length;
  if((length<0.0f)||(length>2.0f))
  {
   Console.WriteLine ("长的取值范围应在1.0-2.0之内,请重新设值。");
   return 0.0f;
  }
  return width;
 }
 public float SetWidth(float width)
 {
        this.width=width;
  if((width<0.0f)||(width>2.0f))
  {
   Console.WriteLine ("宽的取值范围应在1.0-2.0之内,请重新设值。"); 
   return 0.0f;
  }
  return width;
 }
 public float GetLength(float length)
 {
  return length;
 }
 public float GetWidth(float width)
 {
  return width; 
 }
 public float perimeter()
 {
  return length*2+width*2;
 }
 public float area()
 {
    return length*width;
 }
}
class Rectangle_Test
{
 public static void Main()
 {
  Rectangle r1=new Rectangle ();
  r1.SetLength (1.8f);
  r1.SetWidth (1.2f);
     Console.WriteLine (r1.perimeter ());
  Console.WriteLine (r1.area ());
 }
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# 反射(Reflection) | 菜鸟教程
☀️ 学会编程入门必备 C# 最基础知识介绍(五)——方法、封装、继承、多态
C# interface学习经验浅谈 - 51CTO.COM
C# 基本语法
C# 7
最简单的C#快速入门教程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服