OJ Problema 3438 c # calcular el área de un rectángulo (problema de herencia)

Descripción del Título

De acuerdo con el código dado, complete el código que falta, ingrese dos números como la longitud y el ancho del rectángulo para obtener el área del rectángulo. 

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;    } / ***** *********** /  Escriba el código aquí y solo envíe el código aquí  / **************** /    class RectangleTester    {       static void Main (string [ ] args)       {          Rectangle Rect = new Rectangle ();
















   





        int ancho = int.Parse (Console.ReadLine ());
          int altura = int.Parse (Console.ReadLine ());
         Rect.setWidth (ancho);
         Rect.setHeight (altura);
         Console.WriteLine ("总 面积 : {0}", Rect.getArea ());
         Console.ReadKey ();
      }
   }
}
 

ingresar

3 5

Producción

15

Entrada de muestra

 

5 
7

Salida de muestra

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;
        }
    }
} 

 

Supongo que te gusta

Origin blog.csdn.net/wangws_sb/article/details/105113624
Recomendado
Clasificación