Learn

mail@pastecode.io avatar
unknown
csharp
a year ago
4.1 kB
6
Indexable
Never
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class MonHoc
    {
        public int MaMon { get; set; }
        public string TenMon { get; set; }
        public int SoTinChi { get; set; }
        public virtual void Nhap()
        {
            Console.WriteLine("Ma mon: "); MaMon = int.Parse(Console.ReadLine());
            Console.WriteLine("Ten mon: "); TenMon = Console.ReadLine();
            Console.WriteLine("So tin chi: "); SoTinChi = int.Parse(Console.ReadLine());
        }

    }
    class TinChi : MonHoc
    {
        public double DiemThanhPhan { get; set; }
        public double DiemThi { get; set; }    
        public double DiemTongKet()
        {
            return DiemThanhPhan * 0.3 + DiemThi * 0.7;
        }
        public override void Nhap()
        {
            base.Nhap();
            Console.WriteLine("Diem thanh phan: "); MaMon = int.Parse(Console.ReadLine());
            Console.WriteLine("Diem thi: "); MaMon = int.Parse(Console.ReadLine());
        }

    }
    class SinhVien
    {
        public int MaSinhVien { get; set; }
        public string TenSinhVien { get; set; }
        public int SoTinChi {
            get
            {
                return SoTinChi;
            }
            set
            {
                if(SoTinChi!= value )
                {
                    SoTinChi = value;
                    ThongTinTinChi = new TinChi[value];
                }
            }
        }
        public TinChi[] ThongTinTinChi;
        public double TongKet()
        {
            double result = 0;
            foreach (var item in ThongTinTinChi)
            {
                result += item.DiemTongKet();
            }
            return result / SoTinChi;
        }
        public void HienThi()
        {
            Console.WriteLine($"{MaSinhVien} - {TenSinhVien}");
        }
        public void Nhap()
        {
            Console.WriteLine("Ma Sinh Vien: ");
            MaSinhVien = int.Parse(Console.ReadLine());
            Console.WriteLine("Ten sinh vien: ");
            TenSinhVien = Console.ReadLine();
            Console.WriteLine("So tin chi: ");
            SoTinChi = int.Parse(Console.ReadLine());
            Console.WriteLine("Danh sach tin chi: ");
            for(int i = 0; i < SoTinChi;++i)
            {
                ThongTinTinChi[i] = new TinChi();
                ThongTinTinChi[i].Nhap();
            }

        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            //Console.InputEncoding = Encoding.Unicode;
            //Console.OutputEncoding = Encoding.Unicode;
            //Cau2(123);

            Console.Write("So sinh vien: ");
            int n = int.Parse(Console.ReadLine());
            SinhVien[] DSSV = new SinhVien[n];
            for(int i =0;i < n; ++i)
            {
                Console.WriteLine("Nhap thong tin sinh vien: ");
                DSSV[i] = new SinhVien();

            }


            Console.WriteLine("Danh sach sinh vien: ");
            for (int i = 0; i < n; ++i)
            {
                DSSV[i].HienThi();
            }

            Console.ReadLine();
        }
        static void Cau2(long n)
        {
            int size = (int)Math.Log10(n) + 1;
            int count = 0;
            long[] x = new long[size];
            while(n > 0)
            {
                x[count] = n % 10;
                n /= 10;
                count++;
            }
            string[] text = {"","mươi","trăm","nghìn","mươi","trăm","triệu","mươi","trăm","tỷ" };
            string[] words = { "không", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín" };
            for(int i = count - 1; i >= 0; i--)
            {
                Console.Write("{0} {1} ", words[x[i]], text[i]);
            }
        }
    }
}