생성자, 속성 복습

정영훈·2022년 11월 30일
0

C#프로그래밍

목록 보기
27/29
class Student
{
    public static int count = 0;
    private int id;
    private string name;
    private int kor;
    private int eng;
    private int math;

    public int Id
    {
        get { return id; }
        set { id = value; }
    }
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    public int Kor
    {
        get { return kor; }
        set { kor = value; }
    }
    public int Eng
    {
        get { return eng; }
        set { eng = value; }
    }
    public int Math
    {
        get { return math; }
        set { math = value; }
    }
    //생성자
    public Student(string name, int kor, int eng, int math)
    {
        count++;
        id = count;
        this.name = name;
        this.kor = kor;
        this.eng = eng;
        this.math = math;
    }
    public int Sum()
    {
        return eng + math + kor;
    }
    public float Ave()
    {
        return (float)Sum() / 3;
    }
}



class Program
{
    static void Main(string[] args)
    {
        List<Student> students = new List<Student>();
        int n = int.Parse(Console.ReadLine());
        for(int i = 0; i < n; i++)
        {
            string[] tmp = Console.ReadLine().Split(' ');
            Student tmpStudent = new Student(tmp[0], int.Parse(tmp[1]), int.Parse(tmp[2]), int.Parse(tmp[3]));
            students.Add(tmpStudent);
        }
        //        Console.WriteLine(students.Count);
        for (int i = 0; i < students.Count; i++)
        {
            Console.WriteLine(students[i].Name);
        }
    }
} 
profile
경북소프트웨어고등학교 정보교사

0개의 댓글