By GokiSoft.com| 15:19 28/10/2021|
C Sharp

[Video] Bài tập - Quản lý điểm thi Aptech bằng C# - Lập trình C Sharp


Link Video Bai Giang

Bài tập - Quản lý điểm thi Aptech bằng C# - Lập trình C Sharp

#Program.cs


using System;
using System.Collections.Generic;

namespace BT2499
{
    delegate void SwitchCase();

    class Program
    {
        static void Main(string[] args)
        {
            SwitchCase[] options = { InputStudent, InputMark, DisplayStudent, DisplayMark, SortStudent, SearchStudent, ExitProgram };
            int choose;

            do
            {
                ShowMenu();
                choose = int.Parse(Console.ReadLine());

                if(choose > 0 && choose <= options.Length)
                {
                    options[choose - 1]();
                } else
                {
                    Console.WriteLine("Nhap sai!!!");
                }
            } while (choose != options.Length);
        }

        private static void DisplayMark()
        {
            List<StudentMark> markList = DataMgr.GetInstance().MarkList;

            Console.WriteLine("=== Danh sach diem thi");
            foreach(StudentMark mark in markList)
            {
                mark.Display();
            }
        }

        private static void DisplayStudent()
        {
            List<StudentAptech> studentList = DataMgr.GetInstance().StudentList;

            Console.WriteLine("=== Danh sach sinh vien");
            foreach(StudentAptech student in studentList)
            {
                student.Display();
            }
        }

        private static void InputStudent()
        {
            List<StudentAptech> studentList = DataMgr.GetInstance().StudentList;

            Console.WriteLine("Nhap so sinh vien can them: ");
            int N = int.Parse(Console.ReadLine());

            for(int i=0;i<N;i++)
            {
                StudentAptech student = new StudentAptech();
                student.Input();

                studentList.Add(student);
            }
        }

        private static void InputMark()
        {
            List<StudentMark> markList = DataMgr.GetInstance().MarkList;

            Console.WriteLine("Nhap so diem thi can them: ");
            int N = int.Parse(Console.ReadLine());

            for(int i=0;i<N;i++)
            {
                StudentMark mark = new StudentMark();
                mark.Input();

                markList.Add(mark);
            }
        }

        private static void SortStudent()
        {
            List<StudentAptech> studentList = DataMgr.GetInstance().StudentList;

            studentList.Sort((s1, s2) => {
                return s1.StuName.CompareTo(s2.StuName);
            });

            DisplayStudent();
        }

        private static void SearchStudent()
        {
            Console.WriteLine("Nhap msv can kiem tra: ");
            string studId = Console.ReadLine();

            bool isFind = false;

            List<StudentAptech> studentList = DataMgr.GetInstance().StudentList;
            List<StudentMark> markList = DataMgr.GetInstance().MarkList;

            foreach (StudentAptech student in studentList)
            {
                if(student.StuId == studId)
                {
                    isFind = true;

                    StudentMarkTotal markTotal = new StudentMarkTotal(studId);
                    markTotal.CalculateEverageMark(markList);

                    markTotal.Display();
                }
            }

            if(!isFind)
            {
                Console.WriteLine("Khong tim thay sinh vien vs msv = {0}", studId);
            }
        }

        private static void ExitProgram()
        {
            Console.WriteLine("Thoat chuong trinh!!!");
        }

        static void ShowMenu()
        {
            Console.WriteLine("1. Nhap N sinh vien");
            Console.WriteLine("2. Nhap N diem thi");
            Console.WriteLine("3. Hien thi thong tin sinh vien");
            Console.WriteLine("4. Hient thi diem thi");
            Console.WriteLine("5. Sap xep sinh vien theo ten");
            Console.WriteLine("6. Tim kiem ket qua hoc theo msv");
            Console.WriteLine("7. Thoat");
            Console.WriteLine("Chon: ");
        }
    }
}


#IMark.cs


using System;
namespace BT2499
{
    public interface IMark
    {
        void Input();
        void Display();
    }
}


#StudentAptech.cs


using System;
namespace BT2499
{
    public class StudentAptech : IMark
    {
        public String StuId { get; set; }

        public String StuName { get; set; }

        public String Gender { get; set; }

        public String Birthday { get; set; }

        public String NativePlace { get; set; }

        public StudentAptech()
        {
        }

        public StudentAptech(string stuId, string stuName, string gender, string birthday, string nativePlace)
        {
            StuId = stuId;
            StuName = stuName;
            Gender = gender;
            Birthday = birthday;
            NativePlace = nativePlace;
        }

        public void Display()
        {
            Console.WriteLine("MSV: {0}, ten: {1}, gioi tinh: {2}, ngay sinh: {3}, " +
                "que quan: {4}", StuId, StuName, Gender, Birthday, NativePlace);
        }

        public void Input()
        {
            Console.WriteLine("================================");
            Console.WriteLine("Nhap msv: ");
            StuId = Console.ReadLine();

            Console.WriteLine("Nhap ten sv: ");
            StuName = Console.ReadLine();

            Console.WriteLine("Nhap gioi tinh: ");
            Gender = Console.ReadLine();

            Console.WriteLine("Nhap ngay sinh: ");
            Birthday = Console.ReadLine();

            Console.WriteLine("Nhap que quan: ");
            NativePlace = Console.ReadLine();
        }
    }
}


#StudentMark.cs


using System;
using System.Collections.Generic;

namespace BT2499
{
    public class StudentMark : IMark
    {
        public String StuId { get; set; }

        public String ClassName { get; set; }

        public String SubjectName { get; set; }

        public int Semester { get; set; }

        public float Mark { get; set; }

        public StudentMark()
        {
        }

        public void Display()
        {
            Console.WriteLine("MSV: {0}, ten lop: {1}, mon hoc: {2}, ky hoc: {3}, " +
                "diem: {4}", StuId, ClassName, SubjectName, Semester, Mark);
        }

        public void Input()
        {
            List<StudentAptech> studentList = DataMgr.GetInstance().StudentList;
            if (studentList.Count == 0) return;

            Console.WriteLine("================================");
            Console.WriteLine("Nhap msv: ");

            bool isFind = false;
            while (!isFind)
            {
                StuId = Console.ReadLine();
                
                foreach(StudentAptech student in studentList)
                {
                    if(student.StuId == StuId)
                    {
                        isFind = true;
                        break;
                    }
                }
                if(!isFind)
                {
                    Console.WriteLine("Nhap lai!!!");
                }
            }

            Console.WriteLine("Nhap ten lop: ");
            ClassName = Console.ReadLine();

            Console.WriteLine("Nhap mon hoc: ");
            SubjectName = Console.ReadLine();

            Console.WriteLine("Nhap ky hoc: ");
            Semester = int.Parse(Console.ReadLine());

            Console.WriteLine("Nhap diem: ");
            Mark = float.Parse(Console.ReadLine());
        }
    }
}


#StudentMarkTotal.cs


using System;
using System.Collections.Generic;

namespace BT2499
{
    public class StudentMarkTotal : IMark
    {
        public String StuId;

        public int TotalExamSubject;

        public float EverageMark;

        public StudentMarkTotal()
        {
        }

        public StudentMarkTotal(string stuId)
        {
            StuId = stuId;
        }

        public void Display()
        {
            Console.WriteLine("MSV: {0}, tong mon hoc: {1}, diem trung binh: {2}",
                StuId, TotalExamSubject, EverageMark);
        }

        public void Input()
        {
            Console.WriteLine("Nhap msv: ");
            StuId = Console.ReadLine();
        }

        public void GetTotalExamSubject(List<StudentMark> markList)
        {
            TotalExamSubject = 0;
            foreach(StudentMark mark in markList)
            {
                if(mark.StuId == StuId)
                {
                    TotalExamSubject++;
                }
            }
        }

        public void CalculateEverageMark(List<StudentMark> markList)
        {
            TotalExamSubject = 0;
            float totalMark = 0;
            foreach (StudentMark mark in markList)
            {
                if (mark.StuId == StuId)
                {
                    TotalExamSubject++;
                    totalMark += mark.Mark;
                }
            }

            EverageMark = totalMark / TotalExamSubject;
        }
    }
}


#DataMgr.cs


using System;
using System.Collections.Generic;

namespace BT2499
{
    public class DataMgr
    {
        public List<StudentAptech> StudentList { get; set; }
        public List<StudentMark> MarkList { get; set; }

        private static DataMgr _instance = null;

        private DataMgr()
        {
            StudentList = new List<StudentAptech>();
            MarkList = new List<StudentMark>();
        }

        public static DataMgr GetInstance()
        {
            if(_instance == null)
            {
                _instance = new DataMgr();
            }
            return _instance;
        }
    }
}


Tags:

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)