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

Chương trình nhập xuất dữ liệu điểm thi - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP BT1433

Cài đặt lớp StudentMark gồm các thông tin:

-       Rollnumber (Độ dài là 6-12)

-       Họ tên

-       Lớp

-       Môn

-       Điểm (Điều kiện >=0 và <= 10)

 

Cài đặt đầy đủ: 2 constructor, các phương thức set/get.

Cài đặt hàm nhập, hiển thị.

Khai báo luôn hàm main trong lớp này:

Khai báo 2 đối tượng của lớp, khởi tạo 2 đối tượng bằng construcor không có tham số. Gọi hàm nhập để nhập vào các thông tin và hàm hiển thị để hiển thị các thông tin.

Hiển thị thông tin của người có điểm cao nhất.

Liên kết rút gọn:

https://gokisoft.com/1433

Bình luận

avatar
Đào Mạnh Dũng [C2010L]
2021-10-15 12:34:52


#StudentMark.cs


using System;

namespace _1433
{
    internal class StudentMark
    {
        private string rollnumber, fullName, classRoom, subject;
        private float point;

        public string Rollnumber
        {
            get
            {
                return rollnumber;
            }
            set
            {
                if (value.Length <= 12 && value.Length >= 6)
                {
                    rollnumber = value;
                }
                else
                {
                    string val;
                    while (true)
                    {
                        Console.WriteLine("Dau vao khong hop le! nhap lai... ");
                        val = Console.ReadLine();
                        if (value.Length <= 12 && value.Length >= 6)
                        {
                            rollnumber = value;
                            return;
                        }
                    }
                }
            }
        }

        public string FullName
        {
            get
            {
                return fullName;
            }
            set
            {
                this.fullName = value;
            }
        }

        public string ClassRoom
        {
            get
            {
                return classRoom;
            }
            set
            {
                classRoom = value;
            }
        }

        public string Subject
        {
            get
            {
                return subject;
            }
            set
            {
                subject = value;
            }
        }

        public float Point
        {
            get
            {
                return point;
            }
            set
            {
                if (value <= 10 && value >= 0)
                {
                    point = value;
                }
                else
                {
                    int val;
                    while (true)
                    {
                        Console.WriteLine("Dau vao khong hop le! nhap lai... ");
                        val = lib.Utility.ReadInt();
                        if (value <= 10 && value >= 0)
                        {
                            point = value;
                            return;
                        }
                    }
                }
            }
        }

        public StudentMark()

        {
        }

        public StudentMark(string rollnumber, string fullName, string classRoom, string subject, int point)
        {
            this.rollnumber = rollnumber;
            this.fullName = fullName;
            this.classRoom = classRoom;
            this.subject = subject;
            this.point = point;
        }

        public void input()
        {
            System.Console.Write("nhap rollnumber : ");
            this.rollnumber = System.Console.ReadLine();
            System.Console.Write("nhap fullName : ");
            this.fullName = System.Console.ReadLine();
            System.Console.Write("nhap classRoom : ");
            this.classRoom = System.Console.ReadLine();
            System.Console.Write("nhap subject : ");
            this.subject = System.Console.ReadLine();
            System.Console.Write("nhap point : ");
            this.point = lib.Utility.ReadInt();
        }

        public void Display()
        {
            System.Console.WriteLine(this);
        }

        public override string ToString()
        {
            return "StudentMark{" + "rollnumber=" + rollnumber + ", fullName=" + fullName + ", classRoom=" + classRoom + ", subject=" + subject + ", point=" + point + '}';
        }

        private static void Main(string[] args)
        {
            StudentMark studentMark1 = new StudentMark();
            StudentMark studentMark2 = new StudentMark();
            studentMark1.input();
            studentMark2.input();
            if (studentMark1.point >= studentMark2.point)
            {
                studentMark1.Display();
            }
            else
            {
                studentMark2.Display();
            }
        }
    }
}


#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 int ReadInt()
        {
            int integer = 0;
            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 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);
            }
        }
    }
}


avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-10-01 08:21:24


#StudentMark.cs


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

namespace StudentMarkManager.Class
{

    class StudentMark
    {
        private string rollNumber;
        public string RollNumber
        {
            get { return rollNumber; }
            set
            {
                //Regex num = new Regex(@"(\d*");
                //RegexOptions.Compiled | RegexOptions.IgnoreCase);

                while (value.Length < 6 || value.Length > 12 || string.IsNullOrWhiteSpace(value) ||
                    !Regex.Match(value, "^[0-9]*$").Success)
                {
                    if (value.Length > 12)
                    {
                        Console.WriteLine("RollNumber exceeds 12 character");
                    }
                    else if (value.Length < 6)
                    {
                        Console.WriteLine("RollNumber below 6 character");
                    } else if (string.IsNullOrWhiteSpace(value))
                    {
                        Console.WriteLine("Don't prank with white spaces");
                    } else if (!Regex.Match(value, "^[0-9]*$").Success)
                    {
                        Console.WriteLine("Roll Number is not complete digits");
                    }
                    string str = Console.ReadLine();
                    value = str.Trim(' ');
                }
                this.rollNumber = value;
            }
        }
        public string Name { get; set; }
        public string Class { get; set; }
        public string Subject { get; set; }
        private float grade;
        public float Grade
        {
            get { return grade; }
            set
            {
                this.grade = value;
            }
        }
        public StudentMark()
        {

        }
        public StudentMark(string RollNumber, string Name, string Class, string Subject, float Grade)
        {
            this.RollNumber = RollNumber;
            this.Name = Name;
            this.Class = Class;
            this.Subject = Subject;
            this.Grade = Grade;
        }

        public void input()
        {
            Console.WriteLine("Enter Roll Number:");
            RollNumber = Console.ReadLine();
            Console.WriteLine("Enter Name:");
            Name = Console.ReadLine();
            Console.WriteLine("Enter Class:");
            Class = Console.ReadLine();
            Console.WriteLine("Enter Subject:");
            Subject = Console.ReadLine();
            Console.WriteLine("Enter Grade:");
            Grade = validGrade(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine("\nRoll Number: {0}\nName: {1}\nClass: {2}\nSubject: {3}\nGrade: {4}", RollNumber, Name, Class, Subject, Grade);
        }
        bool check(string str)
        {
            try { float.Parse(str); } catch (Exception) { return false; }
            return true;
        }

        public float validGrade(string str)
        {
            str.Trim(' ');
            check(str);
            while (!check(str) || float.Parse(str) > 10 || float.Parse(str) < 0)
            {
                if (!check(str))
                {
                    Console.WriteLine("Grade is not a valid numeric input");
                }
                else if (float.Parse(str) > 10 || float.Parse(str) < 0)
                {
                    Console.WriteLine("Grade must be between 0 and 10.");
                } 
                str = Console.ReadLine();
            }
            
            return float.Parse(str);
        }

        static void Main(string[] args)
        {
            StudentMark sm = new StudentMark();
            sm.input();
            sm.display();
        }
    }
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-09-30 10:21:05


#Program.cs


using System;

namespace Ss5
{
    class Program
    {
        static void Main(string[] args)
        {
            StudentMark s = new StudentMark();
            s.input();
            s.display();
        }
    }
}


#StudentMark.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss5
{
    class StudentMark
    {
        private string rollnumber;
        public string RollNumBer
        {
            get
            {
                return this.rollnumber;
            }
            set
            {
                while (value.Length < 6 || value.Length > 12)
                {
                    Console.WriteLine("RollNumBer must be length from 6 to 12");
                    Console.WriteLine("Enter RollNumBer again :");
                    value = Console.ReadLine();
                }
                this.rollnumber = value;
            }
        }
        public string FullName { get; set; }
        public string Class { get; set; }
        public string Subject { get; set; }
        private int grade;
        public int Grade
        {
            get
            {
                return this.grade;
            }
            set
            {
                while (value < 0 || value > 10)
                {
                    Console.WriteLine("Grade must be >= 0 and <= 10");
                    Console.WriteLine("Enter Grade Again:");
                    value = int.Parse(Console.ReadLine());
                }
                this.grade = value;
            }
        }
        public StudentMark()
        {

        }
        public StudentMark(string rollnumber, string fullname, string classs, string subject, int grade)
        {
            this.RollNumBer = rollnumber;
            this.FullName = fullname;
            this.Class = classs;
            this.Subject = subject;
            this.Grade = grade;
        }
        public void input()
        {
            Console.WriteLine("Enter RollNumBer :");
            RollNumBer = Console.ReadLine();
            RollNumBer = RollNumBer.Trim();

            Console.WriteLine("Enter FullName :");
            FullName = Console.ReadLine();
            FullName = validFullName(FullName);

            Console.WriteLine("Enter Class :");
            Class = Console.ReadLine();
            Class = validClass(Class);

            Console.WriteLine("Enter Subject :");
            Subject = Console.ReadLine();
            Subject = validSubject(Subject);

            Console.WriteLine("Enter Grade :");
            string grade = Console.ReadLine();
            Grade = validGrade(grade);

        }
        public void display()
        {
            Console.WriteLine("RollNumBer :{0}, FullName :{1}, Class :{2}, Subject :{3}, Grade :{4}", RollNumBer, FullName, Class, Subject, Grade);
        }
        static bool IsNumeric(string value)
        {
            try
            {
                int number;
                int.Parse(value);
            }

            catch (Exception ex) { return false; }
            return true;
        }
        public string validFullName(string FullName)
        {
            while (string.IsNullOrWhiteSpace(FullName))
            {
                Console.WriteLine("FullName cannot empty ");
                Console.WriteLine("Enter FullName Again :");
                FullName = Console.ReadLine();

            }
            FullName = FullName.Trim();
            return FullName;
        }
        public string validClass(string Class)
        {
            while (string.IsNullOrWhiteSpace(Class))
            {
                Console.WriteLine("Class cannot empty ");
                Console.WriteLine("Enter Class Again :");
                Class = Console.ReadLine();
            }
            Class = Class.Trim();
            return Class;
        }
        public string validSubject(string Subject)
        {
            while (string.IsNullOrWhiteSpace(Subject))
            {
                Console.WriteLine("Subject cannot empty ");
                Console.WriteLine("Enter Subject Again :");
                Subject = Console.ReadLine();
            }
            Subject = Subject.Trim();
            return Subject;
        }
        public int validGrade(string grade)
        {
            int Grade;
            while (string.IsNullOrWhiteSpace(grade) || !IsNumeric(grade))
            {
                if (string.IsNullOrWhiteSpace(grade))
                {
                    Console.WriteLine("Grade cannot empty ");
                    Console.WriteLine("Enter Grade Again :");
                }
                else if (!IsNumeric(grade))
                {
                    Console.WriteLine("Grade must be number ");
                    Console.WriteLine("Enter Grade Again :");
                }
                grade = Console.ReadLine();

            }
            grade = grade.Trim();
            Grade = int.Parse(grade);
            return Grade;
        }
    }

}


avatar
Nguyễn Tiến Đạt [T2008A]
2021-05-18 15:59:00


#StudentMark.cs


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

namespace StudentMarkHomeWork.studentMark
{
    class StudentMark
    {
        private string rollNo;
        public string RollNo
        {
            get{
                return rollNo;
            }
            set
            {
                if(value.Length < 6 && value.Length > 12)
                {
                    Console.WriteLine("Khong hop le!!");
                }
                else
                {
                    rollNo = value;
                }
            }
        }
        string name, Class, subject;
        private float mark;
        public float Mark
        {
            get
            {
                return mark;
            }
            set
            {
                if (value < 0 && value > 10)
                {
                    Console.WriteLine("Khong hop le!!");
                }
                else
                {
                    mark = value;
                }
            }
        }
        public StudentMark()
        {

        }
        public StudentMark(string rollNo, string name, string Class, string subject, float mark)
        {
           if(rollNo.Length < 6 || rollNo.Length > 12)
            {
                Console.WriteLine("Khong hop le!!");
            }
            else
            {
                this.rollNo = rollNo;
            }
            this.name = name;
            this.Class = Class;
            this.subject = subject;
            if(mark < 0 || mark > 10)
            {
                Console.WriteLine("Khong hop le!!");
            }
            else
            {
                this.mark = mark;
            }
        }
        public void input()
        {
            Console.WriteLine("Nhap ma sinh vien:");
            while (true)
            {
                rollNo = Console.ReadLine();
                if (rollNo.Length < 6 || rollNo.Length > 12)
                {
                    Console.WriteLine("Khong hop le!!");
                }
                else break;
            }
            Console.WriteLine("Nhap ten sinh vien:");
            name = Console.ReadLine();
            Console.WriteLine("Nhap ten lop:");
            Class = Console.ReadLine();
            Console.WriteLine("Nhap diem thi:");
            while (true)
            {
                mark = float.Parse(Console.ReadLine());
                if (mark < 0 || mark > 10)
                {
                    Console.WriteLine("Khong hop le!!");
                }
                else break;
            }
        }
        public void display()
        {
            Console.WriteLine("Ma sinh vien: {0}", rollNo);
            Console.WriteLine("Ten sinh vien: {0}", name);
            Console.WriteLine("Ten lop: {0}", Class);
            Console.WriteLine("Diem thi: {0}", mark);
        }
    }
}


#Test.cs


using System;
using StudentMarkHomeWork.studentMark;

namespace StudentMarkHomeWork.test
{
    class Test
    {
        static void Main(string[] args)
        {
            StudentMark std1 = new StudentMark();
            StudentMark std2 = new StudentMark();
            std1.input();
            std2.input();
            std1.display();
            std2.display();
            Console.WriteLine("Thi sinh co diem cao nhat la:");
            if(std1.Mark > std2.Mark)
            {
                std1.display();
            }
            else
            {
                std2.display();
            }
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-05-18 04:47:55



using System;
using System.Collections.Generic;

namespace Lesson2.StudentMark
{
    class Student
    {
        public string Roolno { get; set; }
        public string Name { get; set; }
        public string Class { get; set; }

        public string Subject { get; set; }
       private int _Mark;
        public int Mark
        {
            get
            {
                return _Mark;
            }
            set
            {
                if(value<0 || value > 10)
                {
                    Console.WriteLine("Nhap diem thi sai");
                }
                else
                {
                    _Mark = value;
                }
            }
        }

        public void Input()
        {
            Console.WriteLine("Nhap ma hoc sinh:");
            Roolno = Console.ReadLine();
            Console.WriteLine("Nhap ten hoc sinh:");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap lop hoc sinh:");
            Class = Console.ReadLine();
            Console.WriteLine("Nhap mon hoc:");
            Subject = Console.ReadLine();
            Console.WriteLine("Nhap diem mon hoc:");
            Mark = Int32.Parse(Console.ReadLine());

        }
        public void Display()
        {
            Console.WriteLine("Ma: {0}, Ten: {1}, Lop: {2}, Mon hoc: {3}, Diem: {4} ", Roolno, Name, Class, Subject, Mark);
        }

        static void Main(string[] args)
        {
            List<Student> StudenList = new List<Student>();
            Console.WriteLine("Nhap so luong hoc sinh can them");
            int N = Int32.Parse(Console.ReadLine());

            int MaxIndex = 0;
            int MaxMark = 0;
            for(int i = 0; i < N; i++)
            {
                Student student = new Student();
                student.Input();
                StudenList.Add(student);

                if(StudenList[i].Mark >= MaxMark)
                {
                    MaxIndex = i;
                }
            }

            Console.WriteLine("Thong tin hoc sinh co diem cao nhat nhu sau:");
            StudenList[MaxIndex].Display();
        }
    }
}


avatar
vuong huu phu [T2008A]
2021-05-18 02:49:56



using System;

namespace diemthi
{
    class Program
    {
        static void Main(string[] args)
        {
            StudentMark std1 = new StudentMark();
            std1.Nhap();
            StudentMark std2 = new StudentMark();
            std2.Nhap();
            std1.hienthi();
            std2.hienthi();
            if (std1.diem > std2.diem)
            {
                Console.WriteLine("Sinh vien co diem lon nhat la");
                std1.hienthi();
            }
            else if (std1.diem < std2.diem)
            {
                Console.WriteLine("Sinh vien co diem lon nhat la");
                std2.hienthi();
            }
            else {
                Console.WriteLine(" 2 sinh vien co diem bang nhau: ");
                std1.hienthi();
                std2.hienthi();
            }
        }
    }
}



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

namespace diemthi
{
    public class StudentMark
    {
        public String rollnumber;
        public String ten;
        public String lop;
        public String mon;
        public float diem;

        public StudentMark() { }
        public StudentMark(String rollnumber, String ten, String lop, String mon, float diem)
        {
            this.rollnumber = rollnumber;
            this.ten = ten;
            this.lop = lop;
            this.mon = mon;
            this.diem = diem;
        }
        public String Rollnumber { get; set; }
        public String Ten { get; set; }
        public String Lop { get; set; }
        public String Mon { get; set; }
        public float Diem { get; set; }

        public void Nhap()
        {
            Console.WriteLine("Nhap ma sinh vien: ");
            rollnumber = Console.ReadLine();
            if (rollnumber.Length > 12) { 
                Console.WriteLine(rollnumber.Length);
                    Console.WriteLine("Nhap lai ma sinh vien it hon 12 ki tu");
                    rollnumber = Console.ReadLine();
            }
            else { 
            Console.WriteLine("Nhap ten sinh vien: ");
            ten = Console.ReadLine();
            Console.WriteLine("Nhap lop ");
            lop = Console.ReadLine();
            Console.WriteLine("Nhap mon");
            mon = Console.ReadLine();
            Console.WriteLine("Nhap diem");
            diem = float.Parse(Console.ReadLine());
            if ( diem > 10){
                    Console.WriteLine("Nhap lai diem thi tu (0 -> 10)");
                    diem = Int32.Parse(Console.ReadLine());
            }}
        }
        public void hienthi(){
            Console.WriteLine(rollnumber + " , " + ten + " , " + lop + " , " + mon + " , " + diem + " : ");
        }
    }
}


avatar
Triệu Văn Lăng [T2008A]
2021-05-18 01:27:25



using System;

namespace bai1433
{
    class StudentMark
    {
        public string Rollnumber { get; set; }
        public string fullname { get; set; }
        public string classname { get; set; }
        public string subject { get; set; }
        private int _mark;
        public int mark
        {
            //private get
            get
            {
                return _mark;
            }

            //private set
            set
            {
                if (value <= 0 && value >= 10)
                {
                    Console.WriteLine("Diem phai tu 1 den 10");
                }
                else
                {
                    _mark = value;
                }
            }
        }

        public StudentMark()
        {

        }

        public StudentMark(string Rollnumber, string fullname, string classname, string subject, int mark)
        {
            this.Rollnumber = Rollnumber;
            this.fullname = fullname;
            this.classname = classname;
            this.subject = subject;
            this.mark = mark;
        }

        public void input()
        {
            Console.WriteLine("Nhap rollnumber: ");
            Rollnumber = Console.ReadLine();

            Console.WriteLine("Nhap fullname: ");
            fullname = Console.ReadLine();

            Console.WriteLine("Nhap classname: ");
            classname = Console.ReadLine();

            Console.WriteLine("Nhap subject: ");
            subject = Console.ReadLine();

            Console.WriteLine("Nhap mark: ");
            mark = Convert.ToInt32(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine("Rollnumber: " + Rollnumber);
            Console.WriteLine("fullname: " + fullname);
            Console.WriteLine("classname: " + classname);
            Console.WriteLine("subject: " + subject);
            Console.WriteLine("mark: " + mark);

        }


        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            StudentMark stdm1 = new StudentMark();
            StudentMark stdm2 = new StudentMark();

            Console.WriteLine("Nhap thong tin sinh vien thu 1: ");
            stdm1.input();

            Console.WriteLine("Nhap thong tin sinh vien thu 2: ");
            stdm2.input();

            Console.WriteLine("Thong tin sinh vien thu 1: ");
            stdm1.display();

            Console.WriteLine("Thong tin sinh vien thu 2: ");
            stdm2.display();

            Console.WriteLine("Sinh vien co diem cao hon la: ");
            if(stdm1.mark > stdm2.mark)
            {
                stdm1.display();
            } else
            {
                stdm2.display();
            }

        }

    }
    
}


avatar
Nguyễn đình quân [T2008A]
2021-05-17 09:20:19



using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;

namespace StudentMark
{
    class Program
    {
        static void Main(string[] args)
        {
            Diemthi t = new Diemthi();
            t.input();
            t.display();
            Diemthi t1 = new Diemthi("8", "nguyendinhquan", "T2008A", "laptrinhC#", 9);
            Console.WriteLine("Nguoi co diem cao nhat");
            if(t.Score > t1.Score)
            {
                t.display();
                return;
            }
            if(t.Score == t1.Score)
            {
                t1.display();
                t.display();
                return;
            }
            t1.display();
            
        }
    }
}



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

namespace StudentMark
{
    class Diemthi
    {
        public string RollNumber { get; set; }
        public string FullName { get; set; }
        public string NameClass { get; set; }
        public string NameSubjects { get; set; }

        public int Score { get; set; }

        public Diemthi() { }
        public Diemthi(string rollnumber,string fullname,string nameClass,string nameSubjects,int score)
        {
            RollNumber = rollnumber;
            FullName = fullname;
            NameClass = nameClass;
            NameSubjects = nameSubjects;
            Score = score;
        }
        public void display()
        {
            Console.WriteLine("Rollnumber = {0}, Fullname = {1}, NameClass= {2}, NameSubject = {3}, Score ={4}",
                RollNumber,FullName,NameClass,NameSubjects,Score);    
        }
        public void input()
        {

            checkRoll();
            Console.WriteLine("nhap fullname");
            FullName = Console.ReadLine();
            Console.WriteLine("nhap nameClass");
            NameClass = Console.ReadLine();
            Console.WriteLine("nhap nameSubject");
            NameSubjects = Console.ReadLine();
            checkScore();
        }

        public void checkRoll()
        {
            bool isCheck = true;
            while(isCheck)
            {
                Console.WriteLine("Nhap rollnumber");
                string data = Console.ReadLine();
                if(5 <data.Length && data.Length < 13)
                {
                    RollNumber = data;
                    isCheck = false;
                    return;
                }
                Console.WriteLine("Nhap rollnumber tu 6-12");
            } 
            
        }
 
        public void checkScore()
        {
            bool isCheck = true;
            while (isCheck)
            {
                Console.WriteLine("Nhap Score");
                int data = Convert.ToInt32(Console.ReadLine());
                if (data >=0 && data <= 10)
                {
                    Score = Convert.ToInt32(data);
                    isCheck = false;
                    return;
                }
                Console.WriteLine("Nhap Score tu 0-10");
            }

        }
    }
}


avatar
hainguyen [T2008A]
2021-05-17 08:54:04



using System;

namespace BaiTap01
{
    class StudentMark
    {
        public string rollno { get; set; }
        public string fullname { get; set; }
        public string className { get; set; }
        public string subject { get; set; }
        public float mark { get; set; }

        public StudentMark() { }

        public StudentMark(string rollno, string fullname, string className, string subject, float mark)
        {
            this.rollno = rollno;
            this.fullname = fullname;
            this.className = className;
            this.subject = subject;
            this.mark = mark;
        }

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

            Console.WriteLine("Nhap fullname: ");
            fullname = Console.ReadLine();

            Console.WriteLine("Nhap className: ");
            className = Console.ReadLine();

            Console.WriteLine("Nhap subject: ");
            subject = Console.ReadLine();

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

        public void Show()
        {
            Console.WriteLine("rollno = {0}, fullname = {1}, className = {2}, subject = {3}, mark = {4}", rollno, fullname, className, subject, mark);
        }

        static void Main(string[] args)
        {
            StudentMark studentMark1 = new StudentMark();
            StudentMark studentMark2 = new StudentMark();

            studentMark1.Input();
            studentMark2.Input();

            studentMark1.Show();
            studentMark2.Show();

            if (studentMark1.mark > studentMark2.mark)
            {
                studentMark1.Show();
            } else if (studentMark1.mark == studentMark2.mark)
            {
                Console.WriteLine("2 sv = diem");
            } else
            {
                studentMark2.Show();
            }
        }
    }
}


avatar
Luong Dinh Dai [T1907A]
2020-06-04 16:18:08


#Program.cs


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;

namespace Lessson4
{
    class Program
    {
        static void Main(string[] args)
        {
            Diemthi t = new Diemthi();
            t.input();
            t.display();
            Diemthi t1 = new Diemthi("ab0001", "smile", "T1907A", "laptrinh", 9);
            Console.WriteLine("Nguoi co diem cao nhat");
            if(t.Score > t1.Score)
            {
                t.display();
                return;
            }
            if(t.Score == t1.Score)
            {
                t1.display();
                t.display();
                return;
            }
            t1.display();
            
        }
    }
}


#Employee.cs


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

namespace Lessson4
{
    class Employee
    {
        string hoten;
        string _gender;
        string address;
        string chucvu;
        float luong;
        public string Hoten { get; set; }
        //enum gender
        public enum GioiTinh { Nam, Nu, KhongXacDinh};
        public GioiTinh Gender { get; set; }

       
        public string Address { get; set; }
        public string ChucVu { get; set; }
        public float Luong { get; set; }

        public Employee() { }
        public Employee(string hoten, GioiTinh gender, string address, string chucvu, float luong)
        {
            Hoten = hoten;
            Gender = gender;
            Address = address;
            ChucVu = chucvu;
            Luong = luong;
        }

        public void display()
        {
            Console.WriteLine("Hoten={0},Gender = {1},Address = {2},Chuc vu ={3},Luong ={4}",
                Hoten, Gender, Address, ChucVu, Luong);
        }
        public void input()
        {
            Console.WriteLine("Nhap hoten");
            Hoten = Console.ReadLine();
            Console.WriteLine("Nhap gender");
            checkGender();
            Console.WriteLine("Nhap address");
            Address = Console.ReadLine();
            Console.WriteLine("nhap Chuc Vu");
            ChucVu = Console.ReadLine();
            Console.WriteLine("Nhap luong");
            Luong = float.Parse(Console.ReadLine());
        }



        public void checkGender()
        {
            int choose;
            do
            {
                Console.WriteLine("0: Nam");
                Console.WriteLine("1: Nu");
                Console.WriteLine("2: Khong Xac Dinh");
                Console.WriteLine("Choose:");
                choose = Convert.ToInt32(Console.ReadLine());
                
                switch (choose)
                {
                    case 0:
                        Gender = GioiTinh.Nam;
                       // Console.WriteLine(Gender);
                        break;
                    case 1:
                        Gender = GioiTinh.Nu;
                        //Console.WriteLine(Gender);
                        break;
                    case 2:
                        Gender = GioiTinh.KhongXacDinh;
                        //Console.WriteLine(Gender);
                        break;

                }
            } while (choose > 2 || choose < 0);

        }
        }
    }



#diemthi.cs


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

namespace Lessson4
{
    class Diemthi
    {
        public string RollNumber { get; set; }
        public string FullName { get; set; }
        public string NameClass { get; set; }
        public string NameSubjects { get; set; }

        public int Score { get; set; }

        public Diemthi() { }
        public Diemthi(string rollnumber,string fullname,string nameClass,string nameSubjects,int score)
        {
            RollNumber = rollnumber;
            FullName = fullname;
            NameClass = nameClass;
            NameSubjects = nameSubjects;
            Score = score;
        }
        public void display()
        {
            Console.WriteLine("Rollnumber = {0}, Fullname = {1}, NameClass= {2}, NameSubject = {3}, Score ={4}",
                RollNumber,FullName,NameClass,NameSubjects,Score);    
        }
        public void input()
        {

            checkRoll();
            Console.WriteLine("nhap fullname");
            FullName = Console.ReadLine();
            Console.WriteLine("nhap nameClass");
            NameClass = Console.ReadLine();
            Console.WriteLine("nhap nameSubject");
            NameSubjects = Console.ReadLine();
            checkScore();
        }

        public void checkRoll()
        {
            bool isCheck = true;
            while(isCheck)
            {
                Console.WriteLine("Nhap rollnumber");
                string data = Console.ReadLine();
                if(5 <data.Length && data.Length < 13)
                {
                    RollNumber = data;
                    isCheck = false;
                    return;
                }
                Console.WriteLine("Nhap rollnumber tu 6-12");
            } 
            
        }

        //
        public void checkScore()
        {
            bool isCheck = true;
            while (isCheck)
            {
                Console.WriteLine("Nhap Score");
                int data = Convert.ToInt32(Console.ReadLine());
                if (data >=0 && data <= 10)
                {
                    Score = Convert.ToInt32(data);
                    isCheck = false;
                    return;
                }
                Console.WriteLine("Nhap Score tu 0-10");
            }

        }
    }
}


#Product.cs


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

namespace Lessson4
{
    class Product
    {
        private string maHH;
        private string tenHH;
        private float soLuong;
        private float gia1Sp;

        
        public string MaHH { get; set; }
        public string TenHH { get; set; }
        public float SoLuong { get; set; }
        public float Gia1Sp { get; set; }

        public Product() {}
        public Product(string maHH,string tenHH,float soLuong,float gia1Sp) 
        {
            MaHH = maHH;
            TenHH = tenHH;
            SoLuong = soLuong;
            Gia1Sp = gia1Sp;
        }
        public void display()
        {
            Console.WriteLine("maHH = {0} || tenHH = {1} || soluong = {2} || gia1Sp = {3}",
                maHH, TenHH, SoLuong, Gia1Sp);
        }
        public void input()
        {
            Console.WriteLine("Nhap maHH");
            MaHH = Console.ReadLine();
            Console.WriteLine("Nhap tenHH");
            TenHH = Console.ReadLine();
            Console.WriteLine("Nhap soLuong");
            SoLuong = float.Parse(Console.ReadLine());
            Console.WriteLine("Nhap gia1Sp");
            Gia1Sp = float.Parse(Console.ReadLine());
        }

    }
}