OJ問題3440c#補足印刷(ポリモーフィズム問題)

タイトル説明

与えられたコードに従って、不足しているコードを入力します。print関数が整数の場合、整数の3乗(浮動小数点数)が出力され、2乗が出力され、文字列の場合は、直接出力されます。 
システムの使用;
名前空間PolymorphismApplication
{    クラスPrintdata    {       / **************************************** ** /           ここにコードを追加し、ここにコードのみを送信します    / ******************************** *** ******* /       static void Main(string [] args)       {          Printdata p = new Printdata();          p.print(2);          p.print(1.23);          p.print( "Hello world");          Console.ReadKey();       }    }








         

        

      




入る

 

出力

8
1.5129
Hello world

サンプル出力

8 
1.5129 
Hello world
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 Printdata
    {
        public void print(int n)
        {
            Console.WriteLine("{0}", n * n * n);
        }
        public void print(double m)
        {
            Console.WriteLine("{0}", m * m);
        }
        public void print(string s)
        {
            Console.WriteLine(s);
        }
        static void Main(string[] args)
        {
            Printdata p = new Printdata();
            p.print(2);
            p.print(1.23);
            p.print("Hello world");
            Console.ReadKey();
        }
    }
} 

 

おすすめ

転載: blog.csdn.net/wangws_sb/article/details/105115078