By GokiSoft.com| 09:53 07/10/2021|
C Sharp

Chương trình quản lý công nhân - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP

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

-       Họ tên             (String)

-       Giới tính          (String) (Nhận 3 giá trị Nam, Nữ, Ko biết)

-       Quê quán        (String)

-       Chức vụ          (String)

-       Lương             (double) => Dữ liệu là số dương

 

Cài đặt 2 constructors.

Cài đặt các phương thức set/get cho các thuộc tính

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

Cài đặt lớp Test, có hàm main:

Khai báo 2 đối tượng của lớp.

1 đối tượng gọi constructor có tham số. 1 đối tượng gọi constructor không có tham số (phải gọi hàm nhập để lấy thông tin).

Gọi hàm hiển thị để hiển thị kết quả.

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

5

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

NguyenHuuThanh [T1907A]
NguyenHuuThanh

2020-05-25 06:22:01



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

namespace BAITAP.BaitapQuanLyCongNhan
{
    class Employee
    {
        public string Name { get; set; }
        private string _gender
        {
            get
            {
                return _gender;
            }
            set
            {
                if (value.Equals("Nam") || value.Equals("Nữ") || value.Equals("Không biết"))
                {
                    this._gender = value;
                }    
                else
                {
                    Console.WriteLine("Error");
                }                    
            }
        }

        public string country { get; set; }

        public string position { get; set; }

        private float _salary
        {
            get
            {
                return _salary;
            }

            set
            {
                if (value > 0)
                {
                    this._salary = value;
                }
                else
                {
                    Console.WriteLine("Error");
                }
            }
        }

        public Employee()
        {

        }

        public Employee(string Name , string _gender , string country , string position , float salary)
        {
            this.Name = Name;
            this._gender = _gender;
            this.country = country;
            this.position = position;
            this._salary = salary;
        }

        public void input()
        {
            Name = Console.ReadLine();
            _gender = Console.ReadLine();
            country = Console.ReadLine();
            position = Console.ReadLine();
            _salary = float.Parse(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine(Name + "," + _gender + "," + country + "," + position + "," + _salary);

        }
    }
}

using BAITAP.BaitapQuanLyCongNhan;
using System;

namespace BAITAP
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee employee = new Employee();
            employee.input();
            employee.display();

            Employee employee01 = new Employee("Thanh", "Nam", "Ha Noi", "sep", 30000);
            employee01.display();
        }
    }
}



nguyễn văn huy [T1907A]
nguyễn văn huy

2020-05-21 10:32:50



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

namespace lesson3
{
    class Class1
    {
        
        public string Name { get; set; }
        private string _gender;
        public string Gender {
            get
            {
                return _gender;

            }
            set
            {
                if(Gender=="nam" || Gender=="nu"||Gender=="Kobiet"){
                    this._gender = value;
                } else
                {
                    Console.WriteLine(">>>>>.");
                }
            }
        
        }
        public string Address { get; set; }
        public string Chucvu { get; set; }
        public double Luong { get; set; }
        public void input()
        {
            Console.WriteLine("nhập tên:");
            Name = Console.ReadLine();
            Console.WriteLine("nhập giới tính");
            Gender = Console.ReadLine();
            Console.WriteLine("nhập địa điểm");
            Address = Console.ReadLine();
            Console.WriteLine("nhập chức vụ");
            Chucvu = Console.ReadLine();
            Console.WriteLine("nhập lương");
            Luong = double.Parse(Console.ReadLine());
        }
        public void display()
        {
            Console.WriteLine("{0},{1},{2},{3},{4},", Name, Gender, Address, Chucvu, Luong);
        }
    }
}
>>>>>>

using System;

namespace lesson3
{
    class Program
    {
        static void Main(string[] args)
        {
            Congnhan();
        }
        static void Congnhan()
        {
            Class1 congnhan = new Class1();
            congnhan.Name = "nguyen van a";
            congnhan.Gender = "nam";
            congnhan.Address = "thai binh";
            congnhan.Chucvu = "sinh vien";
            
            Console.WriteLine(congnhan.Name);
            Console.WriteLine(congnhan.Gender);
            Console.WriteLine(congnhan.Address);
            Console.WriteLine(congnhan.Chucvu);
            Console.WriteLine(congnhan.Luong);
            congnhan.input();
            congnhan.display();
        }
    }
}




Minh Nghia [T1907A]
Minh Nghia

2020-05-21 09:08:59



using System;
using Woker;

namespace Wokers
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee emp1 = new Employee();
            Employee emp2 = new Employee("Nghia", "Male", "Hai Duong", "CEO" ,5000);

            emp1.Input();
            emp1.Display();
            emp2.Display();
        }
    }
}



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

namespace Woker
{
    class Employee
    {

        public  Employee()
        {
        }
        public Employee(string FullName, string Gender, string Address, string Position, double Salary )
        {
            this.FullName = FullName;
            this.Gender = Gender;
            this.Address = Address;
            this.Position = Position;
            this.Salary = Salary;
        }
        public string FullName { get; set; }
        private string _gender;
        public string Gender
        {
            get
            {
                return _gender;
            }

            set
            {

                if (value.Equals("Male") || value.Equals("Female") || value.Equals("Else"))
                {
                    this._gender = value;
                }
                else
                {
                    Console.WriteLine("Enter the correct gender");


                }

            }
        }
        public string Address { get; set; }
        public string Position { get; set; }
        private double _salary;
        public double Salary 
        {
            get
            {
                return _salary;
            }
            set
            {
                if(value > 0)
                {
                    this._salary = value;
                }
                else
                {
                    Console.WriteLine("Du lieu la so duong");
                }
            }
        }

        public void Input()
        {
            Console.WriteLine("Enter Fullname : ");
            FullName = Console.ReadLine();
            Console.WriteLine("Enter Gender : ");
            Gender = Console.ReadLine();
            Console.WriteLine("Enter Address : ");
            Address = Console.ReadLine();
            Console.WriteLine("Enter Position : ");
            Position = Console.ReadLine();
            Console.WriteLine("Enter Salary : ");
            Salary = Double.Parse(Console.ReadLine());
        }
        public void Display()
        {
            Console.WriteLine("Woker {0} ,{1}, {2}, {3}, {4} ", FullName, Gender, Address, Position, Salary);
        }
    }
}



thienphu [T1907A]
thienphu

2020-05-21 07:55:39


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

        }
        }
    }



#Program.cs


using System;
using System.Collections.Generic;

namespace Lessson4
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee e1 = new Employee("thien phu",Employee.GioiTinh.Nam,"Ha Noi","GiamDoc",5000);
            e1.display();
            Employee e2 = new Employee();
            e2.input();
            e2.display();
            
        }
    }
}



hoangduyminh [T1907A]
hoangduyminh

2020-05-21 01:05:17



using System;

namespace Lession5
{
    class Program
    {
        static void Main(string[] args)
        {
            test01();
        }
        public static void test01()
        {
            Employee employee = new Employee();
            employee.name = "Hoang Duy Minh";
            employee.gender = "male";
            employee.address = "Nam Dinh";
            employee.Chucvu = "Student";
            Console.WriteLine(employee.name);
            Console.WriteLine(employee.gender);
            Console.WriteLine(employee.address);
            Console.WriteLine(employee.Chucvu);

            employee.input();
            employee.display();
        }
        
    }
}



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

namespace Lession5
{
    class Employee
    {
         public String name { get; set; }
         private string _gender;
         public String gender {
            get
            {
                return _gender;
            }

            set {
                if (value.Equals("Male") || value.Equals("Female") || value.Equals("??"))
                {
                    this._gender = value;
                }
                else
                {
                    Console.WriteLine(" Ko biet!!!");
                }
            }
        }
         public String address { get; set; }
        public String Chucvu { get; set; }

        private float Salary { get; set; }
      
         public void input()
        {
            Console.WriteLine("Nhap vao ten:");
            name = Console.ReadLine();
            Console.WriteLine("Nhap vao gioi tinh:");
            gender = Console.ReadLine();
            Console.WriteLine("Nhap vao dia chi:");
            address = Console.ReadLine();
            Console.WriteLine("Nhap vap Chuc vu:");
            Chucvu = Console.ReadLine();
            Console.WriteLine("Nhap vao tien luong :");
            Salary = float.Parse(Console.ReadLine());
        }
        public void display()
        {
            Console.WriteLine(" Employee: {0} , {1}, {2}, {3}, {4}", name, gender, address, Chucvu, Salary );
        }
    }
   
}



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

2020-05-20 13:45:39


#Program.cs


using System;

namespace QuanliCN
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee emp = new Employee();
            emp.intput();
            emp.output();
        }
    }
}


#Employee.cs


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

namespace QuanliCN
{
    class Employee
    {
        public string fullname { get; set; }
        public string gender { get; set; }
        public string address { get; set; }
        public string chucvu { get; set; }
        public double luong { get; set; }

        public Employee()
        {

        }

        public Employee(String fullname, String gender, String address, String chucvu, Double luong)
        {
            this.fullname = fullname;
            this.gender = gender;
            this.address = address;
            this.chucvu = chucvu;
            this.luong = luong;
        }
        public void intput()
        {
            Console.Write("Enter fullname: ");
            fullname = Console.ReadLine();
            Console.Write("Enter gender(Male, Female, Gay/Less): ");
            gender = Console.ReadLine();
            Console.Write("Enter address: ");
            address = Console.ReadLine();
            Console.Write("Enter position: ");
            chucvu = Console.ReadLine();
            Console.Write("Enter salary: ");
            luong = double.Parse(Console.ReadLine());
        }
        public void output()
        {
            Console.WriteLine("===============");
            Console.WriteLine("Information: ");
            Console.WriteLine("Full name: {0}, \nGender: {1}, \nAddress: {2}, \nPosition: {3}, \nSalary: {4}", fullname, gender, address, chucvu, luong);
        }



    }
}



Đỗ Văn Huấn [T1907A]
Đỗ Văn Huấn

2020-05-20 12:06:20



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

namespace BaiTapNgay20_5_2020_product
{
    class Employee
    {
        private string fullname { set; get; }

        private enum Gender
        { 
            Nam, Nu, Bede
        }
        private Gender gender { set; get; }


       
        private string address { get; set; }
        private string role { get; set; }
        private double _salary;
        private double salary
        {
            get
            {
                return _salary;
            }
            set
            {
                if (value > 0)
                {
                    this._salary = value;
                }
                else
                {
                    Console.WriteLine("Luong phai lon hon 0.");
                }
            }
        }

        public Employee() { }


        public void input(){
            Console.WriteLine("Nhap ten :");
            fullname = Console.ReadLine();

            int i;
            do
            {
                Console.WriteLine("chon gioi tinh: ");
                Console.WriteLine("1.Nam ");
                Console.WriteLine("2.Nu ");
                Console.WriteLine("3.Bede ");
                 i = Convert.ToInt32(Console.ReadLine());

                switch (i)
                {
                    case 1:
                        gender = Gender.Nam;
                        break;
                    case 2:
                        gender = Gender.Nu;
                        break;
                    case 3:
                        gender = Gender.Bede;
                        break;
                }

            } while (i >3 && i<0 );

            Console.WriteLine("Nhap que quan : ");
            address = Console.ReadLine();
            Console.WriteLine("Nhap chuc vu :");
            role = Console.ReadLine();
            Console.WriteLine("Nhap tien luong : ");
            salary = Convert.ToDouble(Console.ReadLine());

        }

        public void display()
        {
            Console.WriteLine("Ten: {0}\nGioiTinh: {1}\nDia chi: {2}\nChuc vu: {3}\nLuong: {4}", fullname, gender, address, role, salary);
        }
    }
}



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

namespace BaiTapNgay20_5_2020_product
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee employee = new Employee();
            employee.input();
            employee.display();
            Console.ReadKey();

        }
    }
}



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

2020-05-20 10:09:29



using System;

namespace QLCN
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            testOOP();
            testOOP2();
            

        }
        static void testOOP()
        {

            Employee emp = new Employee();
            emp.fullname = "Phi Van Long";
            emp.gender = "Nam";
            emp.address = "Quang Ninh";
            emp.role = " CEO";
            emp.salary = 1000000000;
            Console.WriteLine(emp.fullname);
            Console.WriteLine(emp.gender);
            Console.WriteLine(emp.address);
            Console.WriteLine(emp.role);
            Console.WriteLine(emp.salary);
            
        }
        static void testOOP2()
        {
            Employee emp = new Employee();
            emp.input();
            emp.display();
        }
    }   

}



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

namespace QLCN
{
    class Employee
    {
        public string fullname { get; set; }
        private string _gender;
        public string gender
        {
            get
            {
                return _gender;
            }
            set
            {
                if (value.Equals("Nam")|| value.Equals("nam") || value.Equals("Nu") || value.Equals("nu") || value.Equals("Gay"))
                {
                    this._gender = value;
                }
                else
                {
                    Console.WriteLine("ban phai nhap dung gioi tinh cua minh");
                }

            }




        }
        public string address { get; set; }
        public string role { get; set; }
        private double _salary;
        public double salary
        {
            get
            {
                return _salary;
            }
            set
            {
                if (value > 0 )
                {
                   this._salary = value;
                }
                else
                {
                    Console.WriteLine("Nhap luong la so duong");
                }
            }
        }

        public Employee(string fullname,string gender,string address,string role,double salary)
        {
            this.fullname = fullname;
            this.gender = gender;
            this.address = address;
            this.role = role;
            this.salary = salary;
        }

        public Employee()
        {
        }

        public void input()
        {
            Console.WriteLine("Nhap ten :");
            fullname = Console.ReadLine();
            Console.WriteLine("Nhap gioi tinh : ");
            gender = Console.ReadLine();
            Console.WriteLine("Nhap que quan : ");
            address = Console.ReadLine();
            Console.WriteLine("Nhap chuc vu :");
            role = Console.ReadLine();
            Console.WriteLine("Nhap tien luong : ");
            salary = Convert.ToDouble(Console.ReadLine()) ;
        }
        public void display()
        {
            Console.WriteLine("Cong nhan >> {0},{1},{2},{3},{4}",fullname,gender,address,role,salary);
        }
    }

}



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

2020-05-20 09:09:09



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

namespace Worker
{
    class Employee
    {
        string hoten { get; set; }
        private string _gioitinh;
         string gioitinh
        {
            get
            {
                return _gioitinh;
            }
            set
            {
                
                if (value.Equals("Nam") || value.Equals("Nu") || value.Equals("ko biet"))
                {
                    this._gioitinh = value;
                    
                }
                else
                {
                    Console.WriteLine("Nhận 3 giá trị Nam, Nu, Ko biet");
                    
                }
            }

        }
        string quequan { get; set; }
        string chucvu { get; set; }
        private double _luong;
        double luong { get { return _luong; }
            set {
                
                    if (value > 0)
                    {
                        this._luong = value;
                    }
                    else
                    {
                        Console.WriteLine("Dữ liệu là số dương");
                    }
                
            } }
        
        public Employee()
        {

        }
        public Employee(string hoten , string gioitinh, string quequan , string chucvu , double luong)
        {
            this.hoten = hoten;
            this.gioitinh = gioitinh;
            this.quequan = quequan;
            this.chucvu = chucvu;
            this.luong = luong;
        }
        public void input()
        {
            Console.WriteLine("Họ tên : ");
            hoten = Console.ReadLine();
            
           
                Console.WriteLine("Giới tính :");
                gioitinh = Console.ReadLine();
            
            Console.WriteLine("Quê quán : ");
            quequan = Console.ReadLine();
            Console.WriteLine("Chức vụ : ");
            chucvu = Console.ReadLine();
           
                Console.WriteLine("Lương : ");
                luong = double.Parse(Console.ReadLine());
                
            
        }
        
        public void display()
        {
            Console.WriteLine(toString());
        }
        private string toString()
        {
            return "Employee{" + "ho ten : " + hoten + ", gioi tinh : " + gioitinh + ", que quan : " + quequan + ", chuc vu :" + chucvu + ", luong : $" + luong + "}";
        }

    } 
}



using System;

namespace Worker
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Employee employee = new Employee();
            employee.input();
            employee.display();
            Employee employee1 = new Employee("Truong Cong Vinh","Nam","HN","Employee",3000.0);
            employee1.display();
        }
    }
}



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

2020-05-20 08:54:46



using System;

namespace Lession4
{
    class Tets
    {
        static void Main(string[] agrs)
        {
            Employee emp1 = new Employee();
            Employee emp2 = new Employee("Le Minh Bac", "Nam", "Ha Noi", "Boss", 10000);

            emp1.input();
            emp1.display();
            emp2.display();

            Console.ReadKey();
        }
    }
}



using System;

namespace Lession4
{
    class Employee
    {
        public string Name { get; set; }
        private string _gender;
        public string Gender
        {
            get
            {
                return _gender;
            }
            set
            {
                if (value.Equals("Nam") || value.Equals("Nu") || value.Equals("Khac") ) {
                    this._gender = value;
                } else
                {
                    Console.WriteLine("Du lieu nhap vao phai la: Nam or Nu or Khac");
                    this._gender = "Du lieu nhap sai.";
                    
                }
            }
        }
        public string Address { get; set; }
        public string Position { get; set; }

        private double _salary;
        public double Salary
        {
            get
            {
                return _salary;
            }
            set
            {
                if(value > 0)
                {
                    this._salary = value;
                } else
                {
                    Console.WriteLine("Luong nhap vao phai > 0.");
                }
            }
        }

        public Employee() { }
        public Employee(string Name, string Gender, string Address, string Position, double Salary)
        {
            this.Name = Name;
            this.Gender = Gender;
            this.Address = Address;
            this.Position = Position;
            this.Salary = Salary;
        }

        public void input() {
            Console.Write("Nhap ten: ");
            Name = Console.ReadLine();
            Console.Write("Nhap gioi tinh: ");
            Gender = Console.ReadLine();
            Console.Write("Nhap dia chi: ");
            Address = Console.ReadLine();
            Console.Write("Nhap chuc vu: ");
            Position = Console.ReadLine();
            Console.Write("Nhap luong: ");
            Salary = double.Parse(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine("Ten: {0}\nGioiTinh: {1}\nDia chi: {2}\nChuc vu: {3}\nLuong: {4}", Name, Gender, Address, Position, Salary);
        }
    }
}