C# 学生信息管理控制台应用程序设计 - 实现小学生、中学生、大学生信息管理
using System;/nusing System.Collections.Generic;/nusing System.Linq;/nusing System.Text;/n/nnamespace ConsoleApplication1/n{/n abstract class Student/n {/n protected string name;/n protected int age;/n public static int totalStudent = 0;//静态成员,记录学生总人数/n public Student(string name, int age)/n {/n this.name = name;/n this.age = age;/n totalStudent++;/n }/n public string Name/n {/n get { return this.name; }/n }/n public abstract string studentType/n {/n get;/n }/n public abstract double totalScore/n {/n get;/n }/n public abstract string GetInfo();/n }/n/n class Pupil : Student/n {/n protected double chinese, math;/n public Pupil(string name, int age, double chinese, double math) : base(name, age)/n {/n this.chinese = chinese;/n this.math = math;/n }/n public override string studentType/n {/n get { return 'pupil'; }/n }/n public override double totalScore/n {/n get { return (this.chinese + this.math) / 2.0; }/n }/n public override string GetInfo()/n {/n string info = string.Format('Total number of student:{0}, Name:{1}, {2}, Age is {3}, AvgScore:{4:F2};',/n Student.totalStudent, this.name, this.studentType, this.age, this.totalScore);/n return info;/n }/n }/n/n class Middle : Student/n {/n protected double chinese, math, english;/n public Middle(string name, int age, double chinese, double math, double english) : base(name, age)/n {/n this.chinese = chinese;/n this.math = math;/n this.english = english;/n }/n public override string studentType/n {/n get { return 'middle school student'; }/n }/n public override double totalScore/n {/n get { return (this.chinese + this.math + this.english) / 3.0; }/n }/n public override string GetInfo()/n {/n string info = string.Format('Total number of student:{0}, Name:{1}, {2}, Age is {3}, AvgScore:{4:F2};',/n Student.totalStudent, this.name, this.studentType, this.age, this.totalScore);/n return info;/n }/n }/n/n class College : Student/n {/n protected double requiredCredits, electiveCredits;/n public College(string name, int age, double requiredCredits, double electiveCredits) : base(name, age)/n {/n this.requiredCredits = requiredCredits;/n this.electiveCredits = electiveCredits;/n }/n public override string studentType/n {/n get { return 'college student'; }/n }/n public override double totalScore/n {/n get { return this.requiredCredits + this.electiveCredits; }/n }/n public override string GetInfo()/n {/n string info = string.Format('Total number of student:{0}, Name:{1}, {2}, Age is {3}, TotalCredits :{4:F2};',/n Student.totalStudent, this.name, this.studentType, this.age, this.totalScore);/n return info;/n }/n }/n/n class Program/n {/n static void Main(string[] args)/n {/n Student[] students = new Student[10];/n string[] input;/n int i = 0;/n while (true)/n {/n input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);/n if (input[0] == '0')/n break;/n int type = int.Parse(input[0]);/n if (type < 1 || type > 3 || input.Length < 4)/n continue;/n string name = input[1];/n int age = int.Parse(input[2]);/n if (type == 1)/n {/n double chinese = double.Parse(input[3]);/n double math = double.Parse(input[4]);/n students[i++] = new Pupil(name, age, chinese, math);/n }/n else if (type == 2)/n {/n double chinese = double.Parse(input[3]);/n double math = double.Parse(input[4]);/n double english = double.Parse(input[5]);/n students[i++] = new Middle(name, age, chinese, math, english);/n }/n else if (type == 3)/n {/n double requiredCredits = double.Parse(input[3]);/n double electiveCredits = double.Parse(input[4]);/n students[i++] = new College(name, age, requiredCredits, electiveCredits);/n }/n }/n for (int j = 0; j < i; j++)/n {/n Console.WriteLine(students[j].GetInfo());/n }/n }/n }/
原文地址: https://www.cveoy.top/t/topic/nYSZ 著作权归作者所有。请勿转载和采集!