Tải bản đầy đủ (.docx) (11 trang)

ĐÁP ÁN FULL CODE VÀ HÌNH BTNT ASSIGMENT OPT3

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (141.49 KB, 11 trang )

Assignments 1
Objective:
Problem Description:

Một trường đại học quản lý thông tin cán bộ (gồm giảng viên và nhân viên hành chính) trong
trường.
Với giảng viên cần quản lý các thông tin: Họ tên, khoa, trình độ (cử nhân, thạc sĩ, tiến sĩ), phụ
cấp, số tiết dạy trong tháng ,hệ số lương.
Với nhân viên hành chính cần quản lý: Họ tên, phòng ban, số ngày công, hệ số lương, phụ cấp,
chức vụ (trưởng phòng, phó phòng, nhân viên).
Phụ cấp cán bộ được tính theo bảng:
cử nhân 300.
thạc sĩ 500.
tiến sĩ 1000.
trưởng phòng 2000.
phó phòng 1000.
nhân viên 500.
Lương giảng viên được tính như sau: Hệ số lương*730+phụ cấp+số tiết dạy*45.
Lương nhân viên được tính như sau: Hệ số lương*730+phụ cấp+số ngày công*30;







Viết chương trình quản lý thông tin cán bộ trong trường bao gồm các chức năng :
1.Nhập dữ liệu cho các cán bộ trong trường.
2.Tìm kiếm nhân viên theo tên và phòng ban và in ra màn hình thông tin chi tiết về nhân viên
này.
3.Xuất ra danh sách cán bộ toàn trường , Sắp xếp theo lương, nếu lương bằng thì sắp xếp theo


tên.
Yêu cầu:



Viết trên console application, có xử lý exceptions, tuân thủ Fsoft coding conventions
Hàm main chỉ việc call (không có thêm bất cứ business check nào)

Estimated time: 3.5 hours

Assignment 3 Opt1 – BTNB
Tạo CLASS QL_CANBO


using
using
using
using
using

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

namespace QL_CANBO
{
class Canbo
{

string hoten;
public string Hoten
{
get { return hoten; }
set { hoten = value; }
}
int loai;
public int Loai
{
get { return loai; }
set { loai = value; }
}
string khoa_phban;
public string Khoa_phban
{
get { return khoa_phban; }
set { khoa_phban = value; }
}
string td_cv;
public string Td_cv
{
get { return td_cv; }
set { td_cv = value; }
}
int sotiet_songaycong;
public int Sotiet_Songaycong
{
get { return sotiet_songaycong; }
set { sotiet_songaycong = value; }
}

double hsluong;
public double Hsluong
{
get { return hsluong; }
set { hsluong = value; }
}
double phucap;
public double Phucap
{
get { return phucap; }
set { phucap = value; }


}
double luong;
public double Luong
{
get { return luong; }
set { luong = value; }
}
public Canbo(string A, int B, string C, string D, int E, double F)
{
Hoten = A;
Loai = B;
Khoa_phban = C;
Td_cv = D;
Sotiet_Songaycong = E;
Hsluong = F;
if (D == "Cu Nhan")
Phucap = 300;

else if (D == "Thac Si")
Phucap = 500;
else if (D == "Tien Si")
Phucap = 1000;
else if (D == "Truong Phong")
Phucap = 2000;
else if (D == "Pho Phong")
Phucap = 1000;
else
Phucap = 500;
if (Loai == 0) //là giang vien
Luong = Hsluong * 730 * Phucap + Sotiet_Songaycong * 45;
else
Luong = Hsluong * 730 * Phucap + Sotiet_Songaycong * 30;
}
}

}

Tạo chương trình Main
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

System.Threading.Tasks;

namespace QL_CANBO
{
class Program
{


public class CanboComparer : IComparer<Canbo>
{
public int Compare(Canbo p, Canbo q)
{
int result = p.Luong.CompareTo(q.Luong);
if(result == 0)
result = p.Hoten.CompareTo(q.Hoten);
return result;

}
}
private static void XuatCB(List<Canbo> list)
{
Console.WriteLine("**Danh sach can bo (chua Sort)**");
for (int i = 0;i < list.Count; i++)
{
if(list[i].Loai == 0)
{
Console.WriteLine("{0} Ho ten Giang Vien: {1,20}",i+1,list[i].Hoten);
Console.WriteLine("\t* Khoa: " + list[i].Khoa_phban + ",*So tiet: " +
list[i].Sotiet_Songaycong);
Console.WriteLine("\t* Trinh do: "+list[i].Td_cv);

Console.WriteLine("\t* He so luong: "+list[i].Hsluong+",*phu
cap: "+list[i].Phucap);
Console.WriteLine("\t* Luong: "+list[i].Luong);
}
else
{
Console.WriteLine("{0} Ho ten Nhan Vien: {1,20}",i+1,list[i].Hoten);
Console.WriteLine("\t* Phong ban: " + list[i].Khoa_phban + ",*So ngay
cong: " + list[i].Sotiet_Songaycong);
Console.WriteLine("\t* Chuc vu: " + list[i].Td_cv);
Console.WriteLine("\t* He so luong: " + list[i].Hsluong +
",*phu cap: " + list[i].Phucap);
Console.WriteLine("\t* Luong: " + list[i].Luong);
}
}
}
private static void XuatCB2(List<Canbo> list)
{
Console.WriteLine("Danh Sach Can Bo (Sort theo Luong, Hoten)");
list.Sort(new CanboComparer());
for (int i = 0; i< list.Count; i++)
{
if (list[i].Loai == 0)
{
Console.WriteLine("{0} Ho Ten Giang Vien: {1,20}",i+1,list[i].Hoten);
Console.WriteLine("\t* Khoa: " + list[i].Khoa_phban + ", * So tiet: " +
list[i].Sotiet_Songaycong);
Console.WriteLine("\t* Trinh Do: " + list[i].Td_cv);
Console.WriteLine("\t* He So Luong: "+ list[i].Hsluong + ",* Phu
cap: "+ list[i].Phucap);

Console.WriteLine("\t* Luong: " + list[i].Luong);


}
else
{

Console.WriteLine("{0} Ho Ten Nhan Vien: {1,20}",i+1,list[i].Hoten);
Console.WriteLine("\t* Phong Ban: " + list[i].Khoa_phban + ", * So ngay
cong: " + list[i].Sotiet_Songaycong);
Console.WriteLine("\t* Chuc Vu: " + list[i].Td_cv);
Console.WriteLine("\t* He So Luong: " + list[i].Hsluong + ",
* Phu cap: " + list[i].Phucap);
Console.WriteLine("\t* Luong: " + list[i].Luong);
}
}
}
private static void XuatCB3(Canbo Item)
{
Console.WriteLine("***Thong Tin Can Bo Tim Thay***");
if(Item.Loai == 0)
{
Console.WriteLine("Ho Ten Giang Vien: " + Item.Hoten);
Console.WriteLine("\t* Khoa: " + Item.Khoa_phban + ", * So tiet: " +
Item.Sotiet_Songaycong);
Console.WriteLine("\t* Trinh Do: " + Item.Td_cv);
Console.WriteLine("\t* He So Luong: " + Item.Hsluong + ", *Phu cap:
" + Item.Phucap);
Console.WriteLine("\t* Luong: " + Item.Luong);
}

else
{
Console.WriteLine("Ho Ten Nhan Vien: " + Item.Hoten);
Console.WriteLine("\t* Phong Ban: " + Item.Khoa_phban + ", * So ngay
cong: " + Item.Sotiet_Songaycong);
Console.WriteLine("\t* Chuc Vu: " + Item.Td_cv);
Console.WriteLine("\t* He So Luong: " + Item.Hsluong + ", *
Phu cap: " + Item.Phucap);
Console.WriteLine("\t* Luong: " + Item.Luong);
}
}
private static void CreateNewCanbo(List<Canbo> list)
{
int mloai = 0, msotsonc = 0, n = 1;
string mhoten, mkhoaphban, mtdcv;
double mhsluong;
Console.Write("Cho biet so Can Bo: ");
n = Convert.ToInt16(Console.ReadLine());
list.Clear();
for (int i = 0; i < n; i++)
{
Console.Write("Cho biet loai (0: Giang Vien, 1: Nhan Vien):
");

mloai = Convert.ToInt16(Console.ReadLine());
if(mloai == 0)
{
Console.Write("Ho ten Giang vien: ");



Convert.ToString(Console.ReadLine());

mhoten = Convert.ToString(Console.ReadLine());
Console.Write("Khoa: ");
mkhoaphban =
Console.Write("Trinh do (Cu Nhan, Thac Si, Tien

Si): ");

Convert.ToDouble(Console.ReadLine());
}
else
{

Convert.ToString(Console.ReadLine());
Phong, Nhan Vien): ");

mtdcv = Convert.ToString(Console.ReadLine());
Console.Write("So Tiet: ");
msotsonc = Convert.ToInt16(Console.ReadLine());
Console.Write("He so luong: ");
mhsluong =

Console.Write("Ho Ten Nhan Vien: ");
mhoten = Convert.ToString(Console.ReadLine());
Console.Write("Phong Ban: ");
mkhoaphban =
Console.Write("Chuc Vu (Truong Phong, Pho
mtdcv = Convert.ToString(Console.ReadLine());
Console.Write("So Ngay Cong: ");

msotsonc = Convert.ToInt16(Console.ReadLine());
Console.Write("He So Luong: ");
mhsluong =

Convert.ToDouble(Console.ReadLine());
}
list.Add(new Canbo(mhoten, mloai, mkhoaphban, mtdcv,
msotsonc, mhsluong));
}
}
private static void SearchList(List<Canbo> list)
{
Console.Write("Nhap ho ten Can Bo can tim: ");
string mten = Convert.ToString(Console.ReadLine());
Console.Write("Nhap Khoa hoac Phong Ban can tim: ");
string mpban = Convert.ToString(Console.ReadLine());
mten);

Canbo Item = list.Find(c => c.Khoa_phban == mpban && c.Hoten ==
if (Item != null)
XuatCB3(Item);
else
Console.WriteLine(mten + " va " + mpban + " khong tim thay!");
}
static void Main(string[] args)
{
List<Canbo> list = new List<Canbo>(0);
int chon;
do
{

Console.Clear();
Console.WriteLine("1/. Nhap du lieu cho Can Bo Truong");
Console.WriteLine("2/. Tim kiem Nhan Vien");


Console.WriteLine("3/. Xuat Danh sach Can Bo co sap xep theo

(Luong, Hoten)");

Console.WriteLine("4/. Ket thuc chuong trinh");
Console.WriteLine("Nhan mot so tu 1 -> 4 de chon (^-^)");
chon = Convert.ToInt32(Console.ReadLine());
switch (chon)
{
case 1:
Console.Clear();
CreateNewCanbo(list);
XuatCB(list);
Console.ReadKey(); break;
case 2:
Console.Clear();
SearchList(list);
Console.ReadKey(); break;
case 3:
Console.Clear();
XuatCB2(list);
Console.ReadKey(); break;
}
} while (chon <=3);
}

}
}

Kết quả sau khi chạy chương trình



Nhấn số 1 để nhập dữ liệu cho Cán Bộ trường

Ví dụ nhập dữ liệu sau:


Số cán bộ : 3
Cán bộ 1
Họ tên : Lê Cảnh Phong
Cho biết loại: 0
Khoa: CNTT
Trình độ: Thạc sĩ
Số tiết: 55
Hệ số lương: 95
Cán bộ 2
Họ tên: Ngô Minh Hiếu
Cho biết loại: 0
Khoa: Ngôn ngữ Anh
Trình độ: Tiến sĩ
Số tiết: 70
Hệ số lương: 110
Cán bộ 3
Họ tên: Trần Tuấn Anh
Cho biết loại: 1

Khoa: Quản lý thiết bị
Chức vụ: Trưởng phòng
Số ngày công: 40
Hệ số lương: 60


 Nhấn Enter để quay lại, sau đó nhấn số 2 để tìm kiếm Nhân Viên
- Kết quả khi tìm thấy


-

Kết quả khi không tìm thấy Nhân Viên nào

 Nhấn Enter để quay lại, sau đó nhấn số 3 để Xuất danh sách Cán Bộ có sắp xếp

 Nhấn Enter để quay lại, sau đó nhấn số 4 để Thoát chương trình




×