111年警察人員特種考試資訊管理人員三等物件導向程式設計

一、下列類別圖及 C# 程式碼是一個影像識別軟體 ImageDetector.exe 的類別設計與部分程式碼,請依以下二個程式執行的結果來撰寫各小題的程式碼。(每小題5分,共15分)

    影像識別軟體的類別圖:

   

pic01.png

   影像識別軟體的部分程式碼:

    Program.cs

class Program

{

     void Main(string[ ] args)

     {

         IFoo foo = null;

         if (args.Length > 0)

         {

             if (args[0] == "1")

                 foo = new FooFeature( );

             else if (args[0] == "2")

                 foo = new FooFeatureFast( );

             string text = foo.Run( );

             Console.WriteLine(text);

         }

         else

         {

             Console.WriteLine("The arguments is null value.");

         }

     }

}

    影像識別軟體程式執行結果(1)

C:\> ImageDetector.exe 1

Hi FooFeature Class!

    影像識別軟體程式執行結果(2)

C:\> ImageDetector.exe 2

Hi FooFeatureFast Class!

    ()請撰寫 IFoo.cs 程式碼。

    ()請撰寫 FooFeatureFast.cs 程式碼。

    ()請撰寫 FooFeature.cs 程式碼。

答:

設定:

pic02.png

 

 

 

 

 

 

 

 

 

 

Program.cs

using System;

namespace ConsoleApp1 {

    class Program {

        static void Main(string[ ] args) {

            IFoo foo = null;

            if (args.Length > 0) {

                if (args[0] == "1") {

                    foo = new FooFeature( );

                }

                else if (args[0] == "2") {

                    foo = new FooFeatureFast( );

                }

                string text = foo.Run();

                Console.WriteLine(text);

            }

            else {

                Console.WriteLine("The arguments is null value.");

            }

            Console.ReadLine( );

        }

    }

}

()IFoo.cs程式碼

namespace ConsoleApp1 {

    interface IFoo {

        string Run( );

    }

}

()FooFeatureFast.cs程式碼

namespace ConsoleApp1 {

    class FooFeatureFast : IFoo {

        public string Run( ) { return "HI FooFeatureFast Class!"; }

    }

}

()FooFeature.cs程式碼

namespace ConsoleApp1 {

    class FooFeature : IFoo {

        public string Run( ) { return "Hi FooFeature Class!"; }

    }

}

arrow
arrow
    文章標籤
    物件導向程式設計
    全站熱搜

    jacksaleok 發表在 痞客邦 留言(0) 人氣()