[c#作业] 9.24

本文展示了如何使用C#编程语言创建一个包含矩形对象的列表,并通过一个气象学家类来获取降雨量和污染数据,进而计算平均污染水平。详细介绍了类、事件、方法和控制流程。
//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
    {
       
    }
}


Postman 是一款广泛使用的 API 开发与测试工具,其版本更新通常会带来功能增强、性能优化以及安全修复。Postman 9.24.2 是其中一个稳定版本,适用于 API 的调试、测试和文档化。 ### Postman 9.24.2 下载 Postman 提供了适用于 Windows、macOS 和 Linux 的客户端版本。用户可以通过以下方式获取 Postman 9.24.2: - **官方网站下载**:访问 [Postman 官方下载页面](https://www.postman.com/downloads/),选择对应操作系统的安装包进行下载。 - **版本锁定**:如果需要特定版本(如 9.24.2),可以通过 Postman 的“历史版本”页面或使用命令行工具如 `brew`(适用于 macOS)来安装特定版本: ```bash brew install --cask postman ``` ### Postman 9.24.2 更新日志概览 虽然 Postman 并不会为每个小版本更新提供详尽的 changelog,但 9.24.x 系列的更新通常包括以下方面的改进: - **性能优化**:提升了大型工作区加载和响应速度。 - **安全性修复**:修补了潜在的安全漏洞,确保用户数据安全。 - **UI 改进**:增强了用户界面交互体验,例如更直观的请求构建器和响应查看器。 - **脚本支持增强**:改进了对 Pre-request Script 和 Test Script 的执行效率。 - **集合运行器改进**:提升了 Newman(Postman 的命令行集合运行器)的兼容性和稳定性。 - **协作功能增强**:优化了团队协作功能,例如共享集合和环境变量的同步机制。 ### 使用 Postman 进行接口测试的示例代码 以下是一个使用 Postman 发送 POST 请求的简单示例,包含 JSON 数据体和自定义 Header: ```http POST /api/v1/company HTTP/1.1 Content-Type: application/json Authorization: Bearer <your_token_here> { "name": "Example Company", "address": "123 Example Street", "industry": "Technology" } ``` 在 Postman 中,用户可以通过 GUI 界面轻松设置请求方法、URL、Headers 和 Body,同时可以使用 Tests 脚本来验证响应结果,例如: ```javascript pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Response time is less than 200ms", function () { pm.expect(pm.response.responseTime).to.be.below(200); }); ``` ### Postman 在 API 开发中的优势 Postman 不仅支持基本的 HTTP 请求发送,还提供了丰富的功能,如自动化测试、Mock 服务器、监控任务、文档生成等。这些功能使得 Postman 成为 API 开发生命周期中不可或缺的工具之一。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值