#include <iostream.h>// quan ly diem sinh vien gom cac thong tin: mssv, tensv, msmh, tenmh, dtb
#include <iomanip.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct sinhvien
{
char mssv[5];
char tensv[50];
char msmh[5];
char tenmh[50];
float dtb;
};
void Nhapsv(sinhvien a[], int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<"\nNhap sinh vien thu: "<<i+1;
cout<<"\n\t+ Nhap ma sinh vien: ";
gets(a[i].mssv);
cout<<"\n\t+ Nhap ten sinh vien: ";
gets(a[i].tensv);
cout<<"\n\t+ Nhap ma mon hoc: ";
cin>>a[i].msmh;
cout<<"\n\t+ Nhap ten mon hoc: ";
gets(a[i].tenmh);
cout<<"\n\t+ Nhap diem trung binh: ";
cin>>a[i].dtb;
}
}
void Insv(sinhvien a[], int n)
{
int i;
cout<<"\n"<<setw(15)<<"MA SINH VIEN"<<setw(20)<<"TEN SINH VIEN"<<setw(15)<<"MA MON
HOC"<<setw(15)<<"TEN MON HOC"<<setw(10)<<"DIEM TB";
cout<<"\n"<<setw(15)<<"============"<<setw(20)<<"============="<<setw(15)<<"=========="<<set
w(15)<<"==========="<<setw(10)<<"======";
for(i=0;i<n;i++)
{
cout<<"\n"<<setw(15)<<a[i].mssv<<setw(20)<<a[i].tensv<<setw(15)<<a[i].msmh<<setw(15)<<a[i].tenmh<<
setw(10)<<a[i].dtb;
}
}
void Sapxepsv(sinhvien a[], int n)
{
int i,j;
sinhvien tg;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i].dtb>a[j].dtb)
{
tg=a[i];
a[i]=a[j];
a[j]=tg;
}
}
}
}
void ThemCuoiDanhSach(sinhvien a[], int &n, sinhvien x)
{
cout<<"\n\t+ Nhap ma sinh vien: ";
gets(x.mssv);
cout<<"\n\t+ Nhap ten sinh vien: ";
gets(x.tensv);
cout<<"\n\t+ Nhap ma mon hoc: ";
cin>>x.msmh;
cout<<"\n\t+ Nhap ten mon hoc: ";
gets(x.tenmh);
cout<<"\n\t+ Nhap diem trung binh: ";
cin>>x.dtb;
a[n] = x;
n++;
}
void ThemVaoBatKy(sinhvien a[], int &n, sinhvien x, int vitri)
{
cout<<"\n\t+ Nhap ma sinh vien: ";
gets(x.mssv);
cout<<"\n\t+ Nhap ten sinh vien: ";
gets(x.tensv);
cout<<"\n\t+ Nhap ma mon hoc: ";
cin>>x.msmh;
cout<<"\n\t+ Nhap ten mon hoc: ";
gets(x.tenmh);
cout<<"\n\t+ Nhap diem trung binh: ";
cin>>x.dtb;
a[n]=a[vitri];
a[vitri] = x;
n++;
}
void ThemVaoBatKy_Soft(sinhvien a[], int &n, sinhvien x, int vitri)
{
cout<<"\n\t+ Nhap ma sinh vien: ";
gets(x.mssv);
cout<<"\n\t+ Nhap ten sinh vien: ";
gets(x.tensv);
cout<<"\n\t+ Nhap ma mon hoc: ";
cin>>x.msmh;
cout<<"\n\t+ Nhap ten mon hoc: ";
gets(x.tenmh);
cout<<"\n\t+ Nhap diem trung binh: ";
cin>>x.dtb;
for (int i=n-1; i>vitri; i--)
{
a[i] = a[i-1];
a[vitri] = x;
}
n++;
}
void XoaBatKy_Soft(sinhvien a[], int &n, int vitri)
{
for (int i=vitri; i<n-1; i++)
a[i] = a[i+1];
n--;
}
void TimKiemSinhVien(const sinhvien a[], int n, const sinhvien x)
{
cout<<"\n"<<setw(15)<<"MA SINH VIEN"<<setw(20)<<"TEN SINH VIEN"<<setw(15)<<"MA MON
HOC"<<setw(15)<<"TEN MON HOC"<<setw(10)<<"DIEM TB";
cout<<"\n"<<setw(15)<<"============"<<setw(20)<<"============="<<setw(15)<<"=========="<<set
w(15)<<"==========="<<setw(10)<<"=======";
for (int i=0; i<n; i++)
{
if (strcmp(a[i].tensv,x.tensv)==0)
{
cout<<"\n"<<setw(15)<<a[i].mssv<<setw(20)<<a[i].tensv<<setw(15)<<a[i].msmh<<setw(15)<<a[i].tenmh<<
setw(10)<<a[i].dtb;
}
else
{
cout<<setw(15)<<"\n\tKhong tim thay sinh vien nay.";
}
}
}
void main()
{
int n, chon,vitri;
sinhvien a[50],x;
char c;
clrscr();
do
{
cout<<"\nChon 1 de nhap so sinh vien ";
cout<<"\nChon 2 de nhap diem sinh vien ";
cout<<"\nChon 3 de sap xep thong tin diem sinh vien ";
cout<<"\nChon 4 de in thong tin diem sinh vien ";
cout<<"\nChon 5 de them thong tin diem sinh vien ";
cout<<"\nChon 6 de xoa thong tin diem sinh vien ";
cout<<"\nChon 7 de tim kiem thong tin diem sinh vien ";
cout<<"\nChon 8 de thoat chuong trinh. ";
cout<<"\nHay chon chuc nang: ";
cin>>chon;
switch (chon)
{
case 1:
cout<<"\nNhap so sinh vien: ";
cin>>n;
break;
case 2:
Nhapsv(a,n);
break;
case 3:
Sapxepsv(a,n);
break;
case 4:
cout<<"\nIn danh sach diem sinh vien:";
Insv(a,n);
break;
case 5:
//ThemCuoiDanhSach(a,n,x);
cout<<"\nChon vi tri de them diem sinh vien: ";
cin>>vitri;
ThemVaoBatKy_Soft(a,n,x,vitri);
//ThemVaoBatKy(a,n,x,vitri);
break;
case 6:
cout<<"\nChon vi tri de xoa diem sinh vien: ";
cin>>vitri;
XoaBatKy_Soft(a,n,vitri);
break;
case 7:
cout<<"\nNhap ten sinh vien de tim kiem: ";
gets(x.tensv);
TimKiemSinhVien(a,n,x);
break;
case 8:
cout<<"\nTiep tuc nua khong (c/k), khong tiep nua nhan n de thoat: ";
cin>>c;
}
}while(c!='k' && c!='K');
exit(1);
getch();
}