c# 用C#编写出一个通用的人员类(Person),该类具有姓名(Name)、年龄(Age)、性别(Sex)等属性。然后对Person 类的继承得到一个学生类(Student),Student类能够存放5门课的成绩,并能求出平均成绩。最后在Main函数中对Student类的功能进行验证 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class Person { public string Name { get; set; } public int Age { get; set; } public string Sex { get; set; } } public class Student : Person { /// <summary> /// 语文分数 /// </summary> public int ChineseScore { get; set; } /// <summary> /// 数学分数 /// </summary> public int MathScore { get; set; } /// <summary> /// 英语分数 /// </summary> public int EnglishScore { get; set; } /// <summary> /// 物理分数 /// </summary> public int PhysicsScore { get; set; } /// <summary> /// 化学分数 /// </summary> public int ChemistryScore { get; set; } } static void Main(string[] args) { Student li = new Student(); li.Name = "李四"; li.Age = 18; li.Sex = "男"; li.ChineseScore = 91; li.MathScore = 85; li.EnglishScore = 48; li.PhysicsScore = 95; li.ChemistryScore = 85; Console.WriteLine(String.Format("学生姓名:{0},性别:{1},年龄:{2}",li.Name,li.Sex,li.Age)); Console.WriteLine(String.Format("语文成绩:{0},数学成绩:{1},英语成绩:{2},物理成绩:{3},化学成绩:{4}", li.ChineseScore, li.MathScore, li.EnglishScore, li.PhysicsScore, li.ChemistryScore)); double avgScore = (li.ChineseScore + li.MathScore + li.EnglishScore + li.PhysicsScore + li.ChemistryScore) / 5.0; Console.WriteLine(String.Format("学生姓名:{0},五科平均分:{1}", li.Name, avgScore)); Console.ReadKey(); } 太谢谢了,我刚刚自己也实现了一个。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace task4{ class Person { public Person(string name, string age, string sex) { this.Name = name; this.Age = age; this.Sex = sex; } public String Name { get; set; } public string Age { get; set; } public String Sex { get; set; } } class Student : Person { public Student(string name, string age, string sex) : base(name, age, sex) { Console.Write("{0}的语文成绩为:", Name); int str4 = int.Parse(Console.ReadLine()); Grade = str4; Console.Write("{0}的数学成绩为:", Name); int str = int.Parse(Console.ReadLine()); Grade1 = str; Console.Write("{0}的英语成绩为:", Name); int str1 = int.Parse(Console.ReadLine()); Grade2 = str1; Console.Write("{0}的物理成绩为:", Name); int str2 = int.Parse(Console.ReadLine()); Grade3 = str2; Console.Write("{0}的化学成绩为:", Name); int str3 = int.Parse(Console.ReadLine()); Grade4 = str3; } public int Grade { get; set; } public int Grade1 { get; set; } public int Grade2 { get; set; } public int Grade3 { get; set; } public int Grade4 { get; set; } public void Avg() { int sum = 0; int avg = 0; sum = Grade + Grade1 + Grade2 + Grade3 + Grade4; avg = sum / 5; Console.WriteLine("他的平均成绩为{0}", avg); } } class Program { static void Main(string[] args) { Console.Write("学生姓名:"); string Name = Console.ReadLine(); Console.Write("学生年龄:"); string Age = Console.ReadLine(); Console.Write("学生性别:"); string Sex = Console.ReadLine(); Student student1 = new Student(Name, Age, Sex); student1.Avg(); } }} 百度地图:悬浮标点之后如何变成另一个图 C#读取word 求个完整的C#连接Access数据库的ODBC字符串 泛型函数返回值怎么写? 生成解决方案发生错误,但是不能弹出出错窗口,该怎么办? CrystalReport 如何使文本可编辑 请问,大家,如何用c# 打开或关闭一个windows端口吗!....急呀,大侠!. 初学者关于线程的疑问 简单问题:winForm里dataGrid的列抬头怎么显示中文? 这样写错在那 c#添加CCD瞄准的的功能 c#winform自制一个数字输入键盘,文本如何传送?
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Sex { get; set; }
}
public class Student : Person
{
/// <summary>
/// 语文分数
/// </summary>
public int ChineseScore { get; set; }
/// <summary>
/// 数学分数
/// </summary>
public int MathScore { get; set; }
/// <summary>
/// 英语分数
/// </summary>
public int EnglishScore { get; set; }
/// <summary>
/// 物理分数
/// </summary>
public int PhysicsScore { get; set; }
/// <summary>
/// 化学分数
/// </summary>
public int ChemistryScore { get; set; }
} static void Main(string[] args)
{
Student li = new Student();
li.Name = "李四";
li.Age = 18;
li.Sex = "男";
li.ChineseScore = 91;
li.MathScore = 85;
li.EnglishScore = 48;
li.PhysicsScore = 95;
li.ChemistryScore = 85;
Console.WriteLine(String.Format("学生姓名:{0},性别:{1},年龄:{2}",li.Name,li.Sex,li.Age));
Console.WriteLine(String.Format("语文成绩:{0},数学成绩:{1},英语成绩:{2},物理成绩:{3},化学成绩:{4}", li.ChineseScore, li.MathScore, li.EnglishScore, li.PhysicsScore, li.ChemistryScore));
double avgScore = (li.ChineseScore + li.MathScore + li.EnglishScore + li.PhysicsScore + li.ChemistryScore) / 5.0;
Console.WriteLine(String.Format("学生姓名:{0},五科平均分:{1}", li.Name, avgScore));
Console.ReadKey();
}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace task4{ class Person { public Person(string name, string age, string sex) { this.Name = name; this.Age = age; this.Sex = sex; } public String Name { get; set; } public string Age { get; set; } public String Sex { get; set; } } class Student : Person { public Student(string name, string age, string sex) : base(name, age, sex) { Console.Write("{0}的语文成绩为:", Name); int str4 = int.Parse(Console.ReadLine()); Grade = str4; Console.Write("{0}的数学成绩为:", Name); int str = int.Parse(Console.ReadLine()); Grade1 = str; Console.Write("{0}的英语成绩为:", Name); int str1 = int.Parse(Console.ReadLine()); Grade2 = str1; Console.Write("{0}的物理成绩为:", Name); int str2 = int.Parse(Console.ReadLine()); Grade3 = str2; Console.Write("{0}的化学成绩为:", Name); int str3 = int.Parse(Console.ReadLine()); Grade4 = str3; } public int Grade { get; set; } public int Grade1 { get; set; } public int Grade2 { get; set; } public int Grade3 { get; set; } public int Grade4 { get; set; } public void Avg() { int sum = 0; int avg = 0; sum = Grade + Grade1 + Grade2 + Grade3 + Grade4; avg = sum / 5; Console.WriteLine("他的平均成绩为{0}", avg); } } class Program { static void Main(string[] args) { Console.Write("学生姓名:"); string Name = Console.ReadLine(); Console.Write("学生年龄:"); string Age = Console.ReadLine(); Console.Write("学生性别:"); string Sex = Console.ReadLine(); Student student1 = new Student(Name, Age, Sex); student1.Avg(); } }}