C#源代码—姓名 请输入老师的编号、姓名、职称和部门

时间:2022-08-23 08:36:42
静态成员  性别姓名 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _3._3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public enum Gender { 男, 女 };
        public class person
        {
            private static int males;
            private static int females;
            public string name;
            public Gender sex;
            public int age;
            public person(string name, Gender sex, int age)
            {
                this.name = name;
                this.sex = sex;
                this.age = age;
                if (sex == Gender.男)
                    males++;
                if (sex == Gender.女)
                    females++;
            }
            public static int Numbermales()
            {
                return males;
            }
            public static int Numberfemales()
            {
                return females;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            person[] ps = new person[5];
            string result="";
            ps[0] = new person("张伟", Gender.男, 20);
            ps[1] = new person("李静", Gender.女, 21);
            ps[2] = new person("黄薇", Gender.女, 19);
            ps[3] = new person("赵恒", Gender.男, 22);
            ps[4] = new person("钱沿", Gender.男, 20);


            label3.Text = Convert.ToString(person.Numbermales());
            label4.Text = Convert.ToString(person.Numberfemales());
            foreach (person p in ps)
            {
                result =result+"  "+ p.name;
               
            }
           
                label5.Text=result;
                     
        }
       
    }
}


姓名 请输入老师的编号、姓名、职称和部门
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace _1
{
    public class person
    {
        public int cno;
        public string name;
        public person() { }
        public void getxy() 
        {
           cno=Convert.ToInt32(Console.ReadLine());
           name = Console.ReadLine();
        }
        public void display()
        {
            Console.WriteLine("编号:{0},姓名:{1}",cno,name);
        }
    }
    public class student: person
    {
        public string banji;
        public int grade;
        public student(){ }      
        public void getxy()
        {
            Console.WriteLine("请输入学生的编号、姓名、班级和成绩:");
            cno = Convert.ToInt32(Console.ReadLine());
            name = Console.ReadLine();
            banji = Console.ReadLine();
            grade = Convert.ToInt32(Console.ReadLine());
        }
        public void display()
        {
            Console.WriteLine("编号:{0},姓名:{1},班级:{2},成绩:{3}", cno, name,banji,grade);
        }
    }
    public class teacher : person
    {
        public string zhicheng;
        public string bumen;
        public teacher() { }
        public void getxy()
        {
            Console.WriteLine("请输入老师的编号、姓名、职称和部门:");
            cno = Convert.ToInt32(Console.ReadLine());
            name = Console.ReadLine();
            zhicheng = Console.ReadLine();
            bumen = Console.ReadLine();
 
        }
        public void display()
        {
            Console.WriteLine("编号:{0},姓名:{1},职称:{2},部门:{3}", cno, name, zhicheng, bumen);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            student s1 = new student();
            teacher t1 = new teacher();
            s1.getxy();
            t1.getxy();
            s1.display();
            t1.display();
        }
    }
}