[c#ジョブ]9.24


//1.p179_13
using System;
namespace p179_13
{
    class Program
    {
        static void Main(string[] args)
        {
            Rectangle rec = null;
            My_list ml = new My_list();
            int count = 0;
            string str1, str2;
            double len, wid;
            bool flag = true;


            Console.WriteLine(" ?");
            str1 = Console.ReadLine();
            if (str1[0] == 'n')
            {
                flag = false;
            }
            while (flag)
            {
                Console.WriteLine(" ");
                str1 = Console.ReadLine();
                len = Convert.ToDouble(str1);
                str2 = Console.ReadLine();
                wid = Convert.ToDouble(str2);

                rec = new Rectangle(len, wid);
                ml[count] = rec;
                count++;

                Console.WriteLine(" ?");
                str1 = Console.ReadLine();
                if (str1[0] == 'n')
                {
                    flag = false;
                }
            }
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("the length and width of ml[{0}] is {1}, {2}", i, ml[i].Length, ml[i].Width);
                Console.WriteLine("the area of ml[{0}] is {1}", i, ml[i].get_area());
                Console.WriteLine("********************");
            }

          


        }
    }
    class Rectangle
    {
        private double length, width;
        public Rectangle()
        {
 
        }
        public Rectangle(double l, double w)
        {
            length = l;
            width = w;
        }
        
        public double Length
        {
            get { return length; }
            set { length = value; }
        }

       public double Width
       {
           get { return width; }
           set { width = value; }
       }
       public double get_area()
       {
           return length * width;
       }
        
    }
    class My_list
    {
        Rectangle[] rec_list = new Rectangle[100];
        static int size = 100;
        public My_list()
        {
            for (int i = 0; i < size; i++)
                rec_list[i] = new Rectangle();
        }
        

        public Rectangle this[int index]
        {
            get
            {
                Rectangle rec = null;
                if (index >= 0 && index <= size - 1)
                {
                    rec = rec_list[index];
                }
               
                return rec;
            }
            set
            {
                if (index >= 0 && index <= size)
                {
                    rec_list[index] = value;
                }
 
            }
        }


    }
}
//2.p225_25
using System;

namespace P225_25
{
    class Meteorologist
    {
        public Meteorologist(int[] rf, int[] po)
        {
            for (int i = 0; i < 12; i++)
            {
                rainfall[i] = rf[i];
                pollution[i] = po[i];
            }
 
        }
        public int[] rainfall = new int[12];
        public int GetRainfall(int index)
        {
            int temp = 0;
            try
            {
                temp = rainfall[index];
            }
            catch(IndexOutOfRangeException e)
            {
                Console.WriteLine(e.ToString());
            }
            return temp;
            
        }
        public int[] pollution = new int[12];
        public double GetAveragePollution(int index)
        {
            double averagePollution = 0;
            try
            {
                averagePollution = (double)pollution[index] / rainfall[index];
            }
            catch (IndexOutOfRangeException e)
            {
                e.ToString();
            }
            catch (DivideByZeroException e)
            {
                e.ToString();
            }
            finally
            {
                Console.WriteLine("Closing WeatherXYZ file");
            }
            
            return averagePollution;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //int[] arr = new int[10];
            //Console.WriteLine(arr[10]);
            int[] arr1 = new int[12];
            int[] arr2 = new int[12];
            for (int i = 0; i < 12; i++)
            {
                arr1[i] = 100 * i;
                arr2[i] = 10 * i;
            }
            //double.pa
            Meteorologist me = new Meteorologist(arr1, arr2);
            double temp = me.GetAveragePollution(2);
            Console.WriteLine(temp);
            
        }
    }
}
//3.p290_21
using System;

namespace p290_21
{
    public  delegate void Del();
    public class BigCat
    {
        public void Cry()
        {
            Console.WriteLine(" !");
        }
 
    }
    public class Host
    {
        public static void awake()
        {
            Console.WriteLine(" !");
        }
 
    }
    public class Mouse
    {
        public static void awake()
        {
            Console.WriteLine(" !");
        }
 
    }
    class Program
    {
        static void Main(string[] args)
        {
            Del d = null;
            BigCat bc = new BigCat();
            Console.WriteLine(" ?");
            string str;
            str = Console.ReadLine();
            if (str[0] == 'y')
            { 
                bc.Cry();
                //Del d = null;
                
                d += Host.awake;
                d += Mouse.awake;
                d();
            }
        }
    }
}

 


// , 。。
using System;

namespace p290_21
{
    public delegate void Del();
    public class BigCat
    {

        event Del E;

        public void Cry()
        {
            Console.WriteLine(" !");
        }
        static void Main(string[] args)
        {
            //Del d = null;

            BigCat bc = new BigCat();
            Console.WriteLine(" ?");
            string str;
            str = Console.ReadLine();
            if (str[0] == 'y')
            {
                bc.E += new Del(bc.Cry);
                bc.E += new Del(Host.awake);
                bc.E += new Del(Mouse.awake);
                //bc.Cry();
                //Del d = null;  

                //d += Host.awake;
                //d += Mouse.awake;
                //d();
                bc.E();
                Console.ReadLine();
            }
        }

    }
    public class Host
    {
        public static void awake()
        {
            Console.WriteLine(" !");
        }

    }
    public class Mouse
    {
        public static void awake()
        {
            Console.WriteLine(" !");
        }

    }
    class Program
    {
       
    }
}