加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CRect.cs 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
谭亚飞 提交于 2021-11-06 19:36 . 实验2-4写一个矩形类CRect
//using System;
//using System.Collections.Generic;
//using System.Text;
//namespace c_sharp_experiment02
//{
// class CRect
// {
// private int top, bottom, left, right;
// public static int total_rects = 0;
// public static long total_rect_area = 0;
// public CRect(){
// left = top = right = bottom = 0;
// total_rects++;
// total_rect_area += getHeight() * getWidth();
// Console.WriteLine("CRect() Constructing rectangle numer{0}", total_rects);
// Console.WriteLine("Total rectangle areas is:{0}", total_rect_area);
// }
// public CRect(int x1,int y1,int x2,int y2) {
// left = x1;top = y1;
// right = x2;bottom = y2;
// total_rects++;
// total_rect_area+= getHeight() * getWidth();
// Console.WriteLine("CRect(int,int,int,int) Constructing rectangle numer{0}", total_rects);
// Console.WriteLine("Total rectangle areas is:{0}", total_rect_area);
// }
// public CRect(CRect r) {
// left = r.left;
// right = r.right;
// top = r.top;
// bottom = r.bottom;
// total_rects++;
// total_rect_area += getHeight() * getWidth();
// Console.WriteLine("CRect(CRect&) Constructing rectangle numer{0}", total_rects);
// Console.WriteLine("Total rectangle areas is:{0}", total_rect_area);
// }
// public int getHeight() {
// return top > bottom ? top - bottom : bottom - top;
// }
// public int getWidth() {
// return right > left ? right - left : left - right;
// }
// public static int getTotalRects() {
// return total_rects;
// }
// public static long getTotalTectArea() {
// return total_rect_area;
// }
// }
// class Test2_4 {
// public static void Main(string[] args) {
// CRect rect1 = new CRect(1, 3, 6, 4), rect2 = new CRect(rect1);
// Console.WriteLine("Rectangle 2:Height:{0},Width:{1}",rect2.getHeight(),rect2.getWidth());
// {
// CRect rect3 = new CRect();
// Console.WriteLine("Rectangle3:Height:{0},Width:{1}", rect3.getHeight(), rect3.getWidth());
// }
// Console.Write("total_rects={0},", CRect.total_rects);
// Console.WriteLine("total_rect_area={0}", CRect.total_rect_area);
// }
// }
//}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化