#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
typedef char inf1[20];
typedef float inf2;
typedef float inf3;
typedef struct _svien { //Dinh nghia kieu du lieu hsinh
inf1 hten;
inf2 cnang;
inf3 ccao;
} svien;
typedef svien list[MAX];
list p;
// Nguyen mau ham
int nhap();//Nhap thong tin cho danh sach sinh vien
svien nhapsv();//Nhap thong tin cho 1 sihn vien
void xuat(int);//Xuat danh sach sinh vien ra man hinh
int them(svien,int,int);//Them mot sv vao ds
int timkiem(inf1,int);//Tim 1 nguoi tra ve vi tri trong ds
int xoa(int,int); //Xoa mot sv ra ds
void menu();//hien thi menu
int main(){
clrscr();
svien temp;
inf1 hten;
int n=0,choice,vitri;//n la so luong sinh vien
while (1){
clrscr();
inf3 ccao;
do{
printf("\nNhap ten sv thu %d (nhap 'end' de ket thuc) :",i+1);
gets(hten);
if (strcmpi(hten,"end")&&(i<MAX)) {
strcpy(p[i].hten,hten);
printf("\nNhap thong tin cho sv %s:",p[i].hten);
printf("\nChieu cao (cm): ");scanf("%f",&ccao);fflush(stdin);
p[i].ccao=ccao;
p[i].cnang= ccao - 105;
i++;
}
if (i==MAX) printf("FULL");
} while (strcmpi(hten,"end")&&(i<MAX));
return i;
}
svien nhapsv(){
svien temp;
inf2 ccao;
inf1 hten;
printf("\nHo ten: ");gets(hten);
strcpy(temp.hten,hten);
printf("\nChieu cao: (cm) ");scanf("%f",&ccao);fflush(stdin);
temp.ccao=ccao;
temp.cnang=ccao-105;
return temp;
}
void xuat(int n){
%3d",p[i].ccao,p[i].cnang,i+1);
}
getch();
if (i<100) return i+1;
else return 0;
}
int xoa(int vitri,int n){
int i;
if (vitri<1||vitri>n) printf("\nVi tri khong thich hop");
else {
for(i=vitri-1;i<n;i++) p[i]=p[i+1];
n ;
printf("\nThanh Cong ");
}
getch();
return n;
}
void menu(){
printf("\n1. Nhap moi mot danh sach sinh vien");
printf("\n2. Liet ke danh sach");
printf("\n3. Them 'Le Them' ccao 155 vao vi tri thu 2 danh
sach");
printf("\n4. Them mot sv vao danh sach");
printf("\n5. Tim kiem sv 'Le Tim' trong danh sach");
printf("\n6. Xem thong tin mot sv");
printf("\n7. Xoa sv thu 2 ra khoi danh sach");
printf("\n8. Xoa sv co vi tri x ra khoi danh sach");
printf("\n9. Xoa sv 'Le Xoa' trong ds neu co");
printf("\n10. Xoa mot sv ra khoi danh sach");
void timsv(inf1 hten);//Tim va xuat thong tin sv co ten la hten
void menu();//Hien thi menu
int main(){
clrscr();
inf1 hten;
int choice;
while (1){
menu();
printf("\nMoi lua chon:");scanf("%d",&choice); fflush(stdin);
switch (choice){
case 0: exit(0);
case 1:nhapds();break;
case 2:clrscr();p=new svien;p=nhapsv(p);pus(p);break;
case 3:clrscr();xuatds(top);break;
case 4: printf("\Nhap ho ten sv muon xem thong tin:
");gets(hten);timsv(hten);break;
case 5:if (top!=NULL) top=top->next; else printf("\nDanh sach
rong !"); break;
case 6: printf("\nNhap ho ten sv can xoa:
");gets(hten);xoasv(hten);break;
default: printf("Lua chon khong hop le !");getch();break;
}
clrscr();
};
}
svien *nhapsv(svien *tem){
inf1 hten={0};
void nhapds(){
int end=2;
while (end==2){
p=new svien;//Cap phat moi bo nho cho sv moi
p=nhapsv(p);//Nhap thong tin cho sv p
pus(p);
printf("\t\t\t1. Ket thuc");
printf("\n\t\t\t2. Nhap tiep");
printf("\n\t\t\tChoice ? ");
scanf("%d",&end) ;fflush(stdin);
}
clrscr();
}
void xoasv(inf1 hten){
svien *hientai,*ketruoc;
hientai=top;
while ((hientai!=NULL)&&strcmpi(hientai->hten,hten)) {
ketruoc=hientai;
hientai=hientai->next;
};
if (hientai==NULL) printf("\nKhong tim thay sinh vien !");
else {
if (hientai==top) top=hientai->next;
else ketruoc->next=hientai->next;
printf("\nXoa thanh cong");
getch();
}
}
void timsv(inf1 hten){
svien *tem;
inf3 ccao;
struct _svien *next;
} svien;
svien *first=NULL,*last=NULL,*p=NULL;
// Nguyen mau ham
svien *nhapsv(svien *tem);//Nhap thong tin cho danh sach sinh
vien
void xuatsv(svien *tem);//Xuat thong tin 1 sinh vien
void pus(svien *tem);//Them mot sv vao cuoi danh sach lien ket
void pus1(svien *tem);//Them mot sv vao dau danh sach
void xuatds(svien *top);
void nhapds();//Nhap danh sach sin vien
void xoasv(inf1 hten);//Xoa sv co ten la hten
void timsv(inf1 hten);//Tim va xuat thong tin sv co ten la hten
void menu();//Hien thi menu
int main(){
clrscr();
inf1 hten;
int choice;
while (1){
menu();
printf("\nMoi lua chon:");scanf("%d",&choice); fflush(stdin);
switch (choice){
case 0: exit(0);
case 1:nhapds();break;
case 2:clrscr();p=new svien;p=nhapsv(p);pus1(p);break;
case 3:clrscr();xuatds(first);break;
case 4: printf("\Nhap ho ten sv muon xem thong tin:
tem->next=NULL;
if (first==NULL) first=tem;
else last->next=tem;
last=tem;
}
void pus1(svien *tem){//Them 1 sv vao dau danh sach
tem->next=first;
first=tem;
}
void xuatds(svien *top){
svien *tem;
tem=top;//Cat giu top
if (tem==NULL) printf("\nDanh sach rong !");
else printf("\nDanh sach sv:");
while (tem!=NULL){
xuatsv(tem); //xuat thong tin
tem=tem->next;//tro den sv tiep theo
}
getch();
}
void nhapds(){
int end=2;
while (end==2){
p=new svien;//Cap phat moi bo nho cho sv moi
p=nhapsv(p);//Nhap thong tin cho sv p
pus(p);
printf("\t\t\t1. Ket thuc");
printf("\n\t\t\t2. Nhap tiep");
printf("\n\t\t\tChoice ? ");
scanf("%d",&end) ;fflush(stdin);
printf("\n3. Liet ke danh sach");
printf("\n4. Nhap ten sv can xem thong tin");
printf("\n5. Xoa sv dau tien ra khoi danh sach");
printf("\n6. Nhap ten sinh vien can xoa ra khoi danh sach");
printf("\n0. Ket thuc chuong trinh");
}
//Danh Sach sap xep theo thu tu tang dan cua ho ten
// su dung stack
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
typedef char inf1[20];
typedef float inf2;
typedef float inf3;
typedef struct _svien { //Dinh nghia kieu du lieu hsinh
inf1 hten;
inf2 cnang;
inf3 ccao;
struct _svien *next;
} svien;
svien *top=NULL,*p=NULL;
// Nguyen mau ham
svien *nhapsv(svien *tem);//Nhap thong tin cho danh sach sinh
vien
void xuatsv(svien *tem);//Xuat thong tin 1 sinh vien
}
clrscr();
};
}
svien *nhapsv(svien *tem){
inf1 hten={0};
inf2 ccao=0;
printf("\nNhap thong tin cho sv:");
printf("\nNhap ten: "); gets(hten);
strcpy(tem->hten,hten);
printf("Nhap chieu cao (cm):");scanf("%f",&ccao);
fflush(stdin);//xoa bo nho dem ban phim
tem->ccao=ccao;
tem->cnang=ccao-105;
return tem;
}
void xuatsv(svien *tem){
printf("\nTen sv: ");printf("%-20s",tem->hten);
printf("\tChieu cao %.1f (cm) \t Can nang chuan %.1f",tem-
>ccao,tem->cnang);
}
void pus(svien *tem){ //Them sv vao ds theo thu tu tang dan ho
ten
svien *hientai=NULL,*ketruoc=NULL;
hientai=top;
while ((strcmpi(tem->hten,hientai-
>hten)>0)&&(hientai!=NULL)){
ketruoc=hientai;
hientai=hientai->next;
}
scanf("%d",&end) ;fflush(stdin);
}
clrscr();
}
void xoasv(inf1 hten){
svien *hientai,*ketruoc;
hientai=top;
while ((hientai!=NULL)&&strcmpi(hientai->hten,hten)) {
ketruoc=hientai;
hientai=hientai->next;
};
if (hientai==NULL) printf("\nKhong tim thay sinh vien !");
else {
if (hientai==top) top=hientai->next;
else ketruoc->next=hientai->next;
printf("\nXoa thanh cong");
getch();
}
}
void timsv(inf1 hten){
svien *tem;
tem=top;
while ((tem!=NULL)&&strcmpi(tem->hten,hten)) tem=tem-
>next;
if (tem==NULL) printf("\nKhong tim thay sinh vien");
else xuatsv(tem);
getch();
}
void menu(){
printf("\n1. Nhap moi mot danh sach sinh vien");