C# —— 面向对象编程练习

2023-11-03

C# —— 面向对象编程练习

基础题
在这里插入图片描述
代码如下:

class Program
    {
        static void Main(string[] args)
        {
            rectangle r = new rectangle();
            Console.WriteLine("调用不含参构造函数初始化后矩形的长为{0},宽为{1}", r.GetLength().ToString(), r.GetWidth().ToString());
            Console.WriteLine("请输入矩形长、宽:");
            rectangle R = new rectangle(float.Parse(Console.ReadLine()), float.Parse(Console.ReadLine()));
            Console.WriteLine("调用不含参构造函数初始化后矩形的长为{0},宽为{1}", R.GetLength().ToString(), R.GetWidth().ToString());
            Console.WriteLine("此矩形的周长为{0},面积为{1}", R.GetPerimeter().ToString(), R.GetArea().ToString());
            Console.WriteLine("修改矩形的长为:");
            R.ChangeLength(float.Parse(Console.ReadLine()));
            Console.WriteLine("修改矩形的宽为:");
            R.ChangeWidth(float.Parse(Console.ReadLine()));
            Console.WriteLine("修改后的矩形的周长为{0},面积为{1}", R.GetPerimeter().ToString(), R.GetArea().ToString());
        }
    }
    class rectangle
    {	
    	//私有访问。只限于本类成员访问,子类,实例都不能访问
        private float len;
        private float wid;
        //无参构造函数
        public rectangle()
        {
            this.len = 0;
            this.wid = 0;
        }
        //含参构造函数
        public rectangle(float length,float width)
        {
            this.len = length;
            this.wid = width;
        }
        //求周长
        public float GetPerimeter()
        {
            return (this.len + this.wid) * 2;
        }
        //求面积
        public float GetArea()
        {
            return this.len * this.wid;
        }
        //取矩形长度
        public float GetLength()
        {
            return this.len;
        }
        //取矩形宽度
        public float GetWidth()
        {
            return this.wid;
        }
        //修改矩形长度
        public void ChangeLength(float length)
        {
            this.len = length;
        }
        // 修改矩形宽度
        public void ChangeWidth(float width)
        {
            this.wid = width;
        }
    }

运行结果:
在这里插入图片描述
解析:

  • this代表当前类的实例对象,所以this.len 和 this.wid 都是全局变量。

在这里插入图片描述
考察点:继承,构造函数的多种方法

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Student s1 = new Student();
            s1.Display();
            Student s2 = new Student("张大磊", "男", 40, new int[] { 10, 20, 30, 40, 50 });
            s2.Display();
            Student s3 = new Student(new int[] { 60, 70, 80, 90, 100 });
            s3.Display();
        }
    }
    class Person
    {
        //保护访问。只限于本类和子类访问,实例不能访问
        protected string Name;
        protected string Sex;
        protected int Age;

        /*此处必须写一个无参构造函数。
        因为如果你的父类定义了带参数的构造函数同时没有无参重载的情况下,
        那么在子类中,你必须对父类的带参数的构造进行赋值
        */
        public Person() { }
        public Person(string name , string sex ,int age)
        {
            this.Name = name;
            this.Sex = sex;
            this.Age = age;
        }
    }

    class Student : Person
    {
        private int[] Sorce;
        //构造函数1
        public Student()
        {
            this.Name = "张磊";
            this.Sex = "男";
            this.Age = 30;
            this.Sorce = new int[] { 60, 60, 60, 60, 60 };
        }
        //构造函数2
        public Student(string name,string sex,int age,int[] sorce)
            :base(name, sex, age)//调用父类的含参构造函数
        {
            this.Sorce = sorce;
        }
        //构造函数3
        public Student(int[] sorce)
        {
            this.Name = "张小磊";
            this.Sex = "男";
            this.Age = 30;
            this.Sorce = sorce;
        }
        //求平均成绩
        public float Avg()
        {
            float sum = 0;
            foreach (int i in Sorce)
            {
                sum += i;
            }
            return sum / Sorce.Length;
        }
        public void Display()
        {
            Console.WriteLine($"姓名:{this.Name}");
            Console.WriteLine($"性别:{this.Sex}");
            Console.WriteLine($"年龄:{this.Age}");
            Console.Write("成绩:");
            foreach (int i in this.Sorce)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine($"平均成绩为:{Avg()}\n");
        }
    }

运行结果:
在这里插入图片描述
3.
(1)定义一个接口CanCry,描述会吼叫的方法public void cry()。 
(2)分别定义狗类(Dog)和猫类(Cat),实现CanCry接口。实现方法的功能分别为:打印输出“我是狗,我的叫声是汪汪汪”、“我是猫,我的叫声是喵喵喵”。 
(3)定义一个主类G,①定义一个void makeCry(CanCry c)方法,其中让会吼叫的事物吼叫。 ②在main方法中创建狗类对象(dog)、猫类对象(cat)、G类对象(g),用g调用makecry方法,让狗和猫吼叫。

考察点:接口,多继承。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Cancry dog = new Dog();
            Cancry cat = new Cat();
            G g = new G();
            g.makeCry(dog);
            g.makeCry(cat);
        }
    }
    //接口用来实现多继承是让一个类具有两个以上基类的唯一方式。
    interface Cancry
    {
        public void cry();        
    }
    class Dog : Cancry
    {
        public void cry()
        {
            Console.WriteLine("我是狗,我的叫声是汪汪汪");
        }
    }
    class Cat : Cancry
    {
        public void cry()
        {
            Console.WriteLine("我是猫,我的叫声是喵喵喵");
        }
    }
    class G
    {
        public void makeCry(Cancry c)
        {
            c.cry();
        }
    }

运行结果:
在这里插入图片描述

4.定义一个人类,包括属性:姓名、性别、年龄、国籍;包括方法:吃饭、睡觉,工作。 (1)根据人类,派生一个学生类,增加属性:学校、学号;重写工作方法(学生的工作是学习)。 (2)根据人类,派生一个工人类,增加属性:单位、工龄;重写工作方法(工人的工作是做工)。 (3)根据学生类,派生一个学生干部类,增加属性:职务;增加方法:开会。 (4)编写主函数分别对上述3类具体人物进行测试。

考点:继承,方法的重写,属性。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Student student = new Student("张磊", "男", 18, "中国", "河南大学", "s123");
            student.Work();
            Worker worker = new Worker("张小磊", "男", 28, "中国", "河南大学", 4);
            worker.Work();
            Student_cadres student_cadres = new Student_cadres("张大磊", "男", 20, "河南大学","s456", "班长");
            student_cadres.Meeting();
        }
    }
    class Person
    {
        public string Name { get;  set; } = "";
        public string Sex { get; protected set; } = "";
        public int Age { get; protected set; } = 0;
        public string Country { get; protected set; } = "";
        public virtual void Eat() { }
        public virtual void Ship() { }
        public virtual void Work() { }       
    }

    class Student : Person
    {
        public Student() { }
        public Student(string name,string sex,int age ,string country,string school,string stu_num)
        {
            Name = name;
            Sex = sex;
            Age = age;
            Country = country;
            School = school;
            Stu_Num = stu_num;
        }
        public string School { get; protected set; } = "";
        public string Stu_Num { get; protected set; } = "";
        public override void Work()
        {
            Console.WriteLine($"{Name}是{School}{Age}岁的{Country}{Sex}学生,{Name}的学号是{Stu_Num}。{Name}有好好学习哦\n");
        }
    }

    class Worker: Person
    {
        public Worker(string name, string sex, int age, string country, string company, int working_years)
        {
            Name = name;
            Sex = sex;
            Age = age;
            Country = country;
            Company = company;
            Working_years = working_years;
        }
        public string Company { get; protected set; } = "";
        public int Working_years { get; protected set; } = 0;
        public override void Work()
        {
            Console.WriteLine($"{Name}是{Company}{Age}岁的{Country}{Sex}工人,{Name}的工龄是{Working_years}。{Name}工作超努力的哦\n");
        }
    }

    class Student_cadres : Student
    {
        public Student_cadres(string name, string sex, int age, string country, string stu_num, string post)
        {
            Name = name;
            Sex = sex;
            Age = age;
            Country = country;
            Stu_Num = stu_num;
            Post = post;
        }
        public string Post { get; protected set; } = "";
        public void Meeting()
        {
            Console.WriteLine($"{Name}是{School}{Age}岁的{Country}{Sex}学生,{Name}的学号是{Stu_Num},职务是{Post}。{Name}有认真开会哦\n");
        }
    }

运行结果:
在这里插入图片描述

5.Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:double getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。

SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。属性:每小时的工资、每月工作的小时数

SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率

BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。属性:底薪。

写一个程序,把若干各种类型的员工放在一个Employee数组里,
写一个方法,打印出某月每个员工的工资数额。
注意:要求把每个类都做成完全封装,不允许非私有化属性。

考察点:抽象,私有化属性。

代码如下:

class Program
    {   
        public void PrintSalary(Employee[] woker)
        {
            Console.Write("请输入现在的月份:");
            int month = int.Parse(Console.ReadLine());
            for (int i = 0; i < woker.Length; i++)
            {
                Console.WriteLine($"我是{woker[i].GetName()},我在{month}月的工资是{woker[i].getSalary(month)}\n");
            }
        }
        static void Main(string[] args)
        {
            SalariedEmployee employee1 = new SalariedEmployee("张磊",1,5000);
            HourlyEmployee employee2 = new HourlyEmployee("张小磊", 2, 20, 200);
            SalesEmployee employee3 = new SalesEmployee("张大磊", 3, 10000, 0.7);
            BasePlusSalesEmployee emloyee4 = new BasePlusSalesEmployee("张磊磊", 4, 5000, 0.7, 3000);

            Employee[] woker = { employee1, employee2, employee3, emloyee4 };
            Program p = new Program();
            p.PrintSalary(woker);
        }
    }
    abstract class Employee
    {
        private string Name { get; set; } = "";
        private int BirthMonth { get; set; } = 0;
        public void SetName(string name)
        {
            Name = name;
        }
        public void SetBirthMonth(int birthmonth)
        {
            BirthMonth = birthmonth;
        }
        public string GetName()
        {
            return Name;
        }
        public int GetBirthMonth()
        {
            return BirthMonth;
        }
        public abstract double getSalary(int month) ;
    }

    class SalariedEmployee : Employee
    {
        private int Monthly_Salary { get; set; } = 0;
        public SalariedEmployee (string name,int birthmonth,int monthly_salary)
        {
            SetName(name);
            SetBirthMonth(birthmonth);
            Monthly_Salary = monthly_salary;
        }
        public override double getSalary(int month)
        {
            if (GetBirthMonth() == month)
            {
                return Monthly_Salary + 100;
            }
            else
                return Monthly_Salary;
        }
    }

    class HourlyEmployee : Employee
    {
        private int Hourly_Salary { get; set; } = 0;
        private int Hour { get; set; } = 0;
        public HourlyEmployee(string name, int birthmonth, int hourly_salary,int hour)
        {
            SetName(name);
            SetBirthMonth(birthmonth);
            Hourly_Salary = hourly_salary;
            Hour = hour;
        }
        public override double getSalary(int month)
        {
            double money = 0;
            if (Hour > 160)
            {
                money = 160 * Hourly_Salary + (Hour - 160) * Hourly_Salary * 1.5;
            }
            else
                money = Hourly_Salary * Hour;
            if (GetBirthMonth() == month)
                return money + 100;
            else
                return money;
        }
    }

    class SalesEmployee : Employee
    {
        private int Monthly_Sales { get; set; } = 0;
        private double Royalty_Rate { get; set; } = 0;
        public int GetMonthly_Sales() { return Monthly_Sales; }
        public double GetRoyalty_Rate() { return Royalty_Rate; }
        public SalesEmployee() { }
        public SalesEmployee(string name, int birthmonth,int monthly_slaes,double royalty_rate)
        {
            SetName(name);
            SetBirthMonth(birthmonth);
            Monthly_Sales = monthly_slaes;
            Royalty_Rate = royalty_rate;
        }
        public override double getSalary(int month)
        {
            double money = Monthly_Sales * Royalty_Rate;
            if (GetBirthMonth() == month)
                return money + 100;
            else
                return money;
        }
    }

    class BasePlusSalesEmployee : SalesEmployee
    {
        private int Base_Salary { get; set; } = 0;
        public BasePlusSalesEmployee(string name, int birthmonth, int monthly_slaes, double royalty_rate, int base_salary)
            :base(name,birthmonth,monthly_slaes,royalty_rate)
        {
            Base_Salary = base_salary;
        }
        public override double getSalary(int month)
        {
            double money = GetMonthly_Sales() * GetRoyalty_Rate() + Base_Salary;
            if (GetBirthMonth() == month)
                return money + 100;
            else
                return money;
        }

    }

运行结果:
在这里插入图片描述
解析:
本题特殊点在于要求属性全是私有的,那么子类想要修改和获取父类的属性时就需要通过父类的Get()和Set()函数来进行操作。

6.图书买卖类库,该系统中必须包括三个类,类名及属性设置如下。
图书类(Book)

  • 图书编号(bookId)
  • 图书名称(bookName)
  • 图书单价(price)
  • 库存数量(storage)

订单项类(OrderItem)

  • 图书名称(bookName)
  • 图书单价(price)
  • 购买数量(num)

订单类(Order):

  • 订单号(orderId)
  • 订单总额(total)
  • 订单日期(date)
  • 订单项列表(items)

具体要求及推荐实现步骤
1、创建图书类,根据业务需要提供需要的构造方法和setter/getter方法。
2、创建订单项类,根据业务需要提供需要的构造方法和setter/getter方法。
3、创建订单类,根据业务需要提供需要的构造方法和setter/getter方法。
4、创建测试类Test,实现顾客购买图书。
A、获取所有图书信息并输出:创建至少三个图书对象并输出即可。
B、顾客购买图书:顾客通过输入图书编号来购买图书,并输入购买数量。
C、输出订单信息:包括订单号、订单明细、订单总额、订单日期。

考察点:类之间的相互协同

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Book book1 = new Book(1, "Java教程", 30.6, 30);
            Book book2 = new Book(2, "JSP 指南", 42.1, 40);
            Book book3 = new Book(3, "SSH 架构", 47.3, 15);
            Book[] book = { book1, book2, book3 };
            Test test = new Test();
            test.BookItem(book);
            Order order = new Order();
            test.PrintBookItems(test.Buy(book), order);
        }
    }
    class Test
    {
        public void BookItem(Book[] book)
        {
            Console.WriteLine("\t图书列表");
            Console.WriteLine(string.Format(
                    "{0,-10}{1,-10}{2,-10}{3,5}",
                    "图书编号", "图书名称", "图书单价", "库存数量"));
            Console.WriteLine("--------------------------------------------------");
            for (int i = 0; i < book.Length; i++)
            {
                Console.WriteLine($"{book[i].GetBookId()}\t{book[i].GetBookName()}\t{book[i].GetPrice()}\t{book[i].GetStock()}");
            }
            Console.WriteLine("--------------------------------------------------");
        }
        public List<OrderItem> Buy(Book[] book)
        {
            List<OrderItem> OrderItemList = new List<OrderItem>();
            int i = 1;
            while (i <= 3)
            {
                i++;
                Console.Write("请输入图书编号选择图书:");
                int bookid = int.Parse(Console.ReadLine())-1;
                Console.Write("请输入购买图书的数量:");
                int num = int.Parse(Console.ReadLine());
                Console.WriteLine("请继续购买图书。");
                OrderItemList.Add(new OrderItem(num, book[bookid].GetBookName(), book[bookid].GetPrice()));
            }
            return OrderItemList;
        }
        public void PrintBookItems(List<OrderItem> OrderItemList, Order order)
        {
            Console.WriteLine("\n\t图书订单");
            Console.WriteLine($"图书订单号:{order.GetOrderId()}");
            Console.WriteLine(string.Format("{0,-10}{1,-10}{2,-10}", "图书名称", "购买数量", "图书单价"));
            Console.WriteLine("---------------------------------");
            order.PrintItems(OrderItemList);
            Console.WriteLine("---------------------------------");
            Console.WriteLine($"订单总额:\t\t\t{order.GetTotal(OrderItemList)}");
            Console.WriteLine($"日期:{order.GetData()}");
        }
    }
    class Book
    {
        private int BookId { get; set; } = 0;
        private string BookName { get; set; } = "";
        private double Price { get; set; } = 0;
        private int Stock { get; set; } = 0;
        public Book(int bookid, string bookname, double price, int stock)
        {
            BookId = bookid;
            BookName = bookname;
            Price = price;
            Stock = stock;
        }
        public void SetStock(int stock)
        {
            Stock = stock;
        }
        public void SetPrice(double price)
        {
            Price = price;
        }
        public int GetBookId()
        {
            return BookId;
        }
        public string GetBookName()
        {
            return BookName;
        }
        public double GetPrice()
        {
            return Price;
        }
        public int GetStock()
        {
            return Stock;
        }
    }

    class OrderItem
    {
        private int Num { get; set; } = 0;
        private string BookName { get; set; } = "";
        private double Price { get; set; } = 0;
        public OrderItem(int num, string bookname, double price)
        {
            Num = num;
            BookName = bookname;
            Price = price;
        }
        public void SetNum(int num)
        {
            Num = num;
        }
        public int GetNum()
        {
            return Num;
        }
        public string GetBookName()
        {
            return BookName;
        }
        public double GetPrice()
        {
            return Price;
        }
    }

    class Order
    {
        private string OrderId = "00001";
        private double Total { get; set; } = 0;
        private string Data = DateTime.Now.ToString();
        private string Items { get; set; } = "";
        public double GetTotal(List<OrderItem> OrderItemList)
        {
            foreach (var orderitem in OrderItemList)
            {
                Total += orderitem.GetNum() * orderitem.GetPrice();
            }
            return Total;
        }
        public string GetData()
        {
            return Data;
        }
        public void PrintItems(List<OrderItem> OrderItemList)
        {
            foreach (var orderitem in OrderItemList)
            {
                Console.WriteLine($"{orderitem.GetBookName()}\t{orderitem.GetNum()}\t{orderitem.GetPrice()}");
            }
        }
        public string GetOrderId() { return OrderId; }


    }

运行结果:
在这里插入图片描述
解析:
感觉这道题没用多少类的知识,但是写完感觉对函数用法更加深刻了。建议闲了动手写写,还挺好玩的。

7.在这里插入图片描述
考察点:虚方法的实现,二维数组。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入本次评优的学生数量:");
            string[,] s = new string[int.Parse(Console.ReadLine()),2];
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Console.Write("请输入学生姓名:");
                s[i, 0] = Console.ReadLine();
                Console.Write("请输入学生的成绩:");
                s[i, 1] = Console.ReadLine();
                Console.WriteLine();
            } 
            Console.Write("请输入本次评优的老师数量:");
            string[,] t = new string[int.Parse(Console.ReadLine()),2];
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Console.Write("请输入老师姓名:");
                t[i, 0] = Console.ReadLine();
                Console.Write("请输入老师的论文数量:");
                t[i, 1] = Console.ReadLine();
                Console.WriteLine();
            }
            Console.WriteLine("----优秀学生榜----");
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Student student = new Student(s[i, 0].ToCharArray(), int.Parse(s[i, 1]));
                if (student.Isgood() == 1)
                    Console.WriteLine(student.print());
            }

            Console.WriteLine("\n----优秀老师榜----");
            for (int i = 0; i < s.GetLength(0); i++)
            {
                Teacher teacher = new Teacher(t[i, 0].ToCharArray(), int.Parse(t[i, 1]));
                if (teacher.Isgood() == 1)
                    Console.WriteLine(teacher.print());
            }
        }
        class Base
        {
            protected char[] Name = new char[8];
            protected int Num;
            public Base() { }
            public Base(char[] name)
            {
                Name = name;
            }
            public string print()
            {
                return $"我是{string.Join("",Name)},我的成果是{Num}(分/篇),所以我很优秀哦!";
            }
            public virtual int Isgood() { return 0; }
        }
        class Student : Base
        {
            public Student(char[] name,int num)
                :base(name)
            {
                Num = num;
            }
            public override int Isgood()
            {
                if (Num > 90)
                    return 1;
                else
                    return 0;
            }
        }
        class Teacher : Base
        {
            public Teacher(char[] name,int num)
                :base (name)
            {
                Num = num;
            }
            public override int Isgood()
            {
                if (Num > 3)
                    return 1;
                else
                    return 0;
            }
        }
    }

运行结果:
在这里插入图片描述
8.在这里插入图片描述
在这里插入图片描述在这里插入图片描述
基础题不难。

代码如下:

class Program
    {
        static void Main(string[] args)
        {
            Triangle tri = new Triangle(1, 1, 4, 1, 4, 5);
            tri.f();
            tri.Print();
        }
    }
    class Point
    {
        protected int x1 { get; set; } = 0;
        protected int y1 { get; set; } = 0;
        public Point() { }
        public Point(int a ,int b)
        {
            x1 = a;
            y1 = b;
        }
    }

    class Line : Point
    {
        protected int x2 { get; set; } = 0;
        protected int y2 { get; set; } = 0;
        public Line() { }
        public Line(int a,int b,int c,int d)
            :base(a, b)
        {
            x2 = c;
            y2 = d;
        }
    }

    class Triangle : Line
    {
        private int x3 { get; set; } = 0;
        private int y3 { get; set; } = 0;
        private double area { get; set; } = 0;
        public Triangle(int a, int b, int c, int d, int e,int f)
            :base(a, b, c, d)
        {
            x3 = e;
            y3 = f;
        }
        public void f()
        {
            double x = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
            double y = Math.Sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
            double z = Math.Sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
            double s = (x + y + z) / 2;
            area = Math.Sqrt(s * (s - x) * (s - y) * (s - z));
        }
        public void Print()
        {
            Console.WriteLine($"({x1},{y1})\t({x2},{y2})\t({x3},{y3})");
            Console.WriteLine($"area = {area}");
        }
    }

运行结果:
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C# —— 面向对象编程练习 的相关文章

  • InvalidOperationException - 对象当前正在其他地方使用 - 红十字

    我有一个 C 桌面应用程序 其中我连续创建的一个线程从源 实际上是一台数码相机 获取图像并将其放在 GUI 中的面板 panel Image img 上 这必须是另一个线程 如它是控件的代码隐藏 该应用程序可以工作 但在某些机器上 我会在随
  • 使用 std::packaged_task/std::exception_ptr 时,线程清理程序报告数据争用

    我遇到了线程清理程序 TSan 的一些问题 抱怨某些生产代码中的数据争用 其中 std packaged task 通过将它们包装在 std function 中而移交给调度程序线程 对于这个问题 我简化了它在生产中的作用 同时触发 TSa
  • Directory.Delete 之后 Directory.Exists 有时返回 true ?

    我有非常奇怪的行为 我有 Directory Delete tempFolder true if Directory Exists tempFolder 有时 Directory Exists 返回 true 为什么 可能是资源管理器打开了
  • MVC 在布局代码之前执行视图代码并破坏我的脚本顺序

    我正在尝试将所有 javascript 包含内容移至页面底部 我正在将 MVC 与 Razor 一起使用 我编写了一个辅助方法来注册脚本 它按注册顺序保留脚本 并排除重复的内容 Html RegisterScript scripts som
  • 复制目录内容

    我想将目录 tmp1 的内容复制到另一个目录 tmp2 tmp1 可能包含文件和其他目录 我想使用C C 复制tmp1的内容 包括模式 如果 tmp1 包含目录树 我想递归复制它们 最简单的解决方案是什么 我找到了一个解决方案来打开目录并读
  • java.io.Serialized 在 C/C++ 中的等价物是什么?

    C C 的等价物是什么java io Serialized https docs oracle com javase 7 docs api java io Serializable html 有对序列化库的引用 用 C 序列化数据结构 ht
  • 将 Word 文档另存为图像

    我正在使用下面的代码将 Word 文档转换为图像文件 但是图片显得太大 内容不适合 有没有办法渲染图片或将图片保存到合适的尺寸 private void btnConvert Click object sender EventArgs e
  • 为什么调用非 const 成员函数而不是 const 成员函数?

    为了我的目的 我尝试包装一些类似于 Qt 共享数据指针的东西 经过测试 我发现当应该调用 const 函数时 会选择它的非 const 版本 我正在使用 C 0x 选项进行编译 这是一个最小的代码 struct Data int x con
  • 从 Linux 内核模块中调用用户空间函数

    我正在编写一个简单的 Linux 字符设备驱动程序 以通过 I O 端口将数据输出到硬件 我有一个执行浮点运算的函数来计算硬件的正确输出 不幸的是 这意味着我需要将此函数保留在用户空间中 因为 Linux 内核不能很好地处理浮点运算 这是设
  • 在一个平台上,对于所有数据类型,所有数据指针的大小是否相同? [复制]

    这个问题在这里已经有答案了 Are char int long 甚至long long 大小相同 在给定平台上 不能保证它们的大小相同 尽管在我有使用经验的平台上它们通常是相同的 C 2011 在线草稿 http www open std
  • Qt - ubuntu中的串口名称

    我在 Ubuntu 上查找串行端口名称时遇到问题 如您所知 为了在 Windows 上读取串口 我们可以使用以下代码 serial gt setPortName com3 但是当我在 Ubuntu 上编译这段代码时 我无法使用这段代码 se
  • 为什么 std::strstream 被弃用?

    我最近发现std strstream已被弃用 取而代之的是std stringstream 我已经有一段时间没有使用它了 但它做了我当时需要做的事情 所以很惊讶听到它的弃用 我的问题是为什么做出这个决定 有什么好处std stringstr
  • AES 128 CBC 蒙特卡罗测试

    我正在 AES 128 CBC 上执行 MCT 如中所述http csrc nist gov groups STM cavp documents aes AESAVS pdf http csrc nist gov groups STM ca
  • 如何设置 log4net 每天将我的文件记录到不同的文件夹中?

    我想将每天的所有日志保存在名为 YYYYMMdd 的文件夹中 log4net 应该根据系统日期时间处理创建新文件夹 我如何设置它 我想将一天中的所有日志保存到 n 个 1MB 的文件中 我不想重写旧文件 但想真正拥有一天中的所有日志 我该如
  • 将 MQTTNet 服务器与 MQTT.js 客户端结合使用

    我已经启动了一个 MQTT 服务器 就像this https github com chkr1011 MQTTnet tree master例子 该代码托管在 ASP Net Core 2 0 应用程序中 但我尝试过控制台应用程序 但没有成
  • 使用 %d 打印 unsigned long long

    为什么我打印以下内容时得到 1 unsigned long long int largestIntegerInC 18446744073709551615LL printf largestIntegerInC d n largestInte
  • 按 Esc 按键关闭 Ajax Modal 弹出窗口

    我已经使用 Ajax 显示了一个面板弹出窗口 我要做的是当用户按 Esc 键时关闭该窗口 这可能吗 如果有人知道这一点或以前做过这一点 请帮助我 Thanks 通过以下链接 您可以通过按退出按钮轻松关闭窗口 http www codepro
  • 调用堆栈中的“外部代码”是什么意思?

    我在 Visual Studio 中调用一个方法 并尝试通过检查调用堆栈来调试它 其中一些行标记为 外部代码 这到底是什么意思 方法来自 dll已被处决 外部代码 意味着该dll没有可用的调试信息 你能做的就是在Call Stack窗口中单
  • 如何部署“SQL Server Express + EF”应用程序

    这是我第一次部署使用 SQL Server Express 数据库的应用程序 我首先使用实体 框架模型来联系数据库 我使用 Install Shield 创建了一个安装向导来安装应用程序 这些是我在目标计算机中安装应用程序所执行的步骤 安装
  • 从列表中选择项目以求和

    我有一个包含数值的项目列表 我需要使用这些项目求和 我需要你的帮助来构建这样的算法 下面是一个用 C 编写的示例 描述了我的问题 int sum 21 List

随机推荐

  • 页面结构分析

  • 关于解决Win10家庭中文版没有组策略编辑器的问题

    今天在使用远程桌面连接服务器的时候发生了一些列的问题 首先是突然间出现了凭据不工作问题 但自己的用户名及密码都没有错误 最后查询发现需要修改在凭据管理中修改相应信息 呢么修改则需要在组策略编辑器中修改 但是呢win10家庭版又无法进入 以下
  • 【华为OD机试真题 python】最大数字【2023 Q1

    题目描述 最大数字 给定一个由纯数字组成以字符串表示的数值 现要求字符串中的每个数字最多只能出现2次 超过的需要进行删除 删除某个重复的数字后 其它数字相对位置保持不变 如 34533 数字3重复超过2次 需要删除其中一个3 删除第一个3后
  • idea读取数据库乱码,Navicat正常(解决)

    乱码问题困扰了我2天 菜的抠脚 先说说问题吧 你如果不想看这些废话就直接去下面解决 我先创建了数据库 拷贝了sql语句运行之后 Navicat正常显示 但是页面显示乱码 其实是中文latin1编码 debug跟进程序 发现在hibernat
  • msvcp140_1.dll丢失怎样修复?快速修复dll文件缺失

    msvcp140 1 dll丢失怎样修复 关于msvcp140 1 dll丢失 其实和其他dll文件的修复方法是一模一样的 你缺失了什么dll文件 那么你就在百度搜索这个dll文件 然后放到指定的文件夹就好了 解决起来还是非常的简单的 ms
  • Cocos Creator资源管理AssetManager细说一二

    关于AssetManager Asset Manager 是 Creator 在 v2 4 新推出的资源管理器 用于替代之前的 cc loader 新的 Asset Manager 资源管理模块具备加载资源 查找资源 销毁资源 缓存资源 A
  • VUE搭建项目,配置本地IP地址其他人可访问项目(整理)

    1 首先找到config文件夹目录下的 index js文件 Various Dev Server settings host localhost 将localhost进行替换成 0 0 0 0 host 0 0 0 0 can be ov
  • 如何使用USB接口对C51单片机下载固件

    使用USB转UART芯片对单片机下载固件时会遇到的问题 C51系列单片机在下载固件的时候需要断电重启 在使用RS232接口的时候不会遇到什么困难 因为RS232不需要进行识别 但是现在使用USB转UART的芯片时会遇到问题 因为USB设备在
  • CIFAR-10训练模型(ResNet18)

    1 搭建环境 环境在实验进行时已经搭建完毕 具体步骤就不过多赘述 参考 https blog csdn net weixin 39574469 article details 117454061 接下来只需导入所需的包即可 import n
  • python中列表数据汇总和平均值_如何从记录列表中计算平均值

    所以我正在做一个作业 当从一个数据列表中计算一个平均值 数据是从一个外部的 txt文件中读取的 时 我似乎遇到了麻烦 具体来说 我要做的是从下面的数据列表中读取数据记录 在1 2 2014 Frankton 42305 67 23 12 4
  • 高德地图API INVALID_USER_SCODE问题以及keystore问题

    转载地址 http m blog csdn net article details id 50448014 请尊重原创 今天这篇文章会给大家介绍三个问题 1 接入API时出现invalid user scode问题 首先进行第一个大问题 接
  • python连接数据库设置编码_python连接mysql数据库——编码问题

    编码问题 1 连接数据库语句 在利用pycharm连接本地的mysql数据库时 要考虑到的是将数据库语句填写完整 困扰了一下午的问题就是连接语句并没有加入编码设置 db pymysql connect host localhost user
  • 如何利用计算机打印较大的字,如何在一张A4纸上打印一个超大字?

    是不是很想打印超大字 要是硬件上去了 就什么话也不用说了 可惜的是 手中只有一个A4的打印机 怎么办 还是有办法的 用Microsoft Office 2003就可以 我由于学校工作的原因 打印机只能打A4的纸 有时又想打超大字 不得不用现
  • TensorFlow零基础入门,实现手写数字识别

    TensorFlow 是一个用于人工智能的开源神器 主要为深度学习算法提供了很多函数 以及独特的运算支持 废话不多说直接上干货 我的环境 python3 7 tensorflow 1 13 2 numpy 1 20 2 1 入门示例 imp
  • 算法分享三个方面学习方法(做题经验,代码编写经验,比赛经验)

    目录 0 前言 遇到OI不要慌 只要道路对了 就不怕遥远 1 做题经验谈 1 1 做题的目的 1 2 我对于算法比赛的题目的看法 1 2 1 类似题 1 2 2 套模型 1 3 在训练过程中如何做题 1 4 一些建议 提高算法能力 1 5
  • AJAX分页以及IFRAME载入

    AJAX获取数据并分页显示 ul class movList ul div div
  • leetcode-03. 数组中重复的数字刷题笔记(c++)

    写在前面 难度 简单 unordered map 或 sort排序 大数组方法异常溢出 数据量 小数据量 数组元素作为下标 大数据量 无需map映射 耗费空间 sort排序 前后元素是否等值 题目详情 找出数组中重复的数字 在一个长度为 n
  • 一条慢SQL引发的改造

    前言 闲鱼服务端在做数据库查询时 对每一条SQL都需要仔细优化 尽可能使延时更低 带给用户更好的体验 但是在生产中偶尔会有一些情况怎么优化都无法满足业务场景 本文通过对一条慢SQL的真实改造 介绍解决复杂查询的一种思路 以及如何使得一条平均
  • Seata 处理分布式事务

    文章目录 1 Seata 简介2 2 Seata的安装 2 1 修改配置文件 2 2 在nacos上创建配置文件 seataServer yaml 2 3 安装路径seata seata server 1 6 0 seata script
  • C# —— 面向对象编程练习

    C 面向对象编程练习 基础题 代码如下 class Program static void Main string args rectangle r new rectangle Console WriteLine 调用不含参构造函数初始化后