IMG-LOGO
×

Giáo Trình Học

Khoá học lập trình C# (.NET Core)

Kiến Thức Căn Bản - Khai Báo Biến, Toán Tử, Mệnh Đề Điều Kiện, Lặp

[Video] Giới thiệu về ngôn ngữ lập trình C# & .NET Framework + Khai báo biến trong C# [Video] Hướng dẫn tìm hiểu biến + toán tử trong lập trình C# [Video] Hướng dẫn tìm hiểu mệnh đề điều kiện if - else - switch trong C# [Video] Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# [Video] In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C#




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

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

by GokiSoft.com - 19:58 21/10/2021 1,350 Lượt Xem

1.      Create interface IMark in package named aptech has two methods:

public void input()

public void display()

 

2.      Create a class named StudentAptech in package aptech implements interface IMark and adding follow attributes:

private String StuId;

private String StuName;

private String gender;

private String birthday;

private String nativePlace;

 

Create two constructors for this class.

Create method sets/gets for these attributes.

Override methods in the interface that it inherited.

 

3.      Create class named StudentMark in package aptech.mark implements interface IMark and adding follow attributes:

private String StuId;

private String className;

private String subjectName;

private int semester;

private float mark;

 

Create two constructors for this class.

Create method sets/gets for these attributes.

Override methods in the interface that it inherits.

 

4.      Create class named StudentMarkTotal in package aptech.mark inherits class IMark and adding follow attributes:

private String StuId;

private int totalExamSubject;

private float everageMark;

 

Create two constructors for this class.

Create method sets/gets for these attributes.

Override methods in the class that it inherited.

Construct adding method:

public void getTotalExamSubject(ArrayList<StudentMark> list);  //Tính tổng số môn thi

public void calculateEverageMark(ArrayList<StudentMark> list);  //Tính điểm trung bình các môn thi

   

5.      Create class Manager in package aptech.mark has follow menu:

1.      Input n information of Aptech’s student.

2.      Input m exam marks for these students

3.      Sort by Student’s name and display the list.

4.      Find information of exam marks by student’s id

5.      Exit

Note:

The list of n Students are declared from the StudentAptech class.

The list of n exam marks are declared from StudentMark class.

When you input exam mark for student, you must check the StuId is existed in the list of Student’s information.

Bình luận



Phản Hồi Bởi:

(1) Đào Mạnh Dũng [C2010L]

Chia sẻ từ lớp học

Đào Mạnh Dũng [C2010L]

Ngày viết: 21:25 22/10/2021


#IMark.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace _2499
{
    interface IMark
    {
        public void input();
        public void display();
    }
}


#Manager.cs


using lib;
using System;
using System.Collections.Generic;

namespace _2499
{
    internal class Manager
    {

        public static List<StudentAptech> studentApteches = new List<StudentAptech>();
        private static List<StudentMark> studentMarks = new List<StudentMark>();
        private static void Main(string[] args)
        {
            SwitchCase[] menu = { ShowMenu, InputStudentAptech, InputStudentMark, Sort, Find, Utility.Exist };
            Utility.Menu(menu);
        }

        private static void InputStudentAptech()
        {
            Console.WriteLine("nhap n ");
            int n = Utility.ReadInt();
            for (int i = 0; i < n; i++)
            {
                StudentAptech studentAptech = new StudentAptech();
                Console.WriteLine("=====================");
                studentAptech.input();
                studentApteches.Add(studentAptech);
            }
        }

        private static void InputStudentMark()
        {
            Console.WriteLine("nhap n ");
            int n = Utility.ReadInt();
            for (int i = 0; i < n; i++)
            {
                StudentMark studentMark = new StudentMark();
                Console.WriteLine("=====================");
                studentMark.input();
                studentMarks.Add(studentMark);
            }
        }

        private static void Sort()
        {
            studentApteches.Sort((s1, s2) => s1.StuName.CompareTo(s2.StuName));
            foreach (var item in studentApteches)
            {
                item.display();
            }
        }

        private static void Find()
        {
            Console.WriteLine("nhap StuId");
            string StuId = Console.ReadLine();
            foreach (var item in studentMarks)
            {
                if (item.StuId.Equals(StuId))
                {
                    Console.WriteLine("===========");
                    Console.WriteLine(item);
                }
            }
        }

        private static void ShowMenu()
        {
            Console.WriteLine("1.      Input n information of Aptech’s student.\n" +
            "\n" +
            "2.      Input m exam marks for these students\n" +
            "\n" +
            "3.      Sort by Student’s name and display the list.\n" +
            "\n" +
            "4.      Find information of exam marks by student’s id\n" +
            "\n" +
            "5.      Exit");
        }
    }
}


#StudentAptech.cs


using System;

namespace _2499
{
    internal 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;
            this.gender = gender;
            this.birthday = birthday;
            this.nativePlace = nativePlace;
        }

        public void display()
        {
            Console.WriteLine(this);
        }

        public void input()
        {
            Console.WriteLine("nhap StuId");
            StuId = Console.ReadLine();
            Console.WriteLine("nhap StuName");
            StuName = Console.ReadLine();
            Console.WriteLine("nhap gender");
            this.gender = Console.ReadLine();
            Console.WriteLine("nhap birthday");
            this.birthday = Console.ReadLine();
            Console.WriteLine("nhap nativePlace");
            this.nativePlace = Console.ReadLine();
        }

        public override string ToString()
        {
            return "StudentAptech{" + "StuId=" + StuId + ", StuName=" + StuName + ", gender=" + gender + ", birthday=" + birthday + ", nativePlace=" + nativePlace + '}';
        }
    }
}


#StudentMark.cs


using System;

namespace _2499
{
    internal class StudentMark : IMark
    {
        private string stuId;

        public string StuId
        {
            get
            {
                return stuId;
            }
            set
            {
                if (Manager.studentApteches.Exists(item => item.StuId.Equals(value)))
                {
                    stuId = value;
                }
                else
                {
                    while (true)
                    {
                        Console.WriteLine("StuId khong ton tai nhap lai");
                        string val = Console.ReadLine();
                        if (Manager.studentApteches.Exists(item => item.StuId.Equals(val)))
                        {
                            stuId = val;
                            return;
                        }
                    }
                }
            }
        }

        public string className { get; set; }

        public string subjectName { get; set; }

        public int semester { get; set; }

        public float mark { get; set; }

        public StudentMark()
        {
        }

        public StudentMark(string stuId, string className, string subjectName, int semester, float mark)
        {
            StuId = stuId;
            this.className = className;
            this.subjectName = subjectName;
            this.semester = semester;
            this.mark = mark;
        }

        public void display()
        {
            Console.WriteLine(this);
        }

        public void input()
        {
            Console.WriteLine("nhap StuId");
            StuId = Console.ReadLine();
            Console.WriteLine("nhap className");
            this.className = Console.ReadLine();
            Console.WriteLine("nhap subjectName");
            this.subjectName = Console.ReadLine();
            Console.WriteLine("nhap semester");
            this.semester = lib.Utility.ReadInt();
            Console.WriteLine("nhap mark");
            this.mark = lib.Utility.ReadFloat();
        }

        public override string ToString()
        {
            return "StudentMark{" + "StuId=" + StuId + ", className=" + className + ", subjectName=" + subjectName + ", semester=" + semester + ", mark=" + mark + '}';
        }
    }
}


#StudentMarkTotal.cs


using System;
using System.Collections.Generic;

namespace _2499
{
    internal class StudentMarkTotal : IMark
    {
        public string StuId { get; set; }

        public int totalExamSubject { get; set; }

        public float everageMark { get; set; }

        public StudentMarkTotal()
        {
        }

        public StudentMarkTotal(string stuId, int totalExamSubject, float everageMark)
        {
            StuId = stuId;
            this.totalExamSubject = totalExamSubject;
            this.everageMark = everageMark;
        }

        public void display()
        {
            Console.WriteLine(this);
        }

        public void input()
        {
            Console.WriteLine("nhap StuId");
            StuId = Console.ReadLine();
            Console.WriteLine("nhap totalExamSubject");
            this.totalExamSubject = lib.Utility.ReadInt();
            Console.WriteLine("nhap everageMark");
            this.everageMark = lib.Utility.ReadFloat();
        }

        public override string ToString()
        {
            return "StudentMarkTotal{" + "StuId=" + StuId + ", totalExamSubject=" + totalExamSubject + ", everageMark=" + everageMark + '}';
        }

        public void getTotalExamSubject(List<StudentMark> list)
        {
            Dictionary<string, bool> Subject = new Dictionary<string, bool>();
            foreach (var item in list)
            {
                if (!Subject.ContainsKey(item.subjectName))
                {
                    Subject.Add(item.subjectName, true);
                }
            }
            this.totalExamSubject = Subject.Count;
        }

        public void calculateEverageMark(List<StudentMark> list)
        {
            float everageMark = 0;
            foreach (var item in list)
            {
                everageMark += item.mark;
            }
            this.everageMark = everageMark / list.Count;
        }
    }
}


#Utility.cs


using Newtonsoft.Json;
using System;
using System.IO;

namespace lib
{
    internal delegate void SwitchCase();

    internal class Utility
    {
        public static void Menu(SwitchCase[] menu)
        {
            int choose;
            while (true)
            {
                menu[0]();
                choose = Utility.ReadInt();
                if (choose <= menu.Length)
                {
                    menu[choose]();
                }
                else Console.WriteLine("Dau vao khong hop le! ");
            }
        }

        public static void Exist()
        {
            Environment.Exit(0);
        }

        public static int ReadInt()
        {
            int integer;
            while (true)
            {
                try
                {
                    integer = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return integer;
        }

        public static float ReadFloat()
        {
            float _float;
            while (true)
            {
                try
                {
                    _float = float.Parse(System.Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return _float;
        }

        public static DateTime ReadDate()
        {
            DateTime date;
            while (true)
            {
                try
                {
                    date = ConvertDateTime(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return date;
        }

        public static string ConvertDateTime(DateTime myDate)
        {
            return myDate.ToString("dd-MM-yyyy");
        }

        public static DateTime ConvertDateTime(string str)
        {
            return DateTime.ParseExact(str, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
        }

        public static T ReadfileJson<T>(string path)
        {
            return JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
        }

        public static void SavefileJson(object obj, string path)
        {
            System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(obj));
            Console.WriteLine("save file json is success!");
        }

        public static void SaveObject(object serialize, string path)
        {
            using (Stream stream = File.Open(path, FileMode.Create))
            {
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(stream, serialize);
                Console.WriteLine("save file object is success!");
            }
        }

        public static object ReadObject(string path)
        {
            using (Stream stream = File.Open(path, FileMode.Open))
            {
                return new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Deserialize(stream);
            }
        }

        public static void directoryCreate(string path)
        {
            string directoryPath = path;

            DirectoryInfo directory = new DirectoryInfo(directoryPath);

            if (!directory.Exists)
            {
                directory.Create();
            }

            Console.WriteLine("Create directory {0} is success!", directory.Name);
        }
    }
}


Phân Loại Bài Viết

Tài Liệu Tham Khảo

Đã sao chép!!!