用C#创建2个类,使用继承,抽象类的特性做学生基本信息管理

1.学生基本信息管理

(1)使用控制台程序做界面

(2)至少10个属性和5个方法

(3)使用继承、抽象类等面向对象特性

(4)测试要求:测试程序中用到的面向对象特性。


<span style="font-size:32px;color:#ff0000;">主函数</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentBasic
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Father fa = new Father();
            Son so = new Son();
            so.show();
            so.inputsex();
            so.ageAnalysis();
            so.order();
            so.sum();
            Console.ReadLine();
        }
    }
}
<span style="font-size:32px;color:#ff0000;">Father类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentBasic
{
    public class Father
    {
        public string collage { get; set; }//大学的名称
        public string department { get; set; }//院系的名称
        public string grade { get; set; }//班级
        public string classroom { get; set; }//教室
        public string professional { get; set; }//专业
    }
}
<span style="font-size:32px;color:#ff0000;">儿子类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentBasic
{
    public class Son:Father
    {
        public string  sex { get; set; }//性别
        public string number { get; set; }//学号
        public string name { get; set; }//名字
        public int  age { get; set; }//年龄
        public double[] score;//分数
        public Son()
        {
            score = new double[5];
            Console.WriteLine("这学期的5门课程的成绩为:");
            score[0] = double.Parse(Console.ReadLine());
            score[1] = double.Parse(Console.ReadLine());
            score[2] = double.Parse(Console.ReadLine());
            score[3] = double.Parse(Console.ReadLine());
            score[4] = double.Parse(Console.ReadLine());
        }
        public void show() //第一个方法:显示
        {
            collage = "徐州工程学院";
            department = "信电工程学院";
            grade = "13计卓";
            classroom = "教一429";
            professional = "计算机科学与技术";
            name = "刘姗";
            Console.WriteLine(collage);
            Console.WriteLine(department);
            Console.WriteLine(grade);
            Console.WriteLine(classroom);
            Console.WriteLine(professional);
            Console.WriteLine(name);
        }
        public void inputsex()//第二个方法;输入性别
        {
            Console.WriteLine("                  ");
            for (int i = 0; ; i++)
            {
                Console.WriteLine("请输入您的性别:");
                sex = Console.ReadLine();
                string sex2="女";
                string sex3="男";
                if (0 != string.Compare(sex, sex2) && 0 != string.Compare(sex, sex3))
                {
                    Console.WriteLine("您输入的信息有误!!");
                    Console.WriteLine("请继续输入您的性别");
                }
                else { break; }
            }

        }
        public void ageAnalysis() //第三个方法:年龄的分析
        {
            Console.WriteLine("                  ");
            Console.WriteLine("请输入你的年龄:");
            age = int.Parse(Console.ReadLine());
            if (age > 16 && age < 19)
            {
                Console.WriteLine("小欧猜测您应该上大一吧(' 。‘)");
            }
            else
            {
                if (age > 19 && age < 21)
                { Console.WriteLine("小欧猜测您应该上大二吧(' 。‘)"); }
                else 
                {
                    if (age > 21 && age < 24)
                    { Console.WriteLine("小欧猜测您应该上大三吧(' 。‘)"); }
                    else { Console.WriteLine("小欧猜测您应该上大四吧(' 。‘)"); }
                }
            }
        }
        public void order() //第四个方法:由大到小选择排序
        {
            Console.WriteLine("                  ");
            double t;
            for (int i = 0; i < 4; i++)
            {
                for (int j = i + 1; j < 5; j++)
                {
                    if (score[i] < score[j])
                    { t = score[i]; score[i] = score[j]; score[j] = t; }
                }
            }
            Console.WriteLine("五门课的成绩从大到小排列为:");
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(score[i]);
            }
        }
        public void sum() //第五种方法:求五门课的总成绩
        {
            Console.WriteLine("                  ");
            double sum = score[0] + score[1] + score[2]
                + score[3] + score[4];
            Console.WriteLine("五门课的总成绩为:" + sum);
            
        }
    }
}




用C#创建2个类,使用继承,抽象类的特性做学生基本信息管理

上一篇:WPF中嵌入Office编辑器(支持Word、Excel、PPT、Visio等)


下一篇:git之.gitignore文件用途