With c # write a general class of people (Person), the class has a Name (Name), Age (Age), gender (Sex), and other attributes, and then the Person class have inherited a Student (Student), Student class can hold 5 course grades, and can calculate the average scores, finally in the Main function to validate the function of the Student class
CodePudding user response:
Not drop out of school
CodePudding user response:
Public class Person { Public string Name {get; The set; } Public int the Age {get; The set; } Public string Sex {get; The set; } } Public class Student: Person { ///& lt; Summary> ///the language score ///& lt;/summary> Public int ChineseScore {get; The set; } ///& lt; Summary> ///math score ///& lt;/summary> Public int MathScore {get; The set; } ///& lt; Summary> ///English score ///& lt;/summary> Public int EnglishScore {get; The set; } ///& lt; Summary> ///physical score ///& lt;/summary> Public int PhysicsScore {get; The set; } ///& lt; Summary> ///chemical fraction ///& lt;/summary> Public int ChemistryScore {get; The set; } }
The static void Main (string [] args) { Student li=new Student (); Li. The Name="bill"; Li. Age=18; Li. Sex="male"; Li. ChineseScore=91; Li. MathScore=85; Li. EnglishScore=48; Li. PhysicsScore=95; Li. ChemistryScore=85; Console. WriteLine (the String. Format (" gender: student's Name: {0}, {1}, Age: {2} ", li. The Name, li, Sex, li, Age)); Console. WriteLine (the String. Format (" language result: {0}, math: {1}, English achievement: {2}, physical performance: {3}, chemical grade: {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 (the String. Format (" student's Name: {0}, five average: {1} ", li. The Name, avgScore)); Console.ReadKey(); }