c#計算長方形的面積(繼承問題)
題目描述
根據給出的代碼,補全缺失的代碼,輸入兩個數字為長方形的長和寬,從而得出長方形的面積。
using System;
namespace InheritanceApplication
{
? ?class Shape?
? ?{
? ? ? public void setWidth(int w)
? ? ? {
? ? ? ? ?width = w;
? ? ? }
? ? ? public void setHeight(int h)
? ? ? {
? ? ? ? ?height = h;
? ? ? }
? ? ? protected int width;
? ? ? protected int height;
? ?}
/****************/
編寫此處代碼,并只提交此處代碼
/****************/
? ?
? ?class RectangleTester
? ?{
? ? ? static void Main(string[] args)
? ? ? {
? ? ? ? ?Rectangle Rect = new Rectangle();
????????int width = int.Parse(Console.ReadLine());
????????? int height =int.Parse(Console.ReadLine());
? ? ? ? ?Rect.setWidth(width);
? ? ? ? ?Rect.setHeight(height);
? ? ? ? ?Console.WriteLine("總面積: {0}",? Rect.getArea());
? ? ? ? ?Console.ReadKey();
? ? ? }
? ?}
}
?
樣例輸入
5 7
樣例輸出
35
class Rectangle:Shape{public int getArea(){return width * height;}}
?