프로그래밍/코드 정리

[C#] 성적 입력 프로그램

NIA1995 2021. 3. 25. 16:53
using System;
using System.Threading;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    struct ScoreData
    {
        int id;

        public int ID
        {
            get => id;
            set
            {
                id = value;
            }
        }

        int kor;
        int math;
        int eng;

        public ScoreData(int Id, int Kor = 0, int Math = 0, int Eng = 0)
        {
            id = Id;
            kor = Kor;
            math = Math;
            eng = Eng;
        }

        public void Print()
        {
            Console.WriteLine("ID : {0}, 국어 : {1}, 수학 : {2}, 영어 : {3} 입니다.", id, kor, math, eng);
        }
    }

    class ScoreSystem
    {
        public List<ScoreData> dataList = new List<ScoreData>();

        public ScoreSystem()
        {
            for(int i = 0; i < 3; ++i)
            {
                Console.WriteLine("{0} 번 째 데이터를 입력 받겠습니다. 먼저, ID, 국어, 수학, 영어 성적을 차례 대로 입력해 주세요.", i + 1);

                int tempID   = int.Parse(Console.ReadLine());
                int tempKor  = int.Parse(Console.ReadLine());
                int tempMath = int.Parse(Console.ReadLine());
                int tempEng  = int.Parse(Console.ReadLine());

                dataList.Add(new ScoreData(tempID, tempKor, tempMath, tempEng));
            }
        }

        public void PrintData(int Id)
        {
            for(int i = 0; i < dataList.Count(); ++i)
            {
                if(Id == dataList[i].ID)
                {
                    dataList[i].Print();
                }
            }
        }
    }



    class Program
    {
        static void Main(string[] args)
        {
            ScoreSystem system = new ScoreSystem();

            while(true)
            {
                Console.WriteLine("보고 싶은 학생의 ID를 입력하세요. 단, 0은 프로그램 종료");

                int inputData = int.Parse(Console.ReadLine());

                if(inputData == 0)
                {
                    break;
                }
                else
                {
                    system.PrintData(inputData);
                }
            }
        }
    }
}