、设计一个控制台应用程序,定义一个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. vigil deb 包制作

    前边有写过简单rpm 包的制作,现在制作一个简单的deb 包. deb 包的制作是通过源码编译+ fpm 环境准备 rust curl https://sh.rustup.rs -sSf | sh 配 ...

  2. mysql5.7 之 sql_mode=only_full_group_by问题

    在使用查询时,使用到了group by 分组查询,报如下错误: ERROR (): In aggregated query without GROUP BY, expression # of SELE ...

  3. OpenFOAM——具有压差且平行平板间具有相对运动流动

    本算例翻译整理自:http://the-foam-house5.webnode.es/products/chapter-1-plane-parallel-plates-case/ 这个算例中两平板间具 ...

  4. Linux 文件系统磁盘空间与连接文件

    磁盘与目录的容量 我们知道磁盘的整体数据hi在superblock块中,但是各文件的容量则在inode中记载. df:列出文件系统的整体磁盘使用量 由于df主要读取的数据几乎都是针对整个文件系统,因此 ...

  5. spring boot +dubbo+zookeeper

    dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. 结合本公司的开发也是用的dubbo这款优秀的框架,加上 最近工作重心的.所以对于dubbo的 ...

  6. [代码质量] Git统计本次提交新增代码行数,建议每个评审commit新增行数小于400行

    git log HEAD~1..HEAD --author="$(git config --get user.name)" --pretty=tformat: --numstat ...

  7. 如何通过配置tomcat或是web.xml让ie直接下载文件

    web.xml(tomcat\conf\web.xml)中配置了 <mime-mapping>   <extension>txt</extension>   < ...

  8. Wise Force Deleter 强制删除文件工具

    https://www.xitmi.com/3321.html   Wise Force Deleter v1.49 中文绿色版 强制删除文件工具

  9. plsql 的三种循环

    set serveroutput on declare pnum ; begin loop dbms_output.put_line(pnum); pnum :; end loop; end; / s ...

  10. SAP views

    文章转自 http://blog.csdn.net/HikenWong/article/details/8263969 1. sap的视图的类型sap的视图的类型有五种: Database views ...