Home > Net >  For c # programming
For c # programming

Time:10-04

Help me, thank you very much o source code

CodePudding user response:

The meaning is not very clear?

CodePudding user response:

The class, inheritance, overloading these basic concepts to clear up the easy,

CodePudding user response:

The day before yesterday is not ask the same question? Is this a homework assignments yao and ask questions before you are classmates?

CodePudding user response:

Help you find the
https://bbs.csdn.net/topics/394347332#post-408779973

CodePudding user response:

 using System; 
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;

The namespace ConsoleApplication1
{
Class Program
{
The static void Main (string [] args)
{
Dictionary Score=new Dictionary (a);
Score. The Add (" language ", 90);
Score. The Add (" math ", 88);
Score. The Add (" English ", 78);
Score. The Add (" chemistry ", 84);
Score. The Add (" physics ", 94);

Student Student=new Student (" zhang ", 20, "male");
Student. Score=Score;
Console. WriteLine (" {0} 'average scores for {1} ", the student. The Name, student. AverageScore);
Console.ReadKey();
}
}

Public class Person
{
//name
Protected string name;
Public string Name
{
The get {return name; }
The set {name=value; }
}

//age
Protected int the age;
Public int the Age
{
The get {return the age; }
The set {age=value; }
}

///& lt; Summary>
///gender
///& lt;/summary>
Protected string sex;
Public string Sex
{
The get {return sex; }
The set {sex=value; }
}
}

Public class Student: Person
{
//transcript
Protected Dictionary Score;
Public Dictionary Score
{
The get {return score; }
The set {score=value; }
}

//average score
Public double AverageScore
{
The get
{
If (score==null | | score. Count==0)
{
Throw new Exception (" result can't be empty ");
}
The else
{
Double sum=0;
The foreach (KeyValuePair KVP in score)
{
The sum +=KVP. Value;
}
Return the sum/score. Count;
}
}
}

//the constructor a
Public Student (string name)
{
this.name=name;
}

//constructor.
Public Student (string name, int age)
{
this.name=name;
Enclosing the age=age;
}

//the constructor three
Public Student (string name, int the age, the string sex)
{
this.name=name;
Enclosing the age=age;
This. Sex=sex;
}
}


}

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
{
Public Student (string name)
{
This. Name=Name;
}

Public Student (string name, int the age, the string sex)
{
This. Name=Name;
Enclosing the Age=Age;
This. Sex=Sex;
}

Public Student (string name, int the age, the string sex, double Chinese, double Math, double English, double Physics, double Chemistry)
{
This. Name=Name;
Enclosing the Age=Age;
This. Sex=Sex;
Enclosing ChineseScore=Chinese;
Enclosing MathScore=Math;
Enclosing EnglishScore=English;
Enclosing PhysicsScore=Physics;
Enclosing ChemistryScore=Chemistry;
}
///& lt; Summary>
///the language score
///& lt;/summary>
Public double ChineseScore {get; The set; }
///& lt; Summary>
///math score
///& lt;/summary>
Public double MathScore {get; The set; }
///& lt; Summary>
///English score
///& lt;/summary>
Public double EnglishScore {get; The set; }
///& lt; Summary>
///physical score
///& lt;/summary>
Public double PhysicsScore {get; The set; }
///& lt; Summary>
///chemical fraction
///& lt;/summary>
Public double ChemistryScore {get; The set; }
///& lt; Summary>
///to get five score
///& lt;/summary>
///& lt; Returns>
Public double GetAvgScore ()
{
Return (EnglishScore MathScore ChineseScore + + + + ChemistryScore PhysicsScore)/5.0;
}
}

The static void Main (string [] args)
{
Student li=new Student (18, "bill", "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));
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related