、设计一个控制台应用程序,定义一个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. 2-开发共享版APP(接入指南)-设备接入说明:快速接入

    https://www.cnblogs.com/yangfengwu/p/11249674.html 该APP安装包下载链接: http://www.mnif.cn/appapk/IotDevelop ...

  2. 复旦高等代数 I(16级)每周一题

    每周一题的说明 一.本学期高代I的每周一题面向16级的同学,将定期更新(一般每周的周末公布下一周的题目); 二.欢迎16级的同学通过微信或书面方式提供解答图片或纸质文件给我,优秀的解答可以分享给大家: ...

  3. 虚拟机,安装tools时出现“安装程序无法继续解决

    报错:虚拟机安装了win10,安装tools时出现“安装程序无法继续.Microsoft Runtime DLL安装程序未能安装” 解决步骤: 双击安装程序,在它报以上错时不要点确定 这个时候按下窗口 ...

  4. Hadoop(二)—— HDFS

    HDFS(Hadoop Distributed File System)Hadoop分布式文件系统. 一.HDFS产生的背景 随着数据量越来越大,如果大到一台主机的磁盘都存放不下,该如何解决这个问题. ...

  5. 第09组 Beta冲刺(1/4)

    队名:软工9组 组长博客:https://www.cnblogs.com/cmlei/ 作业博客:https://edu.cnblogs.com/campus/fzu/SoftwareEngineer ...

  6. from bs4 import BeautifulSoup 引入需要安装的文件和步骤

    调用beautifulsoup库时,运行后提示错误: ImportError: No module named bs4 , 意思就是没有找到bs4模块,所以解决方法就是将bs4安装上,具体步骤如下: ...

  7. numpy模块常用函数解析

    https://blog.csdn.net/lm_is_dc/article/details/81098805 numpy模块以下命令都是在浏览器中输入. cmd命令窗口输入:jupyter note ...

  8. SQLServer charindex函数, 查 某个字符 或 某个字符串 在 另一个字符串中的位置

    一:charindex()语法 CHARINDEX ( expression1 , expression2 [ , start_location ] ) 解析: expression1 必需 ---要 ...

  9. gmake: Nothing to be done for `all'.

    安装gc_buffercache的时候报错: [root@~ pg_buffercache]# gmake gmake: Nothing to be done for `all'. 解决方法: > ...

  10. python笔记之按文件名搜索指定路径下的文件

    1.搜索文件名中以指定的字符串开头(如搜索dll,结果中含有dll a,dll abc等) 我的目录下有dll a.txt和dll.txt文件 其中a文件夹下还有这两个文件 我希望通过python选择 ...