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

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.

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

5

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

Thành Lâm [T1907A]
Thành Lâm

2020-06-01 08:31:04



namespace nhập_xuất_dữ_liệu_điểm_thi
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine("Hello World!");
            Console.WriteLine("==================Nhập xuất điểm thi===================");
            diemthi();
        }

        static void diemthi()
        {
            StudentMark studentMark = new StudentMark;
            studentMark.Fullname = "Nguyễn Thành Lâm";
            studentMark.Class = "T1907A";

            studentMark.input();
            studentMark.display();
        }
    }
}



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

namespace nhập_xuất_dữ_liệu_điểm_thi
{
    class StudentMark
    {
        private string _rollnumber;
        public string Rollnumber {
            get
            {
                return _rollnumber;
            }
            set
            {
                if(value.Length >= 6 && value.Length <= 12)
                {
                    this._rollnumber = value;
                }
                else
                {
                    Console.WriteLine("Dữ liệu nhập từ 6 - 12 kí tự");
                }
            }
        }
        public string Fullname { get; set; }
        public string Class { get; set; }
        public string Subjects { get; set; }
        private double _point;
        public double Point {
            get
            {
                return _point;
            }
            set
            {
                if(value >= 0 && value <= 10)
                {
                    this._point = value;
                }
                else
                {
                    Console.WriteLine("Bạn nhập sai điểm!\n Nhập lại");
                }
            }
        }

        public StudentMark()
        {

        }

        public void input()
        {
            Console.WriteLine("Nhập RollNumber: ");
            Rollnumber = Console.ReadLine();
            Console.WriteLine("Nhập tên: ");
            Fullname = Console.ReadLine();
            Console.WriteLine("Nhập Lớp: ");
            Class = Console.ReadLine();
            Console.WriteLine("Nhập Môn: ");
            Subjects = Console.ReadLine();
            Console.WriteLine("Nhập điểm: ");
            Point = double.Parse(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine("{}\n Tên: {}\n Lớp: {}\n Môn: {}\n Điểm: {}", Rollnumber, Fullname, Class, Subjects, Point);
        }

    }
}



NguyenHuuThanh [T1907A]
NguyenHuuThanh

2020-05-25 06:33:25



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

namespace BAITAP.StudentMark
{
    class StudentMark
    {
        private string _rollnumber
        {
            get
            {
                return _rollnumber;
            }

            set
            {
                if ( value.Length >= 6 && value.Length <= 12 )
                {
                    this._rollnumber = value;

                }
                else
                {
                    Console.WriteLine("Error");
                }    
            }
        }

        public string name { get; set; }

        public string classname { get; set; }

        public string subjectname { get; set; }

        private float _point
        {
            get
            {
                return _point;
            }

            set
            {
                if ( value >= 0 && value <= 10)
                {
                    this._point = value;
                }    
                else
                {
                    Console.WriteLine("Error");
                }    
            }
        }

        public StudentMark()
        {

        }

        public StudentMark(string rollnumber, string name, string classname, string subjectname, float point)
        {
            this._rollnumber = rollnumber;
            this.name = name;
            this.classname = classname;
            this.subjectname = subjectname;
            this._point = point;

        }

        public void input()
        {
            _rollnumber = Console.ReadLine();
            name = Console.ReadLine();
            classname = Console.ReadLine();
            subjectname = Console.ReadLine();
            _point = float.Parse(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine(_rollnumber + name + classname + subjectname + _point);
        }

        static void main(String[] args)
        {
            StudentMark sm1 = new StudentMark();
            StudentMark sm2 = new StudentMark();

            sm1.input();
            sm1.display();
            sm2.input();
            sm2.display();
        }
    }
}



thienphu [T1907A]
thienphu

2020-05-21 08:28:39


#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");
            }

        }
    }
}


#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();
            
        }
    }
}



Phí Văn Long [T1907A]
Phí Văn Long

2020-05-21 08:11:12



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

namespace QLDT
{
    class StudentMark
    {
        static void Main (string[] args)
        {
                StudentMark stu = new StudentMark();
                StudentMark stu2 = new StudentMark("TH1907014", "Phi Long", "T1907A", "C#", 6.9f);

                stu.input();
                    stu.display();
                    stu2.display();

                    Console.WriteLine("\n SV co diem cao nhat :");
                    if(stu.Diem > stu2.Diem)
                    {
                        stu.display();
                    }
                    else
                    {
                        stu2.display();
                    }          
        }
        
        private string _rollnumber;
        public string Rollnumber
        {
            get
            {
                return _rollnumber;
            }
            set
            {
                if (value.Length >= 6 && value.Length <= 10)
                {
                    this._rollnumber = value;
                }
                else
                {
                    Console.WriteLine("RollNumber phai tu 6-12 ky tu");
                }
            }
        }
        public string Hoten { get; set; }
        public string Lop { get; set; }
        public string Mon { get; set; }

        private float _diem;
        public float Diem
        {
            get
            {
                return _diem;
            }
            set
            {
                if (value >= 0 && value <= 10)
                {
                    this._diem = value;
                }
                else
                {
                    Console.WriteLine("Point >=0 && <= 10");
                }
            }
        }
        public StudentMark()
        {

        }
        public StudentMark(string Rollnumber, string Hoten, string Lop, string Mon, float Diem)
        {
            this.Rollnumber = Rollnumber;
            this.Hoten = Hoten;
            this.Lop = Lop;
            this.Mon = Mon;
            this.Diem = Diem;
        }
        public void input()
        {
            Console.WriteLine("Nhap Roll Number :  :");
            Rollnumber = Console.ReadLine();
            Console.WriteLine("Nhap Ho va Ten :");
            Hoten = Console.ReadLine();
            Console.WriteLine("Nhap Lop :");
            Lop = Console.ReadLine();
            Console.WriteLine("Nhap Mon hoc : ");
            Mon = Console.ReadLine();
            Console.WriteLine("Nhap Diem :");
            Diem = float.Parse(Console.ReadLine());

        }
        public void display()
        {
            Console.WriteLine("\nDiem cua Sinh vien : {0},{1},{2},{3},{4}", Rollnumber, Hoten, Lop, Mon, Diem);
        }
    }
}



Minh Nghia [T1907A]
Minh Nghia

2020-05-21 01:54:36



using System;


namespace TestMarks
{
    class StudentMark
    {
        static void Main(string[] args)
        {
            
            StudentMark sm1 = new StudentMark();
            StudentMark sm2 = new StudentMark("1907030", "Minh Nghia", "T1907A", "PHP", 7f);

            sm1.Input();
            sm1.Display();

            sm2.Display();


            Console.WriteLine("\nSV co diem cao nhat :");
            if(sm1.Point > sm2.Point)
            {
                sm1.Display();
            }
            else
            {
                sm2.Display();
            }

            
            
        }
        public  StudentMark()
        {
        }
        public StudentMark(string Rollnumber,string Fullname, string Class, string Subject,float Point)
        {
            this.Rollnumber = Rollnumber;
            this.Fullname = Fullname;
            this.Class = Class;
            this.Subject = Subject;
            this.Point = Point;
        }
        private string _rollnumber;
        public string Rollnumber
        {
            get
            {
                return _rollnumber;
            }
            set
            {
                if(value.Length >= 6 && value.Length <= 10)
                {
                    this._rollnumber = value;
                }
                else
                {
                    Console.WriteLine("Length does not exceed approx 6 => 12");
                }
            }
        }
        public string Fullname { get; set; }
        public string Class { get; set; }
        public string Subject { get; set; }

        private float _point;
        public float Point 
        {
            get
            {
                return _point;
            }
            set
            {
                if(value >= 0 && value <= 10)
                {
                    this._point = value;
                }
                else
                {
                    Console.WriteLine("Point >=0 && <= 10");
                }
            }
        }
        public void Input()
        {
            Console.WriteLine("Enter Rollnumber :");
            Rollnumber = Console.ReadLine();
            Console.WriteLine("Enter Fullname :");
            Fullname = Console.ReadLine();
            Console.WriteLine("Enter Class :");
            Class = Console.ReadLine();
            Console.WriteLine("Enter Subject : ");
            Subject = Console.ReadLine();
            Console.WriteLine("Enter Point :");
            Point = float.Parse(Console.ReadLine());

        }
        public void Display()
        {
            Console.WriteLine("\nStudent Mark : {0} , {1} , {2} , {3} , {4}", Rollnumber, Fullname, Class, Subject, Point);
        }
    }
    

}



Trần Mạnh Dũng [T1907A]
Trần Mạnh Dũng

2020-05-20 12:56:12


#Program.cs


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

namespace Nhapxuatdulieudiemthi
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            List<StudentMark> liststdMark = new List<StudentMark>();

            for (int i = 1; i <= 2; i++)
            {
                StudentMark stdMark = new StudentMark();
                Console.WriteLine("===============");
                Console.WriteLine("Enter Student {0}:", i);
                stdMark.input();
                liststdMark.Add(stdMark);
            }
            StudentMark studentMark = liststdMark[0];
            Console.WriteLine("====================");
            Console.WriteLine("The information of the person with the highest score is: ");
            foreach (var item in liststdMark)
            {
                if(studentMark.Mark < item.Mark)
                {
                    studentMark = item;
                }
            }

            studentMark.output();
        }
    }
}


#StudentMark.cs


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

namespace Nhapxuatdulieudiemthi
{
    class StudentMark
    {
        public string rollnumber;
        public string Rollnumber
        {
            get
            {
                return rollnumber;
            }
            set
            {
                if(value.Length >= 6 && value.Length <= 12)
                {
                    this.rollnumber = value;
                }
                else
                {
                    Console.WriteLine("Nhập độ dài từ 6 - 12 ký tự");
                }
            }
        }
        public float mark;
        public float Mark
        {
            get
            {
                return mark;
            }
            set
            {
                if (mark >= 0 && mark <= 10)
                {
                    this.mark = Mark;
                }
                else
                {
                    Console.WriteLine("Nhập điểm từ 0 đến 10");
                }
            }
        }
        public string Fullname { get; set; }
        public string Classroom { get; set; }
        public string Subject { get; set; }
        public StudentMark()
        {

        }
        public StudentMark(String rollnumber,String fullname, String classroom, String subject, float mark)
        {
           this.Rollnumber = rollnumber;
           this.Fullname = fullname;
           this.Classroom = classroom;
           this.Subject = subject;
           this.Mark = mark;
        }
        public void input()
        {
            Console.Write("Enter rollnumber: ");
            Rollnumber = Console.ReadLine();
            Console.Write("Enter fullname: ");
            Fullname = Console.ReadLine();
            Console.Write("Enter classroom: ");
            Classroom = Console.ReadLine();
            Console.Write("Enter Subject: ");
            Subject = Console.ReadLine();
            Console.Write("Enter mark: ");
            Mark = float.Parse(Console.ReadLine());
        }
        public void output()
        {
            Console.WriteLine("Rollnumber: {0}, Fullname: {1}, Classroom: {2}, Subject: {3}, Mark: {4}",Rollnumber, Fullname, Classroom, Subject, Mark);
        }



    }
}



Trương Công Vinh [T1907A]
Trương Công Vinh

2020-05-20 09:39:57



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

namespace StudentMark
{
    class Mark
    {
        public string Rollnumber {
            get { return _rollNumber; }
            set
            {
                if(value.Length >=6 && value.Length <= 12){ 
                    this._rollNumber = value;
                }
                else
                {
                    Console.WriteLine("Độ dài là 6-12");
                }
            }
        }
        private string _rollNumber;
        public string name;
        public string className;
        string subjectName;
        public float mark {
            get
            {
                return _mark;
            }
            set
            {
                if (value >=0 && value <= 10)
                {
                    this._mark = value;
                }
                else
                {
                    this._mark = 0;
                }
            }
        }
        private float _mark;

        public Mark()
        {

        }
        public Mark(string Rollnumber, string name,string className,string subjectName, float mark)
        {
            this.Rollnumber = Rollnumber;
            this.name = name;
            this.className = className;
            this.subjectName = subjectName;
            this.mark = mark;
        }
        public void input()
        {
            
            Console.WriteLine("Rollnumber : ");
            Rollnumber = Console.ReadLine();
            Console.WriteLine(" Student Name : ");
            subjectName = Console.ReadLine();
            Console.WriteLine("Class Name : ");
            className = Console.ReadLine();
            Console.WriteLine("Subject : ");
            subjectName = Console.ReadLine();
            Console.WriteLine("Mark : ");
            mark = float.Parse(Console.ReadLine());
        }
        private string toString()
        {
            return "StudentMark{"+"Roll : "+Rollnumber + ", Name : "+name +", class : "+className+", Subject : "+subjectName+"Mark : "+mark+"}";
        }
        public void display()
        {
            Console.WriteLine(toString());
        }
    }
}



using System;



namespace StudentMark
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Mark mark = new Mark();
            mark.input();
            Mark mark1 = new Mark("Std0001","Nhuyen van a","A","Hoa",6.5f);
            if (mark.mark > mark1.mark)
            {
                mark.display();
            }
            else
            {
                mark1.display();
            }
        }
    }
}



Lê Minh Bắc [T1907A]
Lê Minh Bắc

2020-05-20 09:28:31



using System;


namespace Lession4
{
    class StudentMark
    {
        private string _rollno;
        public string Rollno { 
            get
            {
                return _rollno;
            }
            set
            {
                if (value.Length >= 6 && value.Length <= 12)
                {
                    this._rollno = value;
                }
                else {
                    Console.WriteLine("Rollnumber phai co do dai >= 6 hoac <= 12");
                    this._rollno = "Du lieu nhap loi";
                }
            }
        }

        public string Name { get; set; }
        public string Class { get; set; }
        public string Subject { get; set; }
        private float _point;
        public float Point
        {
            get
            {
                return _point;
            }
            set
            {
                if(value >= 0 && value <= 10)
                {
                    this._point = value;
                }
                else
                {
                    Console.WriteLine("Diem phai >= 0 va <= 10");
                }
            }
        }

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

        public void input()
        {
            Console.Write("Nhap roll number: ");
            Rollno = Console.ReadLine();
            Console.Write("Nhap ten: ");
            Name = Console.ReadLine();
            Console.Write("Nhap lop: ");
            Class = Console.ReadLine();
            Console.Write("Nhap mon hoc: ");
            Subject = Console.ReadLine();
            Console.Write("Nhap diem: ");
            Point = float.Parse(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine("RollNumber: {0}\nTen: {1}\nLop: {2}\nMon hoc: {3}\nDiem: {4}",Rollno,Name,Class,Subject,Point);
        }

        public static void Main(String[] agrs)
        {
            StudentMark std1 = new StudentMark();
            StudentMark std2 = new StudentMark("1234567", "le Minh Bac", "T1907A", "C#", 10);

            std1.input();
            std1.display();
            std2.display();

            Console.WriteLine("SV co diem cao nhat la:");
            if(std1.Point > std2.Point)
            {
                std1.display();
            }
            else if( std1.Point == std1.Point)
            {
                Console.WriteLine("Diem cua 2 SV bang nhau.");
                std1.display();
                std2.display();
            }
            else
            {
                std2.display();
            }

            Console.ReadKey();
        }
    }
}