Skip navigation.

Log in | Sign up

Đời sinh viên >.<

Tìm điểm TB max tuổi min các học sinh

-ĐỀ: tạo class mảng sinh viên yêu cầu sau.
1. Tìm học sinh có điểm trung bình lớn nhất.
2.Tim hoc sinh có tuổi nhỏ nhất.
Bài giải click Read more...


Lớp học sinh
class HocSinh
{
//thuoc tinh
private String _maHocSinh;
private String _tenHocSinh;
private DateTime _ngaySinh;
private String _diaChi;
private float _diemToan;
private float _diemLy;
private float _diemHoa;
//property
public String MaHocSinh
{
get { return this._maHocSinh; }
set { this._maHocSinh = value; }
}
public String TenHocSinh
{
get { return this._tenHocSinh; }
set { this._tenHocSinh = value; }
}
public DateTime NgaySinh
{
get { return this._ngaySinh; }
set { this._ngaySinh = value; }
}
public String DiaChi
{
get { return this._diaChi; }
set { this._diaChi = value; }
}
public float DiemToan
{
get { return this._diemToan; }
set { this._diemToan = value; }
}
public float DiemLy
{
get { return this._diemLy; }
set { this._diemLy = value; }
}
public float DiemHoa
{
get { return this._diemHoa; }
set { this._diemHoa = value; }
}
//PT khoi tao
public HocSinh()
{
this._maHocSinh = "?";
this._tenHocSinh = "?";
this._ngaySinh = new DateTime(1988, 5, 20);
this._diaChi = "?";
this._diemToan = 0;
this._diemLy = 0;
this._diemHoa = 0;
}
public HocSinh( String maHocSinh,String tenHocSinh,
DateTime ngaySinh,String diaChi,
float diemToan,float diemLy,float diemHoa)
{
this._tenHocSinh = tenHocSinh;
this._maHocSinh = maHocSinh;
this._diaChi = diaChi;
this._ngaySinh = ngaySinh;
this._diemToan = diemToan;
this._diemLy = diemLy;
this._diemHoa = diemHoa;
}
public HocSinh(HocSinh hs)
{
this._maHocSinh = hs._maHocSinh;
this._tenHocSinh = hs._tenHocSinh;
this._ngaySinh = hs._ngaySinh;
this._diaChi = hs._diaChi;
this._diemHoa = hs._diemHoa;
this._diemLy = hs._diemLy;
this._diemToan = hs._diemToan;
}
//Nhap
public void Nhap()
{
Console.Write("nhap MHS:");
this._maHocSinh = Console.ReadLine();
Console.Write("nhap HOTEN:");
this._tenHocSinh = Console.ReadLine();
Console.Write("nhap NGAYSINH:");
String temp = Console.ReadLine();
String[] anstr = temp.Split('/');
int ngay = int.Parse(anstr[0]);
int thang = int.Parse(anstr[1]);
int nam = int.Parse(anstr[2]);
Console.Write("Nhap dia chi: ");
this._diaChi=Console.ReadLine();
this._ngaySinh = new DateTime(nam, thang, ngay);
Console.Write("Nhap diem toan: ");
this._diemToan = float.Parse(Console.ReadLine());
Console.Write("Nhap diem ly: ");
this._diemLy = float.Parse(Console.ReadLine());
Console.Write("Nhap diem hoa: ");
this._diemHoa = float.Parse(Console.ReadLine());

}
public void GanMaHocSinh(String maHocSinh)
{
this._maHocSinh = maHocSinh;
}
public void GanTenHocSinh(String tenHocSinh)
{
this._tenHocSinh = tenHocSinh;
}
public void GanDiaChi(String diaChi)
{
this._diaChi=diaChi;
}
public void GanNgaySinh(DateTime ngaySinh)
{
this._ngaySinh = ngaySinh;
}
public void GanDiemToan(float diemToan)
{
this._diemToan = diemToan;
}
public void GanDiemLy(float diemLy)
{
this._diemToan = diemLy;
}
public void GanDiemHoa(float diemHoa)
{
this._diemHoa = diemHoa;
}
//Xuat
public void Xuat()
{
Console.Write("Ma hoc sinh: {0}",this._maHocSinh);
Console.Write("Ten hoc sinh: {0}",this._tenHocSinh);
Console.Write("Ngay sinh: {0}",this._ngaySinh);
Console.Write("Dia chi: {0}",this._diaChi);
Console.Write("Diem toan: {0}",this._diemToan);
Console.Write("Diem ly: {0}",this._diemLy);
Console.Write("Diem hoa: {0}",this._diemHoa);
}
public String LayMaHocSinh()
{
return this._maHocSinh;
}
public String LayTenhocSinh()
{
return this._tenHocSinh;
}
public String LayDiaChi()
{
return this._diaChi;
}
public DateTime LayNgaySinh()
{
return this._ngaySinh;
}
public float LayDiemToan()
{
return this._diemToan;
}
public float LayDiemLy()
{
return this._diemLy;
}
public float LayDiemHoa()
{
return this._diemHoa;
}
//PT nghiep cu
public float DiemTrungBinh()
{
float diemTB;
diemTB=(this._diemToan + this._diemLy + this._diemHoa) / 3;
return diemTB;
}

}
Lớp mảng học sinh.
class MangHocSinh
{
//thuoc tinh
private HocSinh[] _hSinh;
//property
public HocSinh[] HSinh
{
get { return this._hSinh; }
set{this._hSinh=value;}
}
public HocSinh this[int index]
{
get { return this._hSinh[index]; }
set { this._hSinh[index] = value; }
}
public int N
{
get { return this._hSinh.Length; }
}
//PT khoi tao (ham dung)
public MangHocSinh()
{
this._hSinh=null;
}
public MangHocSinh(params HocSinh[] hSinh)
{
this._hSinh = new HocSinh[hSinh.Length];
for (int i = 0; i < hSinh.Length; i++)
{
this._hSinh = new HocSinh(hSinh);
}
}
public MangHocSinh(int soHSinh)
{
this._hSinh=new HocSinh[soHSinh];
for(int i=0;i<this._hSinh.Length;i++)
{
this._hSinh = new HocSinh();
}

}
public MangHocSinh(MangHocSinh hSinh)
{
this._hSinh = new HocSinh[hSinh._hSinh.Length];
for (int i = 0; i < hSinh._hSinh.Length; i++)
{
this._hSinh = new HocSinh(hSinh._hSinh);
}
}
public void Nhap()
{
Console.Write("Nhap so hoc sinh: ");
int n=int.Parse(Console.ReadLine());
this._hSinh=new HocSinh[n];
for (int i = 0; i < this._hSinh.Length; i++)
{
this._hSinh = new HocSinh();
Console.WriteLine("Hoc sinh thu {0}", i + 1);
this._hSinh.Nhap();
}
}
public void Xuat()
{
foreach(HocSinh hSinh in this._hSinh )
{
hSinh.Xuat();
}
}
public HocSinh TuoiNhoNhat()
{
HocSinh hSinh = new HocSinh();
DateTime dTime = this._hSinh[0].NgaySinh;
for (int i = 0; i < this._hSinh.Length; i++)
{
if ((DateTime.Now.Year - dTime.Year) > (DateTime.Now.Year - this._hSinh.NgaySinh.Year))
dTime = this._hSinh.NgaySinh;
hSinh = new HocSinh(this._hSinh);
}
return hSinh;
}
public HocSinh DiemTrungBinhLonNhat()
{
HocSinh hSinh = new HocSinh();
float diemTB = 0;
for (int i = 0; i < this._hSinh.Length; i++)
{
if (diemTB<this._hSinh.DiemTrungBinh() )
{
diemTB = this._hSinh.DiemTrungBinh();
hSinh=new HocSinh(this._hSinh);
}
}
return hSinh;
}
}

Ngày Đẹp...Khoe HàngMất Em

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

December 2009
M T W T F S S
November 2009January 2010
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31