zoukankan      html  css  js  c++  java
  • C#实验三和四

    //实验四
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp3
    {
        class Program
        {
            static int add(int x = 0, int y = 0)
            {
                int z = x + y;
                return z;
            }
            static int mul(int x = 0, int y = 0)
            {
                int z = x * y;
                return z;
            }
    
            static double add(double x = 0, double y = 0)
            {
                double z = x + y;
                return z;
            }
    
            static double mul(double x = 0, double y = 0)
            {
                double z = x * y;
                return z;
            }
            delegate int My(int x, int y);
    
            static void Main(string[] args)
            {
                Console.WriteLine("请输入两个整数:");
                int x = int.Parse(Console.ReadLine());
                int y = int.Parse(Console.ReadLine());
                if (x < 10 && y < 10)
                {
                    My h = new My(add);
                    Console.WriteLine(h(x, y));
                }
                else
                {
                    My h = new My(mul);
                    Console.WriteLine(h(x, y));
                }
                Console.WriteLine(mul(2, 7));
                Console.WriteLine(mul(2.0, 7.2));
            }
        }
    }
    
    实验三 1
      string number;
                string name;
                string educationBackground;
                string[] classRegular = new string[100];
                string[] classMaster = new string[100];
                string[] classDoctor = new string[100];
                int op = 0;
                classRegular[0] = "高级程序设计语言";
                classRegular[1] = "面向对象的程序设计";
                classRegular[2] = "计算机导论";
    
                classMaster[0] = "数据结构与算法";
                classMaster[1] = ".NET应用与开发";
                classMaster[2] = "计算机系统基础";
    
                classDoctor[0] = "计算机组成原理";
                classDoctor[1] = "编译原理";
                classDoctor[2] = "计算机网络";
    
                int classNumber = 0;
                int[] classHaveChosen = new int[3];
    
                Console.WriteLine("请输入您的学号:");
                number = Console.ReadLine().ToString();
                Console.WriteLine("请输入您的姓名:");
                name = Console.ReadLine().ToString();
                Console.WriteLine("请入您的学历:");
                educationBackground = Console.ReadLine().ToString();
                if(educationBackground == "本科")
                {
                    op = 1;
                    int j = 0;
                    Console.WriteLine("本科可选的课程为:");
                    for (int i = 0; i < 3; ++i)
                    {
                        Console.WriteLine(i + "." + classRegular[i]);
                    } 
                    Console.WriteLine("请输入您要选择的课程的门数:");
                    classNumber = int.Parse(Console.ReadLine());
                    for(int i = 0; i < classNumber; i++)
                    {
                        Console.WriteLine("请输入您要选择的课程前的序号:");
                        classHaveChosen[j++] = int.Parse(Console.ReadLine());
                    }
                }
                else if(educationBackground == "硕士")
                {
                    op = 2;
                    int j = 0;
                    Console.WriteLine("硕士可选的课程为:");
                    for (int i = 0; i < 3; ++i)
                    {
                        Console.WriteLine(i + "." + classMaster[i]);
                    }
                    Console.WriteLine("请输入您要选择的课程的门数:");
                    classNumber = int.Parse(Console.ReadLine());
                    for (int i = 0; i < classNumber; i++)
                    {
                        Console.WriteLine("请输入您要选择的课程前的序号:");
                        classHaveChosen[j++] = int.Parse(Console.ReadLine());
                    }
                }
                else if(educationBackground == "博士")
                {
                    op = 3;
                    int j = 0;
                    Console.WriteLine("博士可选的课程为:");
                    for (int i = 0; i < 3; ++i)
                    {
                        Console.WriteLine(i + "." + classDoctor[i]);
                    }
                    Console.WriteLine("请输入您要选择的课程的门数:");
                    classNumber = int.Parse(Console.ReadLine());
                    for (int i = 0; i < classNumber; i++)
                    {
                        Console.WriteLine("请输入您要选择的课程前的序号:");
                        classHaveChosen[j++] = int.Parse(Console.ReadLine());
                    }
                }
                Console.WriteLine("您的基本信息为:");
                Console.WriteLine("姓名:" + name);
                Console.WriteLine("学号:" + number);
                Console.WriteLine("学历:" + educationBackground);
                Console.WriteLine("您的选课信息为:");
                if(op == 1)
                {
                    for(int i = 0; i < classNumber; i++)
                    {
                        Console.WriteLine(i + "." + classRegular[classHaveChosen[i]]);
                    }
                }
                else if(op == 2)
                {
                    for (int i = 0; i < classNumber; i++)
                    {
                        Console.WriteLine(i + "." + classMaster[classHaveChosen[i]]);
                    }
                }
                else if(op == 3)
                {
                    for (int i = 0; i < classNumber; i++)
                    {
                        Console.WriteLine(i + "." + classDoctor[classHaveChosen[i]]);
                    }
                }
    
    //实验三 2
    int[] xx = new int[100];
                int[] yy = new int[100];
                int[] zz = new int[100];
                int x = 0, y = 0;
                int i = 0;
                for (x = 0; x  <= 20; x++)
                {
                    for (y = 0; y <= 33; y++)
                    {
                        if (15 * x + 9 * y  + (100 - x - y) == 300)
                        {
                            xx[i] = x;
                            yy[i] = y;
                            zz[i] = 100 - x - y;
                            i++;
                        }
                    }
                }
                Console.WriteLine("可能的解:");
                for(int j = 0; j < i; j++)
                {
                    Console.WriteLine("x:" + xx[j] + " y:" + yy[j] + " z:" + zz[j]);
                }
    
    作者:LightAc
    出处:https://www.cnblogs.com/lightac/
    联系:
    Email: dzz@stu.ouc.edu.cn
    QQ: 1171613053
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    【原创】elasticsearch入门
    【原创】nginx入门
    【原创】SpringMVC同一RequestMapping返回不同的类型
    [原创]在Centos7.2上源码安装PHP、Nginx、Zentao禅道
    CentOS环境下tomcat启动超级慢的解决方案
    [原创]Nginx反向代理及负载均衡
    常见证书格式和转换
    MySQL基本命令
    研究重力加速度随地球纬度递增的原因
    倒霉的一天
  • 原文地址:https://www.cnblogs.com/lightac/p/11642856.html
Copyright © 2011-2022 走看看