Mã:
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
typedef struct SinhVien
{
char MaSV[10];
char HoTen[30];
char Quequan[30];
int Ngaysinh;
float DiemTB;
struct SinhVien *Tiep;
} Nut;
typedef Nut *TroNut;
Nut *dau, *cuoi;
void themDau(char masv[],char hoten[],char qq[],int ns, float diemtb) // Them SV vao dau
{
Nut *p = (Nut *)malloc(sizeof(Nut));
strcpy(p->HoTen, hoten);
strcpy(p->MaSV, masv);
strcpy(p->Quequan, qq);
p->DiemTB = diemtb;
p->Ngaysinh = ns;
p->Tiep = dau;
dau = p;
}
void themCuoi(char masv[],char hoten[],char qq[],int ns, float diemtb) // Them SV vao cuoi
{
Nut *p = (Nut *)malloc(sizeof(Nut));
strcpy(p->HoTen, hoten);
strcpy(p->MaSV, masv);
strcpy(p->Quequan, qq);
p->DiemTB = diemtb;
p->Ngaysinh = ns;
p->Tiep = NULL;
if (dau == NULL)
dau = p;
else
cuoi->Tiep = p;
cuoi = p;
}
void taoDS() // Tao Danh Sach
{
char hoten[30];
char masv[10];
char qq[30];
float diemtb;
int ns;
dau = NULL; cuoi = NULL;
do
{
cout<<"Nhap ho ten: ";
gets(hoten);
if (hoten[0])
{
cout<<"ma SV : ";
gets(masv);
cout<<"Que Quan : ";
gets(qq);
cout<<"Ngay Sinh : ";
cin>>ns;
cout<<"diem TB: ";
cin>>diemtb;
themCuoi(hoten,masv,qq,ns,diemtb);
}
} while (hoten[0]);
}
void xoaNut(int x) // Xoa SV o dau DS va cuoi DS , Xoa SV co MaSV la x
{
Nut *p, *q;
if (dau == NULL) return;
if (cuoi == NULL) return;
if (dau->MaSV[10]==x)
{
p = dau;
dau = dau->Tiep;
free(p);
}
else
{
q = dau;
p = dau->Tiep;
while (p != NULL && p->MaSV[10]!=x)
{
q = p;
p = p->Tiep;
}
if (p != NULL)
{
q->Tiep = p->Tiep;
free(p);
}
}
if(cuoi->MaSV[10]==x)
{
p=cuoi;
cuoi=cuoi->Tiep;
free(p);
}
else
{
q=cuoi;
p=cuoi->Tiep;
while (p != NULL && p->MaSV[10]!=x)
{
q=p;
p=p->Tiep;
}
if (p != NULL)
{
q->Tiep=p->Tiep;
free(p);
}
}
}
void themSV(TroNut &dau, char x)
{
TroNut p = (TroNut)malloc(sizeof(Nut));
p->HoTen[30]=x;
if (dau == NULL || (dau != NULL && dau->HoTen[30]> x))
{
p->Tiep = dau;
dau = p;
}
else
{
TroNut q = dau;
while (q->Tiep != NULL && q->Tiep->HoTen[30]< x)
q = q->Tiep;
p->Tiep = q->Tiep;
q->Tiep = p;
}
}
void Sapxep(int DiemTB[],int n) // Sap xep tang dan theo DTB
{
int i,j;
for (i=1;i<n;i++)
for(j=n;j>=n;j--)
if(DiemTB[j]<DiemTB[j-1])
swap(DiemTB[j],DiemTB[j-1]);
}
int KiemTraDS(Nut *dau) // Kiem tra danh sach co rong hay khong
{
if(dau==NULL) return 1;
return 0;
}
int HTToanBoDS()
{
Nut *p = dau;
while (p != NULL)
{
cout<<"Ma Sinh Vien : " <<p->MaSV;
cout<<"Ho Ten : " <<p->HoTen;
cout<<"Que Quan : " <<p->Quequan;
cout<<"Ngay Sinh : " <<p->Ngaysinh;
cout<<"Diem TB : " <<p->DiemTB;
p = p->Tiep;
}
cout<<"
";
}
int HienthiSV(int DiemTB,int n) // Hien Thi SV Co 5 < DTB < 7
{
int i;
Nut *p=dau;
for(i=1;i<n;i++)
if(DiemTB<7 && DiemTB>5)
{
cout<<"Ma Sinh Vien : " <<p->MaSV;
cout<<"Ho Ten : " <<p->HoTen;
cout<<"Que Quan : " <<p->Quequan;
cout<<"Ngay Sinh : " <<p->Ngaysinh;
cout<<"Diem TB : " <<p->DiemTB;
p=p->Tiep;
}
else
cout<<" Ds nhap khong co !!!!";
}
int main()
{
char MaSV;
char HoTen;
char Quequan;
int Ngaysinh;
float DiemTB;
taoDS()
cout<<"Nhap ma SV : "; cin>>MaSV;
cout<<"Nhap Ho Ten : "; cin>>HoTen;
cout<<"Nhap Que Quan : "; cin>>Quequan;
cout<<"Nhap Ngay Sinh : "; cin>>Ngaysinh;
cout<<"Nhap diem TB : "; cin>>DiemTB;
KiemTraDS();
themDau();
cout<<"Da them vao dau danh sach 1 SV ";
themCuoi();
cout<<"Da them vao cuoi danh sach 1 SV ";
xoaNut();
themSV();
Sapxep();
cout<<"Danh sach sau khi da sap xep";
HienthiSV();
cout<<"Hien thi SV co 5 < DTB < 7 ";
HTToanBoDS();
}
void main()
{
Nut *dau;
SinhVien x;
char MaSV[10],HoTen[30],Quequan[30],list;
int ns;
float diemtb;
dau=NULL;
while(1)
{
cout<<"
-MENU-";
cout<<"
1.Tao Danh Sach";
cout<<"
2. Them SV vao dau";
cout<<"
3.Them SV vao cuoi";
cout<<"
4.Xoa SV";
cout<<"
5.Sap Xep DS SV";
cout<<"
6.Them SV x";
cout<<"
7.Kiem tra DS rong
cout<<"
8.Chuyen SV dau ve cuoi";
cout<<"
9. Hien Thi SV co 5 < DTB < 7 ";
cout<<"
10. Hien Thi Toan Bo DS";
cout<<"
11.Thoat
cout<<"
Moi ban chon chuc nang : ";
switch(list)
{
case '1':
cout<<"
Nhap DS sinh vien : ";
cout<<"
Nhap Exit de thoat :";
do{
cout<<"
Ho Ten : ";
cin.ignore(1);
cin.get(x.HoTen,30);
if(strcmp(x.HoTen,"exit")==0) break;
cout<<"
Ma SV : ";
cin.ignore(1);
cin.get(x.MaSV,10);
cout<<"
Que Quan : ";
cin.ignore(1);
cin.get(x.Quequan,30);
cout<<"
Ngay Sinh : ";
cin>>Ngaysinh;
cout<<"
Diem TB : ";
cin>>DiemTB;
dau=themDau(dau,x);
}while(strcmp(x.HoTen,"exit")!=0);break;
case '10':
HTToanBoDS();
cout<<"Da hien thi toan bo DS SV";
case '7':
if(IsEmpty(dau)) cout<<"
Danh sach rong";
else
HienthiSV(First);break;
case '2':
themDau();
case '3':
themCuoi();
case '4':
xoaNut();
case '5':
Sapxep();
case '6':
themSV();
case '7':
KiemTraDS();
case '9':
HienthiSV();
case '11': cout<<"
Thoat !!!
";
exit(0);break;
default : cout<<"
Khong co chuc nang nay
";break;
}
}
}
[/b] Tại Lương Sơn TV bạn sở hữu thể xem truyền hình trực tiếp bóng đá hôm nay các giải đấu to trong và ngoài nước. Lương Sơn TV ko chỉ đem lại những trận chiến mãn nhãn sở hữu chất lượng hình ảnh...
Các giải đấu không thể bỏ lỡ tại...