ai giúp mình phần sửa sinh viên và xóa sinh viên trong này ( mình đã làm phần sửa sinh viên nhưng sai rùi )
#include<conio.h>
#include<iostream.h>
#include<math.h>
#include<stdio.h>
#include<string.h>
#define BACK_TO_MENU cout<<"\n\n Press any key to back to menu. . ."; getch();
#include <stdlib.h>
struct sinhvien
{
int SBD;
char hoten[30];
int Nsinh;
char lop[10];
float diemLy;
float diemHoa;
float diemToan;
float DTB;
}
SV1[100] ;
int n;
FILE *fileptr;
int menu2()
{ int chon2;
do{
cout<<"\n\n MENU\n"
" ----------------\n"
" 1. sua ten.\n"
" 2. sua diem toan.\n"
" 3. sua diem ly.\n"
" 4. sua diem hoa.\n"
" 0. Thoat.\n";
cout<<"\n Your chon: ";
cin>>chon2;
} while (chon2<0 || chon2>4);
return chon2;
}
int menu()
{
int choice;
do{
clrscr();
cout<<"\n MENU\n"
" ----------------\n"
" 1. Them sinh vien.\n"
" 2. In danh sach sinh vien.\n"
" 3. Tim Kiem SV.\n"
" 4. Suasv.\n"
" 5. xoa SV. \n"
" 0. Thoat.\n";
cout<<"\n Your choice: ";
cin>>choice;
} while (choice<0 || choice>4);
return choice;
}
void nhapSV()
{ clrscr();
int i=1;
sinhvien SV;
float x;
fileptr=fopen("quan ly SV.txt","a+t");
cout<<"Nhap vao danh sach sv, Kt khi de trong ma\n";
cout<<"----------------------------------------------------------------------------\n";
cout<<"| STT | MaSV | HO VA TEN |DIEM toan|DIEM ly|DIEM hoa |\n";
cout<<"---------------------------------------------------------------------------\n";
while(1)
{
cout<<"|"<<i;
gotoxy(7,4+i);
cout<<"|";
fflush(fileptr);
cin>>SV.SBD;
if(SV.SBD==0)break;
gotoxy(15,4+i);
cout<<"|";
fflush(fileptr);
gets(SV.hoten);
gotoxy(43,4+i);
cout<<"|";
cin>>x;
SV.diemToan=x;
gotoxy(53,4+i);
cout<<"|";
cin>>x;
SV.diemLy=x;
gotoxy(61,4+i);
cout<<"|";
cin>>x;
SV.diemHoa=x;
gotoxy(71,4+i);
cout<<"|";
cout<<"\n";
i++;
/*ghi du lieu vao file */
fwrite(&SV,sizeof(sinhvien),1,fileptr);
}
cout<<"---------------------------------------------------------------\n";
int n=i;
cout<<"Ban da them vao danh sach "<<n-1<<" sinh vien";
// m=i;
fclose(fileptr); BACK_TO_MENU;
}
void xuatfilesv()
{ clrscr();
sinhvien SV;
int i=1;
cout<<"----------------------------------------------------------------------------------\n";
cout<<"| STT | MaSV | HO VA TEN |DIEM toan|DIEM ly|DIEM hoa | DTB |\n";
cout<<"----------------------------------------------------------------------------------\n";
fileptr= fopen("quan ly SV.txt","rb");
while(fread(&SV,sizeof(sinhvien),1,fileptr),!feof( fileptr))
{
gotoxy(0,6+i);
cout<<i;
gotoxy(7,6+i);
cout<<"| ";
cout<<SV.SBD;
gotoxy(15,6+i);
cout<<"| ";
cout<<SV.hoten;
gotoxy(43,6+i);
cout<<"| ";
cout<<SV.diemToan;
gotoxy(53,6+i);
cout<<"|";
cout<<SV.diemLy;
gotoxy(63,6+i);
cout<<"|";
cout<<SV.diemHoa;
gotoxy(73,6+i);
cout<<"|";
cout<<(SV.diemToan+SV.diemLy+SV.diemHoa)/3;
gotoxy(73,6+i);
cout<<"|";
cout<<"\n";
SV1[i]=SV;
i++;
}
cout<<"-------------------------------------------------------------------------\n";
n=i;
}
void xuat_mang_sv(sinhvien SV,int n)
{
cout<<" \n********************* DANH SACH SINH VIEN **************************** \n\n";
cout<<"-------------------------------------------------------------------------\n";
cout<<"| STT | MASV | HO VA TEN | DIEM M1 | DIEM M2 | DTB |\n";
cout<<"-------------------------------------------------------------------------\n";
for(int i=1;i<=n;i++)
{
gotoxy(0,6+i);
cout<<i;
gotoxy(7,6+i);
cout<<"| ";
cout<<SV.SBD;
gotoxy(15,6+i);
cout<<"| ";
cout<<SV.hoten;
gotoxy(43,6+i);
cout<<"| ";
cout<<SV.diemToan;
gotoxy(53,6+i);
cout<<"| ";
cout<<SV.diemLy;
gotoxy(63,6+i);
cout<<"| ";
cout<<SV.diemHoa;
gotoxy(73,6+i);
cout<<"| ";
cout<<(SV.diemToan + SV.diemLy + SV.diemHoa)/2;
gotoxy(73,6+i);
cout<<"| ";
cout<<"\n";
}
cout<<"-------------------------------------------------------------------------\n";
}
void timkiemsv()
{ clrscr();
fileptr=fopen("quan ly SV.txt","rb");
int i=1;
int sbd;
sinhvien SV;
cout<<"moi nhap ma sinh vien "; cin>>sbd;
cout<<"----------------------------------------------------------------------------------\n";
cout<<"| STT | MaSV | HO VA TEN |DIEM toan|DIEM ly|DIEM hoa | DTB |\n";
cout<<"----------------------------------------------------------------------------------\n";
while(fread(&SV,sizeof(sinhvien),1,fileptr),!feof( fileptr))
{
if(sbd==SV.SBD)
{
gotoxy(0,6+i);
cout<<i;
gotoxy(7,6+i);
cout<<"| ";
cout<<SV.SBD;
gotoxy(15,6+i);
cout<<"| ";
cout<<SV.hoten;
gotoxy(43,6+i);
cout<<"| ";
cout<<SV.diemToan;
gotoxy(53,6+i);
cout<<"|";
cout<<SV.diemLy;
gotoxy(63,6+i);
cout<<"|";
cout<<SV.diemHoa;
gotoxy(73,6+i);
cout<<"|";
cout<<(SV.diemToan+SV.diemLy+SV.diemHoa)/3;
gotoxy(73,6+i);
cout<<"|";
cout<<"\n";
break;
}
}
}
void suasv()
{ clrscr();
sinhvien SV;
int mode2=0,dem=0;
fileptr=fopen("quan ly SV.txt","rb");
int sbd;
int i=1;
cout<<" moi nhap ma sinh vien "; cin>>sbd;
cout<<"----------------------------------------------------------------------------------\n";
cout<<"| STT | MaSV | HO VA TEN |DIEM toan|DIEM ly|DIEM hoa | DTB |\n";
cout<<"----------------------------------------------------------------------------------\n";
while(fread(&SV,sizeof(sinhvien),1,fileptr),!feof( fileptr))
{
if(SV.SBD!=0)
{
dem++;
}
if(sbd==SV.SBD)
{
float x;
gotoxy(0,6+i);
cout<<i;
gotoxy(7,6+i);
cout<<"| ";
cout<<SV.SBD;
do
{
mode2=menu2();
switch(mode2)
{
case 1:
gotoxy(15,6+i);
cout<<"| ";
fflush(fileptr);
gets(SV.hoten) ;
fwrite(&SV,sizeof(sinhvien),1,fileptr); break;
case 2:
gotoxy(43,4+i);
cout<<"|";
cin>>x;
SV.diemToan=x;
fwrite(&SV,sizeof(sinhvien),1,fileptr); break;
case 3:
gotoxy(53,4+i);
cout<<"|";
cin>>x;
SV.diemLy=x ;
fwrite(&SV,sizeof(sinhvien),1,fileptr); break;
case 4:
gotoxy(61,4+i);
cout<<"|";
cin>>x;
SV.diemHoa=x;
gotoxy(71,4+i);
cout<<"|";
cout<<"\n" ;
fwrite(&SV,sizeof(sinhvien),1,fileptr);
BACK_TO_MENU; break;
}
}while(mode2);
clrscr();
cout<<"----------------------------------------------------------------------------------\n";
cout<<"| STT | MaSV | HO VA TEN |DIEM toan|DIEM ly|DIEM hoa | DTB |\n";
cout<<"----------------------------------------------------------------------------------\n";
gotoxy(0,6+i);
cout<<i;
gotoxy(7,6+i);
cout<<"| ";
cout<<SV.SBD;
gotoxy(15,6+i);
cout<<"| ";
cout<<SV.hoten;
gotoxy(43,6+i);
cout<<"| ";
cout<<SV.diemToan;
gotoxy(53,6+i);
cout<<"|";
cout<<SV.diemLy;
gotoxy(63,6+i);
cout<<"|";
cout<<SV.diemHoa;
gotoxy(73,6+i);
cout<<"|";
cout<<(SV.diemToan+SV.diemLy+SV.diemHoa)/3;
gotoxy(73,6+i);
cout<<"|";
cout<<"\n";
fwrite(&SV,sizeof(sinhvien),1,fileptr);
}
}
cout<<"---------------------------------------------------------------\n";
cout<<"Ban da sua danh sach thanh "<<n-1<<" sinh vien";
dem=dem-1;
cout<<"dem =: "<<dem<<" : ";
xuat_mang_sv(SV,dem);
fclose(fileptr); BACK_TO_MENU;
}
void main()
{
clrscr();
int mode=0;
sinhvien SV;
do
{ mode=menu();
switch(mode)
{ case 1:nhapSV();break;
case 2uatfilesv();BACK_TO_MENU;break;
case 3:timkiemsv();BACK_TO_MENU;break;
case 4:suasv();BACK_TO_MENU;break;
// case 5oasv();break;
case 0:exit(0);
}
} while(mode!=0);
getch();
}
thanks nhìu nhìu !
Bookmarks