You are on page 1of 6

Chương trinh quản lí sinh viên:

CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<alloc.h>
#include<iostream.h>
struct sv
{
char malop[20];
char hovaten[30];
float diemk1;
float diemk2;
sv*tiep;
};

sv*pdau,*pcuoi,*curr;
void in(sv*p)
{
p=pdau;
while(p!=NULL)
{
cout<<" ho ten: "<<p->hovaten<<" malop: "<<p->malop<<" diemk1:"<<p->diemk1<<",
diemk2:"<<p->diemk2<<" "<<endl;
p=p->tiep;
}
}
void them(sv*q,int i)
{
q=new sv;
cout<<" nhap vao vi tri can them: ";
cin>>i;
printf("\n nhap ho va ten nguoi can them : ");
fflush(stdin);
gets(q->hovaten);
printf("\n ma lop : " );
fflush(stdin);
gets(q->malop);
cout<<" diemk1: ";
cin>>q->diemk1;
cout<<" diemk2: ";
cin>>q->diemk2;
sv*p;
p=pdau;
int d=1;
if(i==1)
{
q->tiep=p;
pdau=q;
}
else
{
while(d!=i-1)
{
p=p->tiep;
d++;
};
q->tiep=p->tiep;
p->tiep=q;

}
}
void xoa(int k)
{
cout<<" nhap vao vi tri can xoa : ";
cin>>k;
sv*p;
p=pdau;
int d=1;
if(k==1)
{
p=pdau->tiep;
pdau=p;
}
else
{
while(d!=k-1)
{
p=p->tiep;
d++;
};
p->tiep=p->tiep->tiep;
p=p->tiep;

}
}
char tach(char ht[30])
{
int n=strlen(ht);
while(ht[n-1]!=' ')
{
n--;
};
return ht[n+1];
}
char lop(char t[20])
{
return t[strlen(t)-1];
}
void doicho(sv*sv1,sv*sv2)
{
sv *sv3;
sv3=new sv;
sv3=sv1;
sv1=sv2;
sv2=sv3;
}
void sapxep(sv*sv1,sv*sv2)
{
if(lop(sv1->malop)>lop(sv2->malop))
doicho(sv1,sv2);
if(lop(sv1->malop)==lop(sv2->malop))
{
if(tach(sv1->hovaten)>tach(sv2->hovaten))
doicho(sv1,sv2);
else
if(tach(sv1->hovaten)>tach(sv2->hovaten))
if(sv1->diemk1<sv2->diemk2)
doicho(sv1,sv2);
}
}
void seach(char ht[30])
{
printf("\n nhap ho va ten nguoi can tim : ");
fflush(stdin);
gets(ht);
sv*cur;
cur=pdau;
while(cur!=NULL)
{
if(strcmp(cur->hovaten,ht)==0)
printf("\n ho ten: %s lop: %s diem k1: %1.1f diem k2: %1.1f.\n",cur->hovaten,cur-
>malop,cur->diemk1,cur->diemk2);
cur=cur->tiep;
}
}

void main()
{

char ht[30];
char ml[20];
float d1;
float d2;
pdau=pcuoi=curr=new sv;
printf("nhap ho va ten : ");
fflush(stdin);
gets(ht);
printf(" nhap ma lop: ");
fflush(stdin);
gets(ml);
cout<<" diemk1: ";
cin>>d1;
cout<<" diemk2 : ";
cin>>d2;
strcpy(curr->hovaten,ht);
strcpy(curr->malop,ml);
curr->diemk1=d1;
curr->diemk2=d2;
pdau=pcuoi=curr;

while(1)
{
printf(" nhap ho va ten : ");
fflush(stdin);
gets(ht);
if(ht[0]==' ')
break;
printf(" nhap ma lop: ");
fflush(stdin);
gets(ml);
cout<<" diemk1: ";
cin>>d1;
cout<<" diemk2 : ";
cin>>d2;
curr=new sv;
strcpy(curr->hovaten,ht);
strcpy(curr->malop,ml);
curr->diemk1=d1;
curr->diemk2=d2;
pcuoi->tiep=curr;
pcuoi=curr;
}
sv*q,*q1,*q2;
sv*cur;
q=cur=new sv;
cur=pdau;
while(cur!=NULL)
{
q1=new sv;
q1=cur;
q=cur->tiep;
while(q!=NULL)
{
q2=new sv;
q2=q;
sapxep(q1,q2);
q=q->tiep;

};
cur=cur->tiep;
};
int m;
A:
{
cout<<" 1.in danh sach"<<endl;
cout<<" 2.them vao mot phan tu "<<endl;
cout<<" 3.xoa 1 phan tu"<<endl;
cout<<" 4.tim kiem theo ten "<<endl;
cout<<" 5.thoat"<<endl;
cin>>m;
switch(m)
{
case 1: sv*p;in(p);
goto A;
break;
case 2: int i;
sv*q;
them (q,i);
goto A;
break;
case 3: int d;
xoa(d);
goto A;
break;
case 4: char ht[30]; seach(ht);
goto A; break;
case 5:goto B; break;
}
}
B:
getch();
}
Kết quả: