OJ 문제 3438 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 높이 = int.Parse (Console.ReadLine ());
         Rect.setWidth (너비);
         Rect.setHeight (height);
         Console.WriteLine ( "면적 : {0}", Rect.getArea ());
         Console.ReadKey ();
      }
   }
}
 

시작하다

3 5

산출

15

샘플 입력

 

5 
7

샘플 출력

35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
    class Program
    {
        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();
        }
    }
    class Shape
    {
        public void setWidth(int w)
        {
            width = w;
        }
        public void setHeight(int h)
        {
            height = h;
        }
        protected int width;
        protected int height;
    }
    class Rectangle:Shape
    {
        public int getArea()
        {
            return width * height;
        }
    }
} 

 

추천

출처blog.csdn.net/wangws_sb/article/details/105113624