Untitled
unknown
csharp
3 years ago
4.3 kB
10
Indexable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace QuanLyNhanVien
{
class NhanVien
{
public string hoTen { get; set; }
public string ngaySinh { get; set; }
public double luongCoBan { get; set; }
public double luong { get; set; }
public virtual void nhap()
{
Console.WriteLine("Nhap ho ten cua nhan vien: ");
hoTen = Console.ReadLine();
Console.WriteLine("Nhap ngay sinh cua nhan vien: ");
ngaySinh = Console.ReadLine();
Console.WriteLine("Nhap luong co ban cua nhan vien: ");
luongCoBan = Convert.ToDouble(Console.ReadLine());
}
public virtual void xuat()
{
Console.WriteLine($"Ho ten nhan vien: {hoTen}");
Console.WriteLine($"Ngay sinh nhan vien: {ngaySinh}");
Console.WriteLine("Luong co ban: {0}", luongCoBan);
}
}
class NVVanPhong : NhanVien
{
public int soNgayLamViec { get; set; }
public double troCap { get; set; }
public NVVanPhong()
{
}
public override void nhap()
{
base.nhap();
Console.WriteLine("Nhap so ngay lam viec: ");
soNgayLamViec = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap tien tro cap: ");
troCap = Convert.ToDouble(Console.ReadLine());
}
public override void xuat()
{
base.xuat();
Console.WriteLine("So ngay lam viec: {0}", soNgayLamViec);
Console.WriteLine("So tien tro cap: {0}", troCap);
tinhLuong();
Console.Write("So tien luong la: {0}", luong);
}
double tinhLuong()
{
luong = luongCoBan + soNgayLamViec * 100000 + troCap;
return luong;
}
}
class NVSanXuat : NhanVien
{
public int soSanPham { get; set; }
public NVSanXuat()
{
}
public override void nhap()
{
base.nhap();
Console.WriteLine("Nhap so san pham: ");
soSanPham = Convert.ToInt32(Console.ReadLine());
}
public override void xuat()
{
base.xuat();
Console.Write("So san pham: ", soSanPham);
tinhLuong();
Console.Write("So tien luong la: {0}", luong);
}
double tinhLuong()
{
luong = luongCoBan + soSanPham * 2000;
return luong;
}
}
class NVQuanLy : NhanVien
{
public double heSoChucVu { get; set; }
public double thuong { get; set; }
public NVQuanLy()
{
}
public override void nhap()
{
base.nhap();
Console.WriteLine("Nhap he so chuc vu: ");
heSoChucVu = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Nhap thuong: ");
thuong = Convert.ToDouble(Console.ReadLine());
}
public override void xuat()
{
base.xuat();
Console.Write("He so chuc vu: ", heSoChucVu);
Console.Write("So thuong: ", thuong);
tinhLuong();
Console.Write("So tien luong la: {0}", luong);
}
double tinhLuong()
{
luong = luongCoBan * heSoChucVu + thuong;
return luong;
}
}
class Program
{
static void Main(string[] args)
{
List<NhanVien> listNhanVien = new List<NhanVien>();
NhapDSNhanVien(listNhanVien);
XuatDSNhanVien(listNhanVien);
Console.WriteLine("Tong luong: {0}", TongLuong(listNhanVien));
Console.ReadKey();
}
static void NhapDSNhanVien(List<NhanVien> nhanViens)
{
int size;
Console.WriteLine("Nhap so luong nhan vien: ");
size = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < size; i++)
{
NhanVien tmp;
Console.WriteLine("Nhap phong ban nhan vien:\n1. Quan ly\n2. San xuat\n3. Van phong\n==> ");
var loaiNv = Convert.ToInt32(Console.ReadLine());
switch (loaiNv)
{
case 1:
tmp = new NVQuanLy();
tmp.nhap();
tmp.xuat();
break;
case 2:
tmp = new NVSanXuat();
tmp.nhap();
tmp.xuat();
break;
case 3:
tmp = new NVVanPhong();
tmp.nhap();
tmp.xuat();
break;
default:
i--;
continue;
}
nhanViens.Add(tmp);
}
}
static void XuatDSNhanVien(List<NhanVien> nhanViens)
{
foreach (var nv in nhanViens)
{
nv.xuat();
}
}
static double TongLuong(List<NhanVien> nhanViens)
{
double sum = 0;
foreach (var nv in nhanViens)
{
sum += nv.luong;
}
return sum;
}
}
}
Editor is loading...