zoukankan      html  css  js  c++  java
  • C#考试题第一波

    第一章

    1.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

     

    namespace Test1_1

    {

        class Program

        {

            static void Main(string[] args)

            {

                int n, i, result = 0;

                Console.WriteLine("请输入一个正整数");

                n = int.Parse(Console.ReadLine());

                if (n % 2 == 0)

                {

                    for (i = 2; i <= n; i++)

                    {

                        if (i % 2 == 0)

                            result += i;

                    }

                }

                else

                {

                    for (i = 1; i <= n; i++)

                    {

                        if (i % 2 != 0)

                            result += i;

                    }

                }

                Console.WriteLine(result);

                Console.ReadKey();

            }

        }

    }

     

    11.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

     

    namespace Test1_10

    {

        class Program

        {

            static void Main(string[] args)

            {

                int i;

                string s_text, s_key, s_result=null;

                char ch;

                Console.WriteLine("请输入原字符串:");

                s_text = Console.ReadLine();

                Console.WriteLine("请输入密钥字符串:");

                s_key = Console.ReadLine();

                if (s_text.Length != s_key.Length)

                {

                    Console.WriteLine("密钥字符串与原字符串长度必须相等");

                    return ;

                }

                    for(i=0;i<s_text.Length-1;i++)

                    {

                        ch =Convert.ToChar(s_text[i]^s_key[i]);

                        s_result+=ch;

                    }

               

                Console.WriteLine("加密后的字符串为:");

                Console.WriteLine(s_result);

                Console.ReadKey();

            }

        }

    }

    第二章

    1.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

     

    namespace Test2_1

    {

        class Program

        {

            static void Main(string[] args)

            {

                Animal ani = new Animal();

                Console.WriteLine(ani.Introduce());

                Dog dog = new Dog();

                Console.WriteLine(dog.Introduce());

                Cat cat = new Cat();

                Console.WriteLine(cat.Introduce());

                Console.ReadKey();

            }

        }

    }

     

     

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

     

    namespace Test2_1

    {

        class Animal

        {

            bool m_sex;

            int m_age;

            public Animal()

            {

                Sex = false;

            }

            public bool Sex

            {

                get { return m_sex; }

                set { m_sex = value; }

            }

            public int Age

            {

                get { return m_age; }

                set { m_age = value; }

            }

            public virtual string Introduce()

            {

                if (Sex)

                    return "This is a male Animal!";

                else

                    return "This is a female Animal!";

            }

        }

        class Dog:Animal

        {

           public Dog()

            {

                Sex = true;

            }

     

            public override string Introduce()

            {

                if (Sex)

                    return "This is a male Dog!";

                else

                    return "This is a female Dog!";

            }

        }

        class Cat : Animal

        {

            public Cat()

            {

                Sex = false;

            }

            public override string Introduce()

            {

                if (Sex)

                    return "This is a male Cat!";

                else

                    return "This is a female Cat!";

            }

        }

    }

     

    11.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

     

    namespace Test2_11

    {

        class Program

        {

            static void Main(string[] args)

            {

                Animal animal = new Animal();

                animal = new Dog();

                Console.WriteLine( animal.Roar());

                animal = new Cat();

                Console.WriteLine(animal.Roar());

                animal = new Cow();

                Console.WriteLine(animal.Roar());

                Console.ReadKey();

            }

        }

    }

     

     

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

     

    namespace Test2_11

    {

        class Animal

        {

            private bool m_sex;

            private string m_sound;

            public bool Sex

            {

                get { return m_sex; }

                set { m_sex = value; }

            }

            public Animal()

            {

                Sex = false;

                Sound = "Howl...";

            }

            public string Sound

            {

                get { return m_sound; }

                set { m_sound = value; }

            }

            public virtual string Roar()

            {

                return m_sound;

            }

        }

        class Dog:Animal

        {

            public Dog()

            {

                Sex = true;

                Sound = "Wow...";

            }

            public override string Roar()

            {

                return "Dog:"+ Sound;

            }

        }

        class Cat : Animal

        {

            public Cat()

            {

                Sex = true;

                Sound = "Miaow...";

            }

            public override string Roar()

            {

                return "Cat:" + Sound;

            }

        }

        class Cow : Animal

        {

            public Cow()

            {

                Sex = true;

                Sound = "Moo...";

            }

            public override string Roar()

            {

                return "Cow:" + Sound;

            }

        }

    }

     

  • 相关阅读:
    Array方面Js底层代码学习记录
    DOM 节点
    跨域
    狂雨cms代码审计:后台文件包含getshell
    在PHP一句话木马使用过程中的种种坑点分析
    记对某CMS的一次代码审计
    通达OA任意文件上传并利用文件包含导致远程代码执行漏洞分析
    DedeCMS V5.7 SP2后台存在代码执行漏洞
    zzzcms(php) v1.7.5 前台SQL注入及其他
    权限维持及后门持久化技巧总结
  • 原文地址:https://www.cnblogs.com/wwws/p/7508390.html
Copyright © 2011-2022 走看看