Using Namespace Public Class Public String Public Int Public Float Public Public Void
Using Namespace Public Class Public String Public Int Public Float Public Public Void
namespace Baitap2
{
public class HS
{
public string ht;
public int ns;
public float tb;
public HS next;
public void nhapthongtin()
{
Console.Write("Nhap ho ten hoc sinh: ");
ht = Convert.ToString(Console.ReadLine());
Console.Write("Nhap nam sinh hoc sinh: ");
ns = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap diem trung binh: ");
tb = Convert.ToSingle(Console.ReadLine());
return;
}
public void inthongtin()
{
Console.WriteLine("HoTen: {0}",ht);
Console.WriteLine("NamSinh: {0}",ns);
Console.WriteLine("DiemTB: {0}",tb);
}
}
public class DS
{
public static void Main()
{
int cn = 1;
HS head = new HS();
HS q = head;
bool cds = false;
while(cn != 0)
{
Console.WriteLine("Ban hay chon mot trong cac
chuc nang");
Console.WriteLine("1_Nhap thong tin hoc sinh");
Console.WriteLine("2_In thong tin hoc sinh");
Console.WriteLine("3_Them mot hoc sinh moi vao
cuoi danh sach");
Console.WriteLine("4_Chen mot hoc sinh moi vao
dau danh sach");
Console.WriteLine("5_In thong tin cac hoc sinh
co nam sinh X->Y");
Console.WriteLine("6_In ra tien thuong hoc sinh
tien tien");
Console.WriteLine("7_In ra thong tin mot hoc
sinh");
Console.WriteLine("8_Cap nhat thong tin hoc
sinh");
Console.WriteLine("9_Dem so hoc sinh co diem tu
X->Y");
Console.WriteLine("10_Xoa thong tin mot hoc
sinh");
Console.WriteLine("11_Nhap thong tin hoc sinh
moi vao vi tri k");
Console.WriteLine("0_Ket thuc chuong trinh");
cn = Convert.ToInt32(Console.ReadLine());
if(cn == 1)
{
if(cds == false)
{
head.nhapthongtin();
cds = true;
}
else
{
q.next = new HS();
q.next.nhapthongtin();
q = q.next;
}
}
if(cn == 2)
{
HS k = head;
while(k != null)
{
k.inthongtin();
k = k.next;
}
Console.ReadLine();
}
if(cn == 3)
themds(ref head);
if(cn == 4)
chendds(ref head);
if(cn == 5)
inds(head);
if(cn == 6)
tientien(head);
if(cn == 7)
hocsinh(head);
if(cn == 8)
capnhat(head);
if(cn == 9)
demhs(head);
if(cn == 10)
xoa(ref head);
if(cn == 11)
chenhsm(ref head);
if(cn == 0)
{
Console.WriteLine("Cam on da dung thu
chuong trinh");
Console.ReadLine();
}
}
}
public static void themds(ref HS head)
{
HS q = head;
while(q.next != null)
q = q.next;
q.next = new HS();
q.next.nhapthongtin();
}
public static void chendds(ref HS head)
{
HS q = new HS();
q.nhapthongtin();
q.next = head;
head = q;
}
public static void inds(HS head)
{
HS q = head;
Console.Write("Nhap nam X: ");
int x = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap nam Y: ");
int y = Convert.ToInt32(Console.ReadLine());
while(q != null)
{
if(q.ns>=x&&q.ns<=y)
{
q.inthongtin();
}
q = q.next;
}
}
public static void tientien(HS head)
{
Console.Write("Nhap vao so tien thuong cho mot hoc
sinh: ");
int x = Convert.ToInt32(Console.ReadLine());
HS q = head;
int award = 0;
while(q != null)
{
if(q.tb > 6)
{
q.inthongtin();
award++;
}
q = q.next;
}
Console.Write("Tong so tien thuong la: {0}",award*x);
}
public static void hocsinh(HS head)
{
HS q = head;
Console.Write("Nhap ho ten hoc sinh can tim: ");
string x = Convert.ToString(Console.ReadLine());
while(q != null)
if(q.ht == x)
q.inthongtin();
}
public static void capnhat(HS head)
{
HS q = head;
Console.Write("Muon tim hoc sinh o vi tri thu may: ");
int k = Convert.ToInt32(Console.ReadLine());
for(int i = 1; i < k; i++)
q = q.next;
q.inthongtin();
Console.Write("Ban muon sua thong tin ho ten
ko?(Y/N)");
string h = Convert.ToString(Console.ReadLine());
if(h == "y")
{
Console.Write("Moi ban nhap lai ten: ");
q.ht = Convert.ToString(Console.ReadLine());
}
Console.WriteLine("Ban muon sua thong tin nam sinh
ko?(Y/N)");
string n = Convert.ToString(Console.ReadLine());
if(n == "y")
{
Console.Write("Moi ban nhap lai nam sinh: ");
q.ns = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Ban muon sua thong tin diem tb
ko?(Y/N)");
string d = Convert.ToString(Console.ReadLine());
if(d == "y")
{
Console.Write("Moi ban nhap lai diem: ");
q.tb = Convert.ToSingle(Console.ReadLine());
}
}
public static void demhs(HS head)
{
HS q = head;
Console.Write("Nhap diem trung binh thap nhat:" );
float x = Convert.ToSingle(Console.ReadLine());
Console.Write("Nhap diem trung binh cao nhat:" );
float y = Convert.ToSingle(Console.ReadLine());
int t = 0;
while(q != null)
{
if(q.tb>=x && q.tb<=y)
t++;
q = q.next;
}
Console.WriteLine("So hoc sinh co diem tb trong
khoang x->y: {0}",t);
}
public static void xoa(ref HS head)
{
HS q = head;
Console.Write("Ban muon xoa thong tin hoc sinh thu
may trong danh sach: ");
int k = Convert.ToInt32(Console.ReadLine());
for(int i = 1; i < k-1; i++)
q = q.next;
q.next = q.next.next;
}
public static void chenhsm(ref HS head)
{
HS q = head;
Console.Write("Nhap vao vi tri ma ban muon chen them
hoc sinh vao: ");
int k = Convert.ToInt32(Console.ReadLine());
for(int i = 1; i < k-1; i++)
q = q.next;
HS x = new HS();
x.nhapthongtin();
x.next = q.next;
q.next = x;
}
}
}