Home > Net >  C #
C #

Time:10-04

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();
}

CodePudding user response:

Sure there are good people to do the homework

CodePudding user response:

refer to the second floor Dear200892 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();
}

Thank you very much, I just I also implemented a,
Using System; Using System. Collections. Generic; Using System. Linq; Using System. The Text; Using System. The Threading. The Tasks; The namespace task4 {class Person {public Person (string name, string age, string sex) {enclosing name=name; Enclosing the Age=Age; This. Sex=Sex; } public String Name {get; The set; } public string Age {get; The set; } public String Sex {get; The set; }} class Student: Person {public Student (string name, string age, string sex) : the base (name, age, sex) {Console. Write (" {0} language result is: ", name); Int str4=int. Parse (Console. ReadLine ()); Grade=str4; The Console. Write (" {0} math grades for: ", Name); Int STR=int. Parse (Console. ReadLine ()); Grade1=STR; The Console. Write (" {0} to record in English: ", Name); Int str1=int. Parse (Console. ReadLine ()); Grade2=str1; The Console. Write (" {0} physics result is: ", Name); Int str2=int. Parse (Console. ReadLine ()); Grade3=str2; The Console. Write (" chemical result is: {0} ", Name); Int str3=int. Parse (Console. ReadLine ()); Grade4=str3; } public int Grade {get; The set; } public int Grade1 {get; The set; } public int Grade2 {get; The set; } public int Grade3 {get; The set; } public int Grade4 {get; The set; } public void Avg () {int sum=0; Int avg=0; Sum=Grade + Grade1 + Grade2 + Grade3 + Grade4; Avg=sum/5; Console. WriteLine (" his average score for {0} ", avg); nullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#