#include
#define max 100
#include
#include
typedef struct SinhVien
{
int MSSV;
char HoTen[30];
float DTB;
}SV;
void Nhap1SV(SV &x)
{
printf("\n Nhap MSSV:");scanf("%d",&x.MSSV);
fflush(stdin);
printf("\n Nhap Ho Ten Sinh Vien:");scanf("%s",&x.HoTen);
float t;
printf("\nNhap DTB cua SV:");scanf("%f",&t);
x.DTB=t;
}
void Xuat1SV(SV x)
{
printf("\n MSSV:%d",x.MSSV);
printf("\t Ho Ten SV:%s",x.HoTen);
printf("\t DTB:%.2f",x.DTB);
}
//==================================================1
void NhapDSSV(SV a[],int &n)
{ printf("\n Nhap so luong sinh vien:"); scanf("%d",&n);
for(int i=0;i
}
//=================================================== 8
void XuatDSSV(SV a[],int n)
{
for(int i=0;i
}
//==================================================2
int DTB_MAX(SV a[],int n)
{
int vt=0;
for(int i=0;i
vt=i;
return vt;
}
//================================================De quy
/*
int DTB_MAX(SV a[],int n)
{
if(n==1)return 0;//vt 0
int m=DTB_MAX(a,n-1)
if(m>a[n-1])
m=n-1;
return m;
}
*/
//============================================3
float DiemBinhQuan(SV a[],int n)
{
float S=0;
for(int i=0;i
return S/n;
}
//===================================================4
/*int TimSV_TheoMSSV(SV a[],int n,int X)
{
for(int i=0;i
return i;
return -1;
} */
//==================Tim Kiem Nhi Phan :khi mang da duoc sap xep
int TimSV_TheoMSSV(SV a[],int n,int X)
{
int l=0,r=n-1,mid;
while(l<=r)
{
mid=(l+r)/2 ;
if(a[mid].MSSV == X) return mid;
if(a[mid].MSSV > X) r= mid-1;
if(a[mid].MSSV < X) l= mid + 1;
}
return -1 ;
}
//====================================================5
void SapXepSV_TangTheoHoTen(SV a[],int n)
{
for(int i=0;i
{
SV temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
//====================================================6
void XoaSV(SV a[],int &n,int vitrixoa)
{
for(int i=vitrixoa;i
n--;
}
//=====================================================7
void ThemSV(SV a[],int &n,SV them)
{
a[n]=them;
n++;
}
int main()
{
SV x;
SV them;
SV a[30];
int n, chon,X;
do
{
// Nhap1SV(x);Xuat1SV(x);
// NhapDSSV(a,n);
printf("\n***************************************\n");
printf("\nNguyen Ngoc Anh");
printf("\nLop: TTDH4");
printf("\nMSSV: ");
printf("\n************Chuong trinh Quan Ly Sinh Vien**************");
printf("\n1.Nhap So Luong va thong tin cho Sinh Vien");
printf("\n2.Tim Sinh Vien Co DTB cao Nhat");
printf("\n3.Tinh diem binh quan cua tat ca cac Sinh Vien");
printf("\n4.Tim Sinh Vien theo MSSV");
printf("\n5.Sap xep Sinh Vien tang dan theo ho ten");
printf("\n6.Them Sinh Vien vao danh sach");
printf("\n7.Xoa Sinh Vien theo MSSV");
printf("\n8.Xuat danh sach Sinh Vien") ;
printf("\n0.Thoat") ;
printf("\n***************************************\n");
printf("\n Chon muc can thuc hien:");scanf("%d",&chon);
switch(chon)
{
case 1:
{
NhapDSSV(a,n);
break;
}
case 2:
{ printf("\nSV co diem trung binh cao nhat:\n");
int kq=DTB_MAX(a,n);
for(int i=0;i
if(a[i].DTB==a[kq].DTB)
Xuat1SV(a[kq]);//kq hay i cung duoc
break;
}
case 3:
{
printf("\n Diem binh quan cua SV:%.2f",DiemBinhQuan(a,n));
break;
}
case 4:
{
printf("\n Nhap MSSV can tim:"); scanf("%d",&X);
int vt=TimSV_TheoMSSV(a,n,X);
if(vt==-1)printf("\nKhong co SV nay trong danh sach");
else
{
printf("\nTim thay tai vi tri:%d",vt);
Xuat1SV(a[vt]);
}
break;
}
case 5:
{
SapXepSV_TangTheoHoTen(a,n); XuatDSSV(a,n);
break;
}
case 6: //THEM sv
{
Nhap1SV(x); ThemSV(a,n,x);XuatDSSV(a,n);
break;
}
case 7://Tim SV theo ma roi xoa sv tai vi tri do
{
printf("\n Nhap vao MSSV can xoa:");
scanf("%d",&X);
int vt=TimSV_TheoMSSV(a,n,X);
if(vt==-1)printf("\Khong co Sinh vien nay de XOA!!");
else
XoaSV(a,n,vt);XuatDSSV(a,n);
break;
}
case 8:
{
XuatDSSV(a,n);
break;
}
case 0:
exit(0);
default:
{
printf("ban da chon sai,Hay chon lai!!!");
}
}
}while(chon);
getch();
}
0 nhận xét:
Đăng nhận xét