复数

来源:互联网 发布:电魂网络有哪些游戏 编辑:程序博客网 时间:2024/05/17 03:26
//时间using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Rectangle{    class Program    {        static void Main(string[] args)        {            CRectangle rect1 = new CRectangle();            try            {                rect1.Width = Convert.ToInt32(Console.ReadLine());                rect1.Height = Convert.ToInt32(Console.ReadLine());            }            catch (FormatException e)            {                Console.WriteLine(e.Message);                Console.ReadKey();                return;            }            catch (Exception a)            {                Console.WriteLine(a.Message);                Console.ReadKey();                return;            }            Console.WriteLine("面积{0}", rect1.Area());            Console.WriteLine("周长{0}", rect1.Perimeter());            Console.ReadKey();        }    }    class CRectangle    {        private int height;        private int width;        public int Width        {            set            {                if (value > 0)                    width = value;                else throw new Exception("宽度应该大于零");            }            get            {                return width;            }        }        public int Height        {            set            {                if (value > 0) height = value;                else throw new Exception("高度应该大于零");            }            get            {                return height;            }        }        public int Area()        {            return width * height;        }        public int Perimeter()        {            return 2 * (width + height);        }    }}

总结:不怎么会复数啊

0 0