Code quan li svien
//quan li sv
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<malloc.h>
#include<string.h>
//du lieu;
struct sv{
char ten[100];
char msv[100];
struct sv*next;
}*p,*pdau,*pcuoi,*t,*moi,*k,*s,*thay,*tg,*luup;
char dung,doc;
int vt,vt2,n;
void huongdan();
void nhap();
void xoa();
void chen();
void them();
void sua ();
void inco();
void tim();
void luu();
//Chuong trinh quan li chinh.
int main()
{
huongdan();
scanf("%i",&n);printf("
");
switch(n){
case 1 :{
nhap();
huongdan();
printf("Nhap de tiep:
");
scanf("%i",&n);
switch(n){
case 2:inco();break;
case 3:{
printf("danh sach dau:
");
inco();
do{
them();
printf("Nhan enter de tiep/esc de thoat!
");
doc=getch();
}while(doc!=27);
printf("Danh sach cuoi la:
");
inco();
break;
}//dong case 3.
case 4:tim();break;
case 5:{
do{
sua();
printf("Nhan enter de tiep/esc de thoat!
");
doc=getch();
}while(doc!=27);
printf("Danh sach cuoi la:
");
inco();
break;
}
case 6:{
do{
xoa();
printf("Nhan enter de tiep/esc de thoat!
");
doc=getch();
}while(doc!=27);
printf("Danh sach cuoi la:
");
inco();
break;
}//dong case6.
default :{
printf("Sorry! Nhap sai hoac Chua co du lieu
");
break;
}
}//dong switch.
break;
}//dong cASE 1 NGOAI.
default :{
printf("Sorry! Nhap sai hoac Chua co du lieu
");
break;
}
}//dong switch.
getch();
}
//Ham huong dan su dung.
void huongdan()
{
int n;
printf("Chuong trinh quan li sinh vien:
");
printf("1:Nhap
");
printf("2:In
");
printf("3:Them
");
printf("4:Tim
");
printf("5:Sua
");
printf("6:xoa
");
return;
}
//Ham nhap;
void nhap()
{
int i;
pdau=NULL;i=1;
do{
system("cls");
p=(struct sv*)malloc(sizeof(struct sv));
printf("Sinh vien %i:
",i);
printf("
- Nhap ten:");
fflush(stdin);
gets(p->ten);
printf("
- Nhap ma sinh vien:");
fflush(stdin);
gets(p->msv);
if(pdau==NULL){
pdau=p;
pcuoi=p;
}
else{
pcuoi->next=p;
pcuoi=p;
}
i++;
system("cls");
printf("An esc de ket thuc/An enter de tiep tuc:
");
dung=getch();
}while(dung!=27);
p->next=NULL;
return;
}
//Ham sua:
void sua()
{
char msvs[100];
printf("Sua thong tin cho sinh vien co ma sinh vien:");
fflush(stdin);
gets(msvs);
p=pdau;
printf("Nhap lai thong tin cho sinh vien nay:
");
while(p!=NULL){
if(strcmp(pdau->msv,msvs)==0){
thay=(struct sv*)malloc(sizeof(struct sv*));
printf("
- Nhap ten:");
fflush(stdin);
gets(thay->ten);
printf("
- Nhap ma sinh vien:");
fflush(stdin);
gets(thay->msv);
//------------------------------
tg=pdau->next;
pdau=thay;
thay->next=tg;
break;
}
else if(strcmp(p->next->msv,msvs)==0){
thay=(struct sv*)malloc(sizeof(struct sv*));
printf("
- Nhap ten:");
fflush(stdin);
gets(thay->ten);
printf("
- Nhap ma sinh vien:");
fflush(stdin);
gets(thay->msv);
//------------------------------
s=p->next->next;
p->next=thay;
thay->next=s;
break;
}
p=p->next;
}
luu();
inco();
return;
}
//Ham them node.
void them()
{
int i;
printf("Nhap vao vi tri can them:");scanf("%i",&vt);
moi=(struct sv*)malloc(sizeof(struct sv));
printf("
Nhap ten sv moi:");
fflush(stdin);gets(moi->ten);
printf("
Nhap so bao danh:");
fflush(stdin);
gets(moi->msv);
i=0;p=pdau;
while(p!=NULL){
i++;
if(vt==1){
t=pdau;
pdau=moi;
moi->next=t;
break;
}
if(i==vt-1){
t=p->next;
p->next=moi;
moi->next=t;
break;
}
p=p->next;
}
p=pdau;i=0;
while(p!=NULL){
i++;
printf("
Sinh vien%i:
",i);
printf("
-Ten: %s",(p->ten));
printf("
-ma sinh vien:%s",p->msv);
printf("
-------------------------
");
p=p->next;
}luu();
void inco();
return;
}
//Ham tim kiem;
void tim()
{
char msvm[100];
printf("Nhap ma sinh vien ma ban muon tim:");
fflush(stdin);
gets(msvm);
printf("
Thong tin sinh vien do la:
");
p=pdau;
while(p!=NULL){
if(strcmp(p->msv,msvm)==0){
printf("Ten: %s",p->ten);
printf("
Ma sinh vien:%s ",p->msv);
break;
}
p=p->next;
} luu();
void inco();
return;
}
//Ham xoa 1 node.
void xoa()
{
printf("NHap vi tri can xoa:");
scanf("%i",&vt2);
p=pdau;int i=0;
while(p!=NULL){
i++;
if(vt2==1){
pdau=pdau->next;
break;
}
if(i==vt2-1){
k=p->next;
k=k->next;
p->next=k;
break;
}
p=p->next;
}
p=pdau;i=0;
while(p!=NULL){
i++;
printf("
Sinh vien%i:
",i);
printf("
-Ten: %s",(p->ten));
printf("
-ma sinh vien:%s",p->msv);
printf("
-------------------------
");
p=p->next;
}luu();
return;
}
//Ham in khi co du lieu truoc.
void inco()
{
int i;
p=pdau;
i=0;
printf("Danh sach sinh vien:
");
while(p!=NULL){
i++;
printf("
Sinh vien%i:
",i);
printf("
-Ten: %s",(p->ten));
printf("
-ma sinh vien:%s",p->msv);
printf("
-------------------------
");
p=p->next;
}luu();
return;
}
// ham luu;
void luu()
{
luup=(struct sv*)malloc(sizeof(struct sv));
luup=p;
free(p);
p=(struct sv*)malloc(sizeof(struct sv));
p=luup;
return;
}
Bạn đang đọc truyện trên: AzTruyen.Top