、设计一个控制台应用程序,定义一个MyPoint类,该类能表示二维平面空间的点,完成点类及运算符重载等相关功能。具体要求如下:
()MyPoint类中定义2个私有字段x和y及相应的构造函数。
()MyPoint类中重载ToString方法输出坐标x和y的值。
()MyPoint类中重载一元运算符“-”。
()MyPoint类中重载二元运算符“+”和“-”。
()MyPoint类中重载二元运算符“>”和“<”。
()MyPoint类中重载二元运算符“==”和“!=”。
()在Main方法中测试上述运算符。
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Myproject
{
class Program
{
static void Main(string[] args)
{
Mypoint a = new Mypoint(, );
Mypoint b = new Mypoint(, );
Mypoint c = new Mypoint(, );
Console.WriteLine( "Check: a+b " + (a + b) );
Console.WriteLine( "Check: a-b " + (a - b) ); Console.WriteLine( "Check: < , > , != , == " );
if (a < c) Console.WriteLine("a < c ");
if( c > a) Console.WriteLine("c > a" ); if( a + b != a)
{
Console.WriteLine("a + b != a");
} if ( a + b == c)
{
Console.WriteLine("a + b == c");
}
}
}
public class Mypoint
{
int x, y; public Mypoint(int x, int y)
{
this.x = x;
this.y = y;
}
public Mypoint() : this(, ) { }
public int X { get { return x; } set { x = value; } }
public int Y { get { return y; } set { y = value; } }
public override string ToString()
{
return string.Format("({0},{1})", x, y);
} public static Mypoint operator - (Mypoint u)
{
Mypoint p = new Mypoint();
p.X = -u.X;
p.Y = -u.Y;
return p;
} public static Mypoint operator + (Mypoint u, Mypoint v)
{
Mypoint p = new Mypoint();
p.X = u.X + v.X;
p.Y = u.Y + v.Y;
return p;
} public static Mypoint operator -(Mypoint u, Mypoint v)
{
Mypoint p = new Mypoint();
p.X = u.X - v.X;
p.Y = u.Y - v.Y;
return p;
} public static bool operator >(Mypoint u, Mypoint v)
{
bool status = false ;
if( u.X >= v.X && u.Y >= v.Y)
{
status = true;
}
return status;
} public static bool operator <(Mypoint u, Mypoint v)
{
bool status = false;
if (u.X <= v.X && u.Y <= v.Y)
{
status = true;
}
return status;
} public static bool operator ==(Mypoint u, Mypoint v)
{
bool status = false;
if (u.X == v.X && u.Y == v.Y)
{
status = true;
}
return status;
} public static bool operator !=(Mypoint u, Mypoint v)
{
bool status = false;
if (u.X != v.X || u.Y != v.Y)
{
status = true;
}
return status;
} } }

、设计一个控制台应用程序,定义一个Box类,该类表示一个立方体,完成该类运算符重载等相关功能。具体要求如下:
()Box类中定义3个私有字段(代表长、宽、高)及相应的构造函数
()MyPoint类中重载ToString方法输出长宽高的值。
()Box类中重载一元运算符“-”。
()Box类中重载二元运算符“+”和“-”。
()Box类中重载二元运算符“>”和“<”。
()Box类中重载二元运算符“==”和“!=”。
()在Main方法中测试上述运算符。
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Myproject
{
class Program
{
static void Main(string[] args)
{
Box b1 = new Box(, , );
Box b2 = new Box(, , );
Box b3 = new Box(, , ); Console.WriteLine("Check: b1 + b2 " + (b1 + b2));
Console.WriteLine("Check: -b1 " + b1);
Console.WriteLine("Check: > , < , == , != ");
if (b2 > b1) Console.WriteLine("b2 > b1");
if (b1 < b2) Console.WriteLine("b1 < b2"); if (b1 + b2 == b3) Console.WriteLine("b1 + b2 == b3 ");
if (b1 + b2 != b1) Console.WriteLine("b1 + b2 != b1 ");
}
}
class Box
{
private int length, width, height; public Box(int length, int width, int height)
{
this.length = length;
this.width = width;
this.height = height;
} public Box() : this(, , ) { }
public int Length { get { return length; } set { length = value; } }
public int Width { get { return width; } set { width = value; } }
public int Height { get { return height; } set { height = value; } } public override string ToString()
{
return string.Format("( {0} , {1} , {2} )",length,width,height);
}
public static Box operator +(Box rhs)
{
Box res = new Box();
res.height = - rhs.height;
res.length = - rhs.length;
res.width = - rhs.width;
return res;
} public static Box operator + (Box lhs , Box rhs)
{
Box res = new Box();
res.height = lhs.height + rhs.height;
res.length = lhs.length + rhs.length;
res.width = lhs.width + rhs.width;
return res;
} public static Box operator - (Box lhs, Box rhs)
{
Box res = new Box();
res.height = lhs.height - rhs.height;
res.length = lhs.length - rhs.length;
res.width = lhs.width - rhs.width;
return res;
} public static bool operator >(Box lhs, Box rhs)
{
bool status = false;
if (lhs.length > rhs.length &&
lhs.width > rhs.width &&
lhs.height > rhs.height)
{
status = true;
}
return status;
} public static bool operator <(Box lhs, Box rhs)
{
bool status = false;
if (lhs.length < rhs.length &&
lhs.width < rhs.width &&
lhs.height < rhs.height)
{
status = true;
}
return status;
} public static bool operator == (Box lhs, Box rhs)
{
bool status = false;
if (lhs.length == rhs.length &&
lhs.width == rhs.width &&
lhs.height == rhs.height)
{
status = true;
}
return status;
} public static bool operator !=(Box lhs, Box rhs)
{
bool status = false;
if (lhs.length != rhs.length ||
lhs.width != rhs.width ||
lhs.height != rhs.height)
{
status = true;
}
return status;
}
}
}

【C#】上机实验五的更多相关文章

  1. SDN第五次上机实验

    1.浏览RYU官网学习RYU控制器的安装和RYU开发入门教程,提交你对于教程代码的理解. 1.通过源码安装RYU控制器 sudo apt-get install python3-pip git clo ...

  2. 20145210 20145226 《信息安全系统设计基础》实验五 简单嵌入式WEB服务器实验

    20145210 20145226 <信息安全系统设计基础>实验五 简单嵌入式WEB服务器实验 结对伙伴:20145226 夏艺华 实验报告封面 实验目的与要求 · 掌握在ARM开发板实现 ...

  3. 实验五 CC2530平台上ADC组件的TinyOS编程

    实验五 CC2530平台上ADC组件的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生初步掌握传感器的ADC组件应用方法 学生通过本实验能够初步的了解和掌握CC ...

  4. oracle上机实验内容

    这是oracle实验的部分代码,我花了一中午做的. 第一次上机内容 实验目的:熟悉ORACLE11G的环境 实验内容: 第二次上机内容 实验目标:掌握oracle体系结构,掌握sqlplus的运行环境 ...

  5. SDN上机第五次作业

    2019 SDN上机第五次作业 1.浏览RYU官网学习RYU控制器的安装和RYU开发入门教程,提交你对于教程代码的理解,包括但不限于: 1.1描述官方教程实现了一个什么样的交换机功能? 答:官方教程实 ...

  6. 20145215&20145307《信息安全系统设计基础》实验五 网络通信

    小组成员:20145215卢肖明.20145307陈俊达 实验报告链接:信息安全系统设计基础--实验五实验报告

  7. 20145216 20145330 《信息安全系统设计基础》 实验五 简单嵌入式WEB 服务器实验

    20145216 20145330 <信息安全系统设计基础> 实验五 简单嵌入式WEB 服务器实验 实验报告封面 实验步骤 1.阅读理解源码 进入/arm2410cl/exp/basic/ ...

  8. 20145208《信息安全系统设计基础》实验五 简单嵌入式WEB 服务器实验

    20145208<信息安全系统设计基础>实验五 简单嵌入式WEB 服务器实验 20145208<信息安全系统设计基础>实验五 简单嵌入式WEB 服务器实验

  9. 20145315&20145307《信息安全系统设计基础》实验五

    20145315&20145307<信息安全系统设计基础>实验五 北京电子科技学院(BESTI) 实 验 报 告 课程:信息安全系统设计基础 班级:1453 1452 姓名:陈俊达 ...

随机推荐

  1. amundsen 来自lyft 的开源数据发现平台

    amundsen 是来自lyft 开源的元数据管理.数据发现平台,功能点很全,有一个比较全的前端.后端以及 数据处理框架 参考架构图 说明 从官方介绍以及github代码仓库可以看出还是比较全的整体解 ...

  2. IIS 站点配置文件

    IIS 站点配置文件  C:/Windows/System32/inetsrv/config/applicationHost.config 配置文件示例: <system.application ...

  3. codevs 2780 ZZWYYQWZHZ

    2780 ZZWYYQWZHZ  时间限制: 1 s  空间限制: 32000 KB  题目等级: 青铜 Bronze       题目描述 Description 可爱的小管在玩吹泡泡.忽然,他想到 ...

  4. pycharm2018.2.1破解、汉化

    ##我只是一个搬运工  -_-   (一)先破解,破解教程直接给个网址吧,感谢各位大神的无私奉献:https://blog.csdn.net/u014044812/article/details/78 ...

  5. idea 导入 eclipse java ee 项目,并使用 tomcat 7 部署运行

    1.导入java ee项目.直接open 2.导入jar依赖 3.修改编译的目录 4.修改tomcat目录 5.tomcat添加目录 请注意classes单词 D:\project\xxxxxx\We ...

  6. MSSQL 数据库复制脚本

    --新表存在复制数据 insert into 新表 (字段) select 字段 from 旧表 -- 新表不存在复制数据 select * into 新表 from 旧表

  7. Java操作Excel中HSSFCell.CELL_TYPE_STRING、BOOLEAN、NUMERIC无定义解决方法

    错误原因:jar包版本更新,官方改动: 解决方法: 导入CellType包import org.apache.poi.ss.usermodel.CellType使用CellType.STRING代替H ...

  8. Node Addon

    Node Addon as bridge between javascript and C++ #include <node.h> namespace HelloWorldDemo { u ...

  9. 解决idea创建Maven项目速度慢

    idea在创建maven项目的时候会去网上自动下载需要的插件,这样就会导致项目创建后一直处于下载插件的状态中,影响开发效率 此时我们可以在创建maven骨架的时候,加入键值对来让maven调用本地的骨 ...

  10. 再谈CAP

    CAP定理设计者Eric Brewer作为Google基础设施副总裁在时隔二十年后重谈CAP定律. Eric Brewer目前正在推动Kubernetes和容器建设,在这篇采访中:Google sys ...