Tải bản đầy đủ (.doc) (23 trang)

bài tập nộp môn lâp trình.net1 ppt

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 (118.01 KB, 23 trang )

using System; bài thực hành1 (sơ đồ lớp bài 1)
using System.Collections.Generic;
using System.Linq;
using System.Text; bài1
namespace Bai_1
{
class Program
{
static void Main(string[] args)
{
Employee a = new Employee();
a.Input();
a.Display();
}
}
class Employee
{
int id;
string name;
int yearOfBirth;
double salaryLevel, basicSalary;
public static int _id = 1;
//public static double _basicSalary;
public Employee() { this.id = _id; _id++; }
public void getId()
{
this.id = _id; HỌ TÊN:VŨ XUÂN TRƯỜNG
LỚP :51TH1
} MSSV :51131780
public void getName(string name) ĐẠI HỌC NHA TRANG
{


this.name = name;
}
public void getYearOfBirth(int year)
Class
Employee(nhanvien
)
Int id
String name
Int year of birth
Double salary level,basic salary
Public void get id()
Public void get name(string
name)
Public void get year of
birth(int year)
Public double get in com()
Public void input()
Public void display()
Public void get level(double
level)
Public void get basic(double
basic)
{
this.yearOfBirth = year;
}
public double getIncome()
{
return salaryLevel * basicSalary;
}
public void Input()

{
name = Console.ReadLine();
yearOfBirth = int.Parse(Console.ReadLine());
salaryLevel = Convert.ToDouble(Console.ReadLine());
basicSalary = Convert.ToDouble(Console.ReadLine());
}
public void Display()
{
Console.WriteLine(id + " " + name + " " + yearOfBirth + " " +
basicSalary + " " + getIncome());
}
public void GetLevel(double level)
{
this.salaryLevel = level;
}
public void GetBasic(double basic)
{
this.basicSalary = basic;
}

}
}
Bài 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_2
{
class Program

{
static void Main(string[] args)
{
stack a = new stack(10);
a.Push(1); a.Push(112); a.Push(51); a.Push(14); a.Push(21);
a.Push(12);
while (!a.IsEmpty())
{
Console.WriteLine(a.Pop() + " ");
}
}
} (sơ đồ lớp bài 2)
class stack
{
int[] ST;
int size, posTop;

public stack()
{
size = 20; ST = new int[size];
posTop = 0;
}
public stack(int size)
{
this.size = size;
ST = new int[size];
posTop = 0;
}
public bool IsEmpty()
{

if (posTop == 0) return true;
return false;
}
public bool IsFull()
{
if (posTop == size) return true;
return false;
}
public void Push(int x)
{
if (IsFull()) return;
ST[posTop++] = x;
}
public int Pop()
{
if (IsEmpty()) return int.MinValue;
return ST[ posTop];
}
}
}
Bài 3
using System;
using System.Collections.Generic;
Class stack
Int[] ST;
Int size,posTop;
Public stack()
Public stack(int size)
Public bool IsEmpty()
Public bool IsFull()

Public void Push(int x)
Public int Pop()
using System.Linq;
using System.Text; (sơ đồ lớp bài 3)
namespace Bai_3
{
class Program
{
static void Main(string[] args)
{
ComPlex a = new ComPlex(4, -2);
ComPlex b = new ComPlex(2,-4);
ComPlex c = new ComPlex();
c = a + b;
c.Display();
c = a - b;
c.Display();
}
}
class ComPlex
{
double real, imag;
public ComPlex() { }
public ComPlex(int real, int imag)
{
this.real = real; this.imag = imag;
}
public void Display()
{
if (imag == 0) Console.WriteLine("z = " + real);

else
{
string s;
if (imag < 0) s = " - ";
else s = " + ";
Console.WriteLine("z = " + real + s + Math.Abs(imag) +
"i");
}
}
public ComPlex Cong(ref ComPlex a)
{
ComPlex tam = new ComPlex();
Class ComPlex NumBer
Double real,imag;
Public Void display()
Public ComPlex Cong(ref
ComPlex a)
Public static ComPlex
operator +(ComPlex
a,ComPlex b)
Public static ComPlex
operator -(ComPlex
a,ComPlex b)
tam.real = real + a.real;
tam.imag = imag + a.imag;
return tam;
}
public static ComPlex operator +(ComPlex a,ComPlex b)
{
ComPlex res = new ComPlex();

res.real = a.real + b.real;
res.imag = a.imag + b.imag;
return res;
}
public static ComPlex operator -(ComPlex a, ComPlex b)
{
ComPlex res = new ComPlex();
res.real = a.real - b.real;
res.imag = a.imag - b.imag;
return res;
}
}
}
Bài4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_4
{
class Program (sơ đồ lốp bài4)
{
static void Main(string[] args)
{
chuyen10sang16 a = new chuyen10sang16();
a.Nhap();
a.Process();
}
Class chuyen10sang16
Class stack

Int n;
Int tam;
Int [] st;
Int size,postop;
Public void Nhap()
Public void process()
Public bool IsEmpty()
Public bool IsFull()
Public void push(int x)
Public void hienthi()
}
class chuyen10sang16
{
int n;
stack s = new stack(10);
public void Nhap()
{
n = int.Parse(Console.ReadLine());
}
public void Process()
{
while (n != 0)
{
s.Push(n % 16);
n /= 16;
};
int tam;
string s1 = "";
while (!s.IsEmpty())
{

tam = s.Pop();
if(tam > 9)s1+= (char)(tam - 10 + 65);
else s1 += (char)(tam + 48);
}
Console.WriteLine("He 16: " + s1);
}
}
class stack
{
int[] ST;
int size, posTop;
public stack()
{
size = 20; ST = new int[size];
posTop = 0;
}
public stack(int size)
{
this.size = size;
ST = new int[size];
posTop = 0;
}
public bool IsEmpty()
{
if (posTop == 0) return true;
return false;
}
public bool IsFull()
{
if (posTop == size) return true;

return false;
}
public void Push(int x)
{
if (IsFull()) return;
ST[posTop++] = x;
}
public int Pop()
{
if (IsEmpty()) return int.MinValue;
return ST[ posTop];
} (sơ đồ lớp bài5)
}
}
Bài 5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PhanSo
{
class Program
{
static void Main(string[] args)
{

PhanSo a = new PhanSo(3,4);
PhanSo b = new PhanSo(1,2);
Console.Write("Phan so thu 1: ");
a.Xuat();

Console.Write("Phan so thu 2: ");
b.Xuat();
PhanSo c = new PhanSo();
Console.Write("Cong 2 phan so: ");
c.Cong(a,b);
c.Xuat();
Console.Write("Cong phan so voi (c + 2): ");
c.Cong(2);
c.Xuat();
Console.Write("Tru 2 phan so: ");
c.Tru(a, b);
Class
phanso:ICloneable
Int tu
Int mau
Public Void xuat()
Public Void copy(Phanso a)
Public object ()
Public phanso cong(int a)
Public phanso tru(phan so
a,phan so b)
Public phanso nhan(phan so
a,phan so b)
Public phanso chia(phan so
a,phan so b)
c.Xuat();
Console.Write("Nhan 2 phan so: ");
c.Nhan(a, b);
c.Xuat();
Console.Write("Chia 2 phan so: ");

c.Chia(a, b);
c.Xuat();
}
}
class PhanSo:ICloneable
{
int tu, mau;
public PhanSo() { tu = 0; mau = 1; }
public PhanSo(int tu, int mau)
{
if (mau == 0) throw new Exception("Khoi tao khong dung!");
this.tu = tu; this.mau = mau;
}
public void Xuat()
{
Console.WriteLine(tu + "/" + mau);
}
public void Copy(PhanSo a)
{
this.tu = a.tu; this.mau = a.mau;
}
public object Clone()
{
return MemberwiseClone();
}
public int ucln(int a, int b)
{
a = Math.Abs(a); b = Math.Abs(b);
if (b == 0) return a;
return ucln(b, a % b);

}
public PhanSo Cong(PhanSo a, PhanSo b)
{
this.tu = b.tu * a.mau + b.mau * a.tu;
this.mau = b.mau * a.mau;
int tam = ucln(this.tu, this.mau);
this.tu /= tam; this.mau /= tam;
return this;
}
public PhanSo Cong(int a)
{
this.tu = this.tu + this.mau * a;
int tam = ucln(this.tu, this.mau);
this.tu /= tam; this.mau /= tam;
return this;
}
public PhanSo Tru(PhanSo a, PhanSo b)
{
this.tu = b.mau * a.tu - b.tu * a.mau;
this.mau = b.mau * a.mau;
int tam = ucln(this.tu, this.mau);
this.tu /= tam; this.mau /= tam;
return this;
}
public PhanSo Nhan(PhanSo a, PhanSo b)
{
this.tu = a.tu * b.tu;
this.mau = b.mau * a.mau;
int tam = ucln(this.tu, this.mau);
this.tu /= tam; this.mau /= tam;

return this;
}
public PhanSo Chia(PhanSo a, PhanSo b)
{
this.tu = a.tu * b.mau;
this.mau = a.mau * b.tu;
int tam = ucln(this.tu, this.mau);
this.tu /= tam; this.mau /= tam;
return this;
}
}
}
Bài thực hành số 2
Bài1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_1
{
class Program
{
static void Main(string[] args)
{
PhanSo a = new PhanSo(3, 5);
PhanSo b = new PhanSo(1, 3);
PhanSo c = new PhanSo();
c = a + b; c.Xuat();
c = a - b; c.Xuat();
c = a * b; c.Xuat();

c = a / b; c.Xuat();
c = a + 3; c.Xuat();
c = 4 + b; c.Xuat();
c = a - 2; c.Xuat();
c = 1 - b; c.Xuat();
c = a * 3; c.Xuat();
c = b * 2; c.Xuat();
c = a / 5; c.Xuat();
c = 4 / b; c.Xuat();
PhanSo d = new PhanSo();
d = (PhanSo)a.Clone();
d.Xuat(); (sơ đồ lớp bài 1)
}
}
class PhanSo : ICloneable
{
int tu, mau;
public PhanSo() { }
public PhanSo(int tu, int mau)
{
this.tu = tu; this.mau = mau;
}
public void Nhap()
{
do
{
Console.Write("Nhap tu: ");
tu = int.Parse(Console.ReadLine());
Console.Write("Nhap mau: ");
Class

phanso:ICloneable
Int tu;
Int ucln(int a,int b)
Int mau;
Public Void nhap()
Public Void xuat()
Public Void rutgon()
Public phanso(){}
Public static phanso
operator +(phanso
a,phanso b)
Public static phanso
operator +(phanso a,int
b)
Public static phanso
operator +(int b,phanso
a)
Public static phanso
operator -(phanso
a,phanso b)
Public static phanso
operator -(phanso a,int
b)
Public static phanso
operator -(int b,phanso
a)
public static PhanSo
operator *(PhanSo a,
PhanSo b)
public static PhanSo

operator *(PhanSo a, int
b)
public static PhanSo
operator /(PhanSo a,
PhanSo b)
public static PhanSo
operator /(PhanSo a,int
b)
public static PhanSo
operator /(int b,
PhanSoa)
mau = int.Parse(Console.ReadLine());
} while (mau == 0);
}
public int ucln(int a, int b)
{
a = Math.Abs(a);
b = Math.Abs(b);
if (b == 0) return a;
return ucln(b, a % b);
}
public void Xuat()
{
Console.WriteLine(tu + "/" + mau);
}
public void RutGon()
{
int r = ucln(Math.Abs(tu), Math.Abs(mau));
tu /= r; mau /= r;
}

public static PhanSo operator +(PhanSo a, PhanSo b)
{
int tu, mau;
mau = a.mau * b.mau;
tu = a.tu * b.mau + b.tu * a.mau;
PhanSo Res = new PhanSo(tu, mau);
return Res;
}
public static PhanSo operator +(PhanSo a, int b)
{
int tu, mau;
mau = a.mau;
tu = a.tu + b * a.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator +(int b, PhanSo a)
{
int tu, mau;
mau = a.mau;
tu = a.tu + b * a.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator -(PhanSo a, PhanSo b)
{
int tu, mau;
mau = a.mau * b.mau;

tu = a.tu * b.mau - b.tu * a.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator -(PhanSo a, int b)
{
int tu, mau;
mau = a.mau;
tu = a.tu - b * a.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator -(int b, PhanSo a)
{
int tu, mau;
mau = a.mau;
tu = b * a.mau - a.tu;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator *(PhanSo a, PhanSo b)
{
int tu, mau;
mau = a.mau * b.mau;
tu = a.tu * b.tu;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();

return Res;
}
public static PhanSo operator *(PhanSo a, int b)
{
int tu, mau;
mau = a.mau;
tu = a.tu * b;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator *(int b, PhanSo a)
{
int tu, mau;
mau = a.mau;
tu = a.tu * b;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator /(PhanSo a, PhanSo b)
{
int tu, mau;
mau = a.mau * b.tu;
tu = a.tu * b.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator /(PhanSo a, int b)

{
int tu, mau;
mau = a.mau * b;
tu = a.tu;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator /(int b, PhanSo a)
{
int tu, mau;
tu = a.mau * b;
mau = a.tu;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public object Clone()
{
return MemberwiseClone();
}
} (sơ đồ lớp bài 2)
}
Bài 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_2
{

class Program
{
static void Main(string[] args)
{
QuanLyHocSinh a = new QuanLyHocSinh();
a.Nhap();
a.Xuat();
a.Process();
}
}
class Hocsinh
{
string hoTen;
double dtoan, dly, dhoa;
public Hocsinh() { }
public Hocsinh(string hoTen, double dtoan, double dly, double dhoa)
{
this.hoTen = hoTen; this.dtoan = dtoan; this.dly = dly;
this.dhoa = dhoa;
}
public void Nhap()
{
Console.Write("Nhap ten: ");
hoTen = Console.ReadLine();
Console.Write("Nhap diem toan: ");
dtoan = int.Parse(Console.ReadLine());
Console.Write("Nhap diem ly: ");
dly = int.Parse(Console.ReadLine());
Console.Write("Nhap diem hoa: ");
dhoa = int.Parse(Console.ReadLine());

}
public double TB()
{
return (dtoan + dly + dhoa)/3;
Class hoc sinh
Class quan ly hoc
sinh
String hoten
Double dtoan,dly,dhoa;
Int number;
Public void nhap()
Public double TB()
Public void xuat()
Public void process()
}
public void xuat()
{
Console.WriteLine(hoTen + " " + dtoan + " " + dly + " " +
dhoa);
}
}
class QuanLyHocSinh
{
int number;
Hocsinh[] ds;
public void Nhap()
{
Console.Write("Nhap so hoc sinh: "); number =
int.Parse(Console.ReadLine());
ds = new Hocsinh[number];

for (int i = 0; i < number; i++)
{
ds[i] = new Hocsinh();
ds[i].Nhap();
}
}
public void Xuat()
{
Console.WriteLine("Danh sach vua nhap: ");
for (int i = 0; i < number; i++) ds[i].xuat();
}
public void Process()
{
bool ok = false;
for (int i = 0; i < number;i++ )
if (ds[i].TB() < 5) { ok = true; break; }
if (ok == true)
{
Console.WriteLine("Danh Sach thi sinh phai thi lai: ");
Console.WriteLine();
for (int i = 0; i < number; i++)
if (ds[i].TB() < 5)
{
ds[i].xuat();
}
}
else Console.WriteLine("Khong co thi sinh nao phai thi lai!");
}
}
}

Bài 3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_3
{
class Program
{
static void Main(string[] args)
{
QuanlyNhanvien a = new QuanlyNhanvien();
a.Nhap();
a.HienThi(); (sơ đồ lớp bài 3)
a.HeSoLuongCaoNhat();
a.TangDan_HeSoLuong();
a.HienThi();
}
}
class NhanVien
{
string hoTen, queQuan;
public double heSoluong { get; set; }
double luongCoban;
public static double _luongcoban = 500000;
public NhanVien(){luongCoban = _luongcoban;}
public void Nhap()
{
Console.Write("Nhap ten: ");
hoTen = Console.ReadLine();

Console.Write("Nhap que quan: ");
queQuan = Console.ReadLine();
Console.Write("Nhap he so luong: ");
heSoluong = Convert.ToDouble(Console.ReadLine());
}
public void Hienthi()
{
Console.WriteLine(hoTen + " "+ queQuan + " "+heSoluong+" " +
Luong());
}
public double Luong()
{
return heSoluong * luongCoban;
}
}
class QuanlyNhanvien
{
int number;
NhanVien[] ds;
public void Nhap()
{
Class nhanvien
Class quanlynhanvien
String hoten,quequan;
Double hesoluong{get;set;}
Double luongcoban;
Int number
Public Void nhap()
Public Void hienthi()
Public void hesoluongcaonhat()

Public void tangdanhesoluong()
Console.Write("Nhap so nhan vien: "); number =
int.Parse(Console.ReadLine());
ds = new NhanVien[number];
for (int i = 0; i < number; i++)
{
ds[i] = new NhanVien();
ds[i].Nhap();
}
}
public void HienThi()
{
Console.WriteLine("Danh sach nhan vien: ");
Console.WriteLine();
for (int i = 0; i < number; i++) ds[i].Hienthi();
}
public void HeSoLuongCaoNhat()
{
double max = 0;
for (int i = 0; i < number; i++)
if (ds[i].heSoluong > max) max = ds[i].heSoluong;
Console.WriteLine("Nhung nguoi co he so luong cao nhat: ");
for (int i = 0; i < number; i++)
if (ds[i].heSoluong == max) ds[i].Hienthi();
}
public void TangDan_HeSoLuong()
{
int i,j;
double tam;
for(i=0;i<number - 1;i++)

for(j=i+1;j<number;j++)
if (ds[i].heSoluong > ds[j].heSoluong)
{
tam = ds[i].heSoluong;
ds[i].heSoluong = ds[j].heSoluong;
ds[j].heSoluong = tam;
}
}
}
}
Bài 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text (sơ đồ lớp bài4 )
namespace Bai_4
{
class Program
{
static void Main(string[] args)
{
QuanLy a = new QuanLy();
a.Nhap();
a.Xuat();
a.Xuat_LuanVan();
a.Xuat_TotNghiep();
a.Xuat_ThiLai();
}
}
class MonHoc

{
string tenMonhoc;
double tylekiemtra;
double diemkiemtra, diemthi;
public MonHoc() { }
public void Nhap()
{
Console.Write("Nhap ten mon hoc: "); tenMonhoc =
Console.ReadLine();
Console.Write("Ty le kiem tra: "); tylekiemtra =
Convert.ToDouble(Console.ReadLine());
Console.Write("Diem kiem tra: "); diemkiemtra =
Convert.ToDouble(Console.ReadLine());
Console.Write("Diem thi: "); diemthi =
Convert.ToDouble(Console.ReadLine());
}
public void Xuat()
{
Console.WriteLine(tenMonhoc + " " + tylekiemtra + " "
+diemkiemtra + " " + diemthi + " " + DiemTB());
}
Class monhoc
Class hocvien
Class quanly
String tenmonhoc;
Double tylekiemtra;
Double diemkiemtra,diemthi;
String hoten;
Int namsinh;
Int number;

Public void nhap()
Public void xuat()
Public Double tb()
Public void xuatluanvan()
Public void
xuattotnghiep()
Public void xuatthilai()
public double DiemTB()
{
return diemkiemtra * tylekiemtra + diemthi * (1 - tylekiemtra);
}
}
class HocVien
{
string hoTen;
int namSinh;
MonHoc[] mh;
int number;
public void Nhap()
{
Console.Write("Nhap ho ten: "); hoTen = Console.ReadLine();
Console.Write("Nhap nam sinh: "); namSinh =
int.Parse(Console.ReadLine());
Console.Write("NHap so mon hoc: "); number =
int.Parse(Console.ReadLine());
mh = new MonHoc[number];
for (int i = 0; i < number; i++)
{
mh[i] = new MonHoc();
mh[i].Nhap();

}
}
public void Xuat()// xuat diem trung binh cua tung mon hoc moi hoc
vien
{
Console.WriteLine(hoTen + " "+namSinh);
for (int i = 0; i < number; i++) mh[i].Xuat();
Console.WriteLine("Diem trung binh: " + TB());
}
public double TB()
{
double tong = 0;
for (int i = 0; i < number; i++) tong += mh[i].DiemTB();
return tong / number;
}
public bool KT_DiemTB()
{
for (int i = 0; i < number; i++)
if (mh[i].DiemTB() < 5) return false;
return true;
}
}
class QuanLy
{
int number;
HocVien[] ds;
bool[] danhDau;
public void Nhap()
{
Console.Write("Nhap so hoc vien: ");

number = int.Parse(Console.ReadLine());
ds = new HocVien[number];
danhDau = new bool[number];
for (int i = 0; i < number; i++)
{
ds[i] = new HocVien();
danhDau[i] = true;
ds[i].Nhap();
}
}
public void Xuat()
{
Console.WriteLine();
for (int i = 0; i < number; i++) ds[i].Xuat();
}
public void Xuat_LuanVan()
{
Console.WriteLine();
Console.WriteLine("Danh sach lam luan van: ");
for (int i = 0; i < number; i++)
if (ds[i].TB() > 7 && ds[i].KT_DiemTB() == true &&
danhDau[i] == true) { ds[i].Xuat(); danhDau[i] = false; }
}
public void Xuat_TotNghiep()
{
Console.WriteLine();
Console.WriteLine("Danh sach thi tot nghiep: ");
for (int i = 0; i < number; i++)
if (ds[i].TB() > 5 && ds[i].KT_DiemTB() == true &&
danhDau[i] == true) { ds[i].Xuat(); danhDau[i] = false; }

}
public void Xuat_ThiLai()
{
Console.WriteLine();
Console.WriteLine("Danh sach bi thi lai: ");
for (int i = 0; i < number; i++)
if (ds[i].KT_DiemTB() == false && danhDau[i] == true)
{ ds[i].Xuat(); danhDau[i] = false; }
}
}
}
Bài 5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_5
{
class Program
{
static void Main(string[] args)
{
/*
Nguoi a = new Nguoi("a", 1991, 1.67, 76);
a.Xuat();

Console.WriteLine("Tinh trang suc khoe: " +
a.TinhTrangSucKhoe());
double tam = a + 12;
Console.WriteLine("So can khi tang them 12 can: " + tam);

// nguoi b copy tu nguoi a qua.
Nguoi b = new Nguoi(a);
b.Xuat();
// Neu nhu ban dua data vao la: Nguoi a = new
Nguoi("a",1991,1.56,198); thi no se nem ngoai le.//
(sơ đồ lớp bài5)
b.ToString();

// thu nghiem
ThuNghiem t = new ThuNghiem();
t.Nhap();
t.HienThi();
t.Hienthi(1.7, 70);
t.Process();
*/
Nguoi a = new Nguoi("dophuchao", 1991, 1.7, 52);
Console.WriteLine(a.ToString());
}
}
class Nguoi
{
public string hoTen{get;set;}
public int namSinh { get; set; }
double chieuCao, trongLuong;
public double ChieuCao
{
get {return chieuCao;}
set
{
if (value < 1.2 || value > 1.8) throw new Exception("Nhap

sai roi.");
else chieuCao = value;
}
}
public double TrongLuong
{
Class nguoi
Class thunghiem
String hoten{get;set;}
Int namsinh{get;set;}
Double chieucao,trongluong;
Double k;
Public void xuat()
Public void hienthi()
Public nguoi(){}
Public int tinhtrangsuckhoe()
Public override string to
string()
Public void process()
get { return trongLuong; }
set
{
if (value < 35 || value > 150) throw new Exception("Nhap
sai roi.");
else trongLuong = value;
}
}
public Nguoi() { }
public Nguoi(string hoTen, int namSinh, double chieuCao, double
trongLuong)

{
this.hoTen = hoTen; this.namSinh = namSinh; this.chieuCao =
chieuCao; this.trongLuong = trongLuong;
}
public Nguoi(Nguoi toCopy)
{
hoTen = toCopy.hoTen;
namSinh = toCopy.namSinh;
ChieuCao = toCopy.ChieuCao;
TrongLuong = toCopy.TrongLuong;
}
public int TinhTrangSucKhoe()
{
double K;
K = trongLuong / (chieuCao * chieuCao);
if (K < 19) return -1;// yeu
if (K > 25) return 1;// manh
return 0;// binh thuong
}
public static double operator +(Nguoi a, Nguoi b)
{
return a.TrongLuong + b.TrongLuong;
}
public static double operator +(Nguoi a, double b)
{
return a.TrongLuong + b;
}
public static double operator +(double a, Nguoi b)
{
return a + b.TrongLuong;

}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Ho Ten : " + hoTen);
sb.AppendLine("Nam Sinh : " + namSinh);
sb.AppendLine("Chieu Cao : " + ChieuCao);
sb.AppendLine("Trong Luong : " + TrongLuong);
return sb.ToString();
}
public void Xuat()
{
Console.WriteLine(hoTen + " "+ namSinh +" "+chieuCao+"
"+trongLuong);
}
}
class ThuNghiem
{
Nguoi[] a = new Nguoi[5];
public void Nhap()
{
a[0] = new Nguoi("DoPhucHao", 1991, 1.69, 52);
a[1] = new Nguoi("NguyenHuuTung", 1991, 1.71, 58);
a[2] = new Nguoi("NguyenTrongKhiem", 1991, 1.70, 52);
a[3] = new Nguoi("NguyenHoHaiTrieu", 1991, 1.73, 72);
a[4] = new Nguoi("NguyenThanhPhu", 1989, 1.75, 74);
}
public void HienThi()
{
Console.WriteLine();

Console.WriteLine("Danh sach vua nhap: "); Console.WriteLine();
for (int i = 0; i < 5; i++) a[i].Xuat();
}
public void Hienthi(double cc,double tl)
{
Console.WriteLine();
Console.WriteLine("Danh sach chieu cao > " + cc + " va trong
luong > " + tl + " la: "); Console.WriteLine();
for (int i = 0; i < 5; i++)
if(a[i].ChieuCao >= cc && a[i].TrongLuong >=
tl)a[i].Xuat();
}
public void Process()
{
double tam;
Console.WriteLine();
Console.WriteLine("Danh SAch nhung nguoi can tang can de dat
the trang tot: "); Console.WriteLine();
for(int i=0;i<5;i++)
if (a[i].TinhTrangSucKhoe() == -1)
{
tam = (a[i].ChieuCao * a[i].ChieuCao) * 19 -
a[i].TrongLuong;
a[i].Xuat();
Console.WriteLine("So kg phai tang them: " + tam);
}
}
}
}

×