C# 形状层次结构编程语言

发布于 2024-10-25 05:17:31 字数 261 浏览 3 评论 0原文

创建一个应用程序,该应用程序使用对层次结构中每个具体类的对象的 Shape 引用数组。应用程序应打印文本描述 每个数组元素引用的对象的。另外,在处理数组中所有形状的循环中,确定每个形状是 TwoDimensionalShape 还是 ThreeDimensionalShape。如果形状是 TwoDimensionalShape,则显示其面积。如果形状是 ThreeDimensionalShape,则显示其面积和体积。

我是这里真正的新手,我真的迷失了这样做。请有人帮我解决这个问题。谢谢。

Create an application that uses an array of Shape references to objects of each concrete class in the hierarchy. The application should print a text description
of the object to which each array element refers. Also, in the loop that processes all the shapes in the array, determine whether each shape is a TwoDimensionalShape or a ThreeDimensionalShape. If a shape is a TwoDimensionalShape, display its area. If a shape is a ThreeDimensionalShape, display its area and volume.

I am a real newbie here, I'm really lost doing this. Please, could someone help me with this. Thank You.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-11-01 05:17:31

我也一直被这个问题困扰,但在 Youtube 上找到这个抽象类教程后,一切都变得清晰起来: http://www.youtube.com/watch?v=hwKOMfsYyxo

教科书中的问题对于需要抽象什么内容不是很清楚,但是当你查看上下文时,Shape、TwoDimensionalShape 和ThreeDimensionalShape 必须全部是抽象的,并且其中包含 Area 和 Volume 的抽象方法。尽管我发现的技巧是,一旦声明了抽象方法,就不必在派生抽象类中声明该方法,直到具体类实现它们为止。

I've been stuck on this one as well, but after finding this abstract class tutorial on Youtube, it all became clear: http://www.youtube.com/watch?v=hwKOMfsYyxo

The question in the textbook wasn't very clear on what needs to abstract but when you look at the context, Shape, TwoDimensionalShape, and ThreeDimensionalShape have to all be abstract and contain abstract methods for Area and Volume within them. Though the trick that I discovered was that once you declare an abstract method, you don't have to declare that method in derived abstract classes until a concrete class implements them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文