ی خوام ببینم برنامه من چرا اجرا نمی شه؟مشکلش کجاست؟چرا سر goto xy , clrscr اشکال می گیره؟ و فایل txt اون چه طوری باید باشه؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
struct student
{
char name[10];
char family[15];
char stdnum[10];
float math;
float ccp;
char date[10];
char code[5];
char del;
};
int i=0;
int display(char choice);
char menu();
student reads(student std,int i);
void writes(student std,int i);
void calculate();
void reorganize();
void update();
void delet();
void search();
void sort();
///////////////////////////////////////////////////////////
//**********************************************************
char menu()
{
char chs;
//clrscr();
//gotoxy(17,5);
cout<<"\nmenu ";
//gotoxy(15,6);
cout<<" \n1)add ";
//gotoxy(15,7);
cout<<" \n2)display ";
//gotoxy(15,8);
cout<<" \n3)calculate ";
//gotoxy(15,9);
cout<<" \n4)reorganize ";
//gotoxy(15,10);
cout<<" \n5)update ";
//gotoxy(15,11);
cout<<" \n6)delete ";
//gotoxy(15,12);
cout<<" \n7)search ";
//gotoxy(15,13);
cout<<" \n8)sort ";
//gotoxy(15,14);
cout<<" \n0)quit ";
//gotoxy(15,15);
cout<<"\nenter your choice 0-7 : ";
//gotoxy(40,15);
cin>>chs;
//clrscr();
return(chs);
}
////////////////////////////////////////////////
int add()
{
int i=5;
char more='Y';
student std;
FILE *fp;
if((fp=fopen("d:\\pcpp\\stud.txt","a+t"))==NULL)
{
cout<<"couldn't open the file.\n";
getch();
exit(0);
}
while((more=='Y')||(more=='Y'))
{
std=reads(std,i);
fwrite(&std,sizeof(struct student),1,fp);
//gotoxy(73,4);
cout<<"\nmore ";
//gotoxy(73,3);
cout<<"----";
//gotoxy(73,i);
cin>>more;
i++;
}
fclose(fp);
return 0;
}
//////////////////////////////////////////////////////
int display(char choice)
{
struct student std;
FILE *fp;
fp=fopen("d:\\pcpp\\stud.txt","r");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
i=5;
//clrscr();
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
if(std.del!=choice)
{
writes(std,i);
i++;
}
}
fclose(fp);
getch();
return 0;
}
/////////////////////////////////////////////////////
void calculate()
{
float summ=0,sumc=0,c=0,maxm=0,maxc=0,minm=100,minc=100;
FILE *fp;
student std;
fp=fopen("d:\\pcpp\\stud.txt","a+t");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
//clrscr();
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
summ+=std.math;
if(std.math>maxm)
maxm=std.math;
if(std.math<minc)
minm=std.math;
sumc+=std.ccp;
if(std.ccp>maxc)
maxc=std.ccp;
if(std.ccp<minc)
minc=std.ccp;
c++;
}
fclose(fp);
cout<<"\n\n the average of math is: "<<summ/c;
cout<<"\n\n the maximom of math is : "<<maxm;
cout<<"\n\n the minimom of math is : "<<minm;
cout<<"\n\n the average of cpp is : "<<sumc/c;
cout<<"\n\n the maximom of cpp is : "<<maxc;
cout<<"\n\n the minimom of cpp is : "<<minc;
getch();
}
//////////////////////////////////////////////////////////
student reads(struct student std,int i)
{
//gotoxy(33,2);
puts("<<input data>>");
//gotoxy(4,3);
cout<<"\nname ";
//gotoxy(17,3);
cout<<"\nfamily";
//gotoxy(29,3);
cout<<"\nstd-num";
//gotoxy(41,3);
cout<<"\nmath";
//gotoxy(47,3);
cout<<"\ncpp";
//gotoxy(54,3);
cout<<"\ndate";
//gotoxy(63,3);
cout<<"\ncode";
//gotoxy(69,3);
cout<<"\ndel";
//gotoxy(1,4);
cout<<"--------- -------- ---------";
cout<<"--- --- ------- --- --";
//gotoxy(1,i);
gets(std.name);
//gotoxy(12,i);
gets(std.family);
//gotoxy(28,i);
gets(std.stdnum);
//gotoxy(40,i);
cin>>std.math;
//gotoxy(47,i);
cin>>std.ccp;
//gotoxy(52,i);
gets(std.date);
//gotoxy(64,i);
gets(std.code);
//gotoxy(69,i);
cin>>std.del;
return(std);
}
/////////////////////////////////////////////
void writes(struct student std,int i)
{
//gotoxy(52,2);
puts("<<output data>>");
//gotoxy(4,3);
cout<<"\nname";
//gotoxy(17,3);
cout<<"\nfamily";
//gotoxy(29,3);
cout<<"\nstd-num";
//gotoxy(41,3);
cout<<"\nmath";
//gotoxy(47,3);
cout<<"\ncpp";
//gotoxy(54,3);
cout<<"\ndate";
//gotoxy(63,3);
cout<<"\ncode";
//gotoxy(69,3);
cout<<"\ndel";
//gotoxy(1,4);
cout<<"--------- -------- ---------";
cout<<"--- --- ------- --- --";
//gotoxy(1,i);
cout<<std.name;
//gotoxy(12,i);
cout<<std.family;
//gotoxy(28,i);
cout<<std.stdnum;
//gotoxy(40,i);
//precision(2);
cout<<std.math;
//gotoxy(47,i);
cout<<std.ccp;
//gotoxy(53,i);
cout<<std.date;
//gotoxy(64,i);
cout<<std.code;
//gotoxy(70,i);
cout<<std.del;
}
///////////////////////////////////////////////////////////////////////
void reorganize()
{
FILE *fp,*hfp;
student std;
fp=fopen("d:\\pcpp\\stud.txt","a+t");
if(fp==NULL)
{
cout<<"couldn't open the file.\n";
getch();
exit(0);
}
hfp=fopen("d:\\pcpp\\hstud.txt","a+t");
if(hfp==NULL)
{
cout<<"couldn't open the help file.\n";
getch();
exit(0);
}
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(std.del!='0')
fwrite(&std,sizeof(student),1,fp);
}
fclose(fp);
fclose(hfp);
remove("d:\\pcpp\\stud.txt");
rename("d:\\pcpp\\hstud.txt","d:\\pcpp\\stud.txt");
getch();
}
////////////////////////////////////////////////////////////////////
void update()
{
int j,i=6,c=0;
FILE *fp;
student std;
cout<<"\n enter number of your student : ";
cin>>j;
fp=fopen("d:\\pcpp\\stud.txt","r+t");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
c++;
}
if(j<c)
{
rewind(fp);
fseek(fp,j*sizeof(student),SEEK_SET);
fread(&std,sizeof(struct student),1,fp);
fclose(fp);
}
else
cout<<"\n it's not in file.";
getch();
}
//////////////////////////////////////////////////////////////////
void delet()
{
int j,i=6,c=0;
char r='y';
FILE *fp;
student std;
cout<<"\n enter number of your student for delet : ";
cin>>j;
fp=fopen("d:\\pcpp\\stud.txt","r+t");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
c++;
}
if(j<c)
{
if(j>=0)
fseek(fp,j*sizeof(student),SEEK_SET);
fread(&std,sizeof(struct student),1,fp);
writes(std,i);
cout<<"\n delete this record (Y/N)? ";
cin>>r;
if((r!='n')&&(r!='N'))
{
std.del='0';
if(j>=0)
fseek(fp,j*sizeof(student),SEEK_SET);
fread(&std,sizeof(struct student),1,fp);
fclose(fp);
}
else
cout<<"\n it's not in file.";
// }
getch();
}
}
///////////////////////////////////////////////////////////////////
void search()
{
int i=6;
float j;
student std;
FILE *fp;
char choice,numstr[15];
//clrscr();
fp=fopen("d:\\pcpp\\stud.txt","r+t");
if(fp==NULL)
{
cout<<"couldn't open the file.\n";
getch();
exit(0);
}
//gotoxy(17,5);
cout<<" \ndo search? ";
//gotoxy(15,6);
cout<<" \n1)name ";
//gotoxy(15,7);
cout<<" \n2)family ";
//gotoxy(15,8);
cout<<" \n3)student number ";
//gotoxy(15,9);
cout<<" \n4)math ";
//gotoxy(15,10);
cout<<" \n5)cpp ";
//gotoxy(15,11);
cout<<" \n6)date ";
//gotoxy(15,12);
cout<<" \n7)code ";
//gotoxy(15,13);
cout<<" \nenter your choice 1-7 : ";
//gotoxy(40,13);
cin>>choice;
//clrscr();
switch (choice)
{
case '1':
cout<<"\n enter the name : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
if(!strcmp(std.name,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this name . ";
break;
case '2':
cout<<" \nenter the family : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(!strcmp(std.family,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this family . ";
break;
case '3':
cout<<" \nenter the student number : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(!strcmp(std.stdnum,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this student number . ";
break;
case '4':
cout<<" \nenter the math : ";
cin>>j;
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(std.math==j)
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this math number . ";
break;
case '5':
cout<<" \nenter the cpp : ";
cin>>j;
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(std.ccp==j)
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with cpp number . ";
break;
case '6':
cout<<" \nenter the date : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(!strcmp(std.date,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this date . ";
break;
case '7':
cout<<" \nenter the code : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
if(!strcmp(std.code,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this code . ";
break;
default:
cout<<"\nyour choice is wrong . ";
}
getch();
}
//////////////////////////////////////////////////////////////////////////////////
void sort()
{
int n=0,j,k,m;
student hstd[20],temp,std;
FILE *fp,*sf;
fp=fopen("d:\\pcpp\\stud,txt","r");
if(fp==NULL)
{
cout<<"\ncouldn't open the file !!! ";
getch();
}
while(!feof(fp))
{
fread(&hstd[n],sizeof(student),1,fp);
n++;
}
fclose(fp);
sf=fopen("d:\\pcpp\\sort.txt","a+t");
if (sf==NULL)
{
cout<<" \ncan not open sort file !!! ";
getch();
exit(0);
}
for(j=0;j<n;j++)
for(k=0;k<n-j;k++)
{
m=strcmp(hstd[k].family,hstd[k+1].family);
if(m>0)
{
temp=hstd[k];
hstd[k]=hstd[k+1];
hstd[k+1]=temp;
}
}
for(j=0;j<=n;j++)
{
fwrite(&hstd[j],sizeof(student),1,sf);
}
fclose(sf);
sf=fopen("d:\\pcpp\\sort.txt","r");
if (sf==NULL)
{
cout<<" \ncan not open sort file !!! ";
getch();
exit(0);
}
i=5;
//clrscr();
while(!feof(sf))
{
fread(&std,sizeof(struct student),1,sf);
writes(std,i);
i++;
}
fclose(sf);
remove("d:\\pcpp\\sort.txt");
getch();
return;
}
//***********************************************************
//////////////////////////////////////////////////////////////
main()
{
int retrnv;
char choice;
retrnv=menu();
while (retrnv!='0')
{
switch(retrnv)
{
case '1':
add();
break;
case '2':
//clrscr();
//gotoxy(17,5);
cout<<"\nmenu ";
//gotoxy(15,6);
cout<<" \n0)just display del=1 ";
//gotoxy(15,7);
cout<<" \n2)display all objects ";
//gotoxy(15,8);
cout<<" \nenter your choice 0 or 2 :";
cin>>choice;
display (choice);
break;
case '3':
calculate();
break;
case '4':
reorganize();
break;
case '5':
update();
break;
case '6':
delet();
break;
case '7':
search();
break;
case '8':
sort();
break;
default:
cout<<"\nyour choice is wrong!!!\n";
cout<<"\nplease enter new select.\n";
}
retrnv=menu();
}
return 0;
}
/////////////////////////////////////////////////////////////
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
struct student
{
char name[10];
char family[15];
char stdnum[10];
float math;
float ccp;
char date[10];
char code[5];
char del;
};
int i=0;
int display(char choice);
char menu();
student reads(student std,int i);
void writes(student std,int i);
void calculate();
void reorganize();
void update();
void delet();
void search();
void sort();
///////////////////////////////////////////////////////////
//**********************************************************
char menu()
{
char chs;
//clrscr();
//gotoxy(17,5);
cout<<"\nmenu ";
//gotoxy(15,6);
cout<<" \n1)add ";
//gotoxy(15,7);
cout<<" \n2)display ";
//gotoxy(15,8);
cout<<" \n3)calculate ";
//gotoxy(15,9);
cout<<" \n4)reorganize ";
//gotoxy(15,10);
cout<<" \n5)update ";
//gotoxy(15,11);
cout<<" \n6)delete ";
//gotoxy(15,12);
cout<<" \n7)search ";
//gotoxy(15,13);
cout<<" \n8)sort ";
//gotoxy(15,14);
cout<<" \n0)quit ";
//gotoxy(15,15);
cout<<"\nenter your choice 0-7 : ";
//gotoxy(40,15);
cin>>chs;
//clrscr();
return(chs);
}
////////////////////////////////////////////////
int add()
{
int i=5;
char more='Y';
student std;
FILE *fp;
if((fp=fopen("d:\\pcpp\\stud.txt","a+t"))==NULL)
{
cout<<"couldn't open the file.\n";
getch();
exit(0);
}
while((more=='Y')||(more=='Y'))
{
std=reads(std,i);
fwrite(&std,sizeof(struct student),1,fp);
//gotoxy(73,4);
cout<<"\nmore ";
//gotoxy(73,3);
cout<<"----";
//gotoxy(73,i);
cin>>more;
i++;
}
fclose(fp);
return 0;
}
//////////////////////////////////////////////////////
int display(char choice)
{
struct student std;
FILE *fp;
fp=fopen("d:\\pcpp\\stud.txt","r");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
i=5;
//clrscr();
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
if(std.del!=choice)
{
writes(std,i);
i++;
}
}
fclose(fp);
getch();
return 0;
}
/////////////////////////////////////////////////////
void calculate()
{
float summ=0,sumc=0,c=0,maxm=0,maxc=0,minm=100,minc=100;
FILE *fp;
student std;
fp=fopen("d:\\pcpp\\stud.txt","a+t");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
//clrscr();
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
summ+=std.math;
if(std.math>maxm)
maxm=std.math;
if(std.math<minc)
minm=std.math;
sumc+=std.ccp;
if(std.ccp>maxc)
maxc=std.ccp;
if(std.ccp<minc)
minc=std.ccp;
c++;
}
fclose(fp);
cout<<"\n\n the average of math is: "<<summ/c;
cout<<"\n\n the maximom of math is : "<<maxm;
cout<<"\n\n the minimom of math is : "<<minm;
cout<<"\n\n the average of cpp is : "<<sumc/c;
cout<<"\n\n the maximom of cpp is : "<<maxc;
cout<<"\n\n the minimom of cpp is : "<<minc;
getch();
}
//////////////////////////////////////////////////////////
student reads(struct student std,int i)
{
//gotoxy(33,2);
puts("<<input data>>");
//gotoxy(4,3);
cout<<"\nname ";
//gotoxy(17,3);
cout<<"\nfamily";
//gotoxy(29,3);
cout<<"\nstd-num";
//gotoxy(41,3);
cout<<"\nmath";
//gotoxy(47,3);
cout<<"\ncpp";
//gotoxy(54,3);
cout<<"\ndate";
//gotoxy(63,3);
cout<<"\ncode";
//gotoxy(69,3);
cout<<"\ndel";
//gotoxy(1,4);
cout<<"--------- -------- ---------";
cout<<"--- --- ------- --- --";
//gotoxy(1,i);
gets(std.name);
//gotoxy(12,i);
gets(std.family);
//gotoxy(28,i);
gets(std.stdnum);
//gotoxy(40,i);
cin>>std.math;
//gotoxy(47,i);
cin>>std.ccp;
//gotoxy(52,i);
gets(std.date);
//gotoxy(64,i);
gets(std.code);
//gotoxy(69,i);
cin>>std.del;
return(std);
}
/////////////////////////////////////////////
void writes(struct student std,int i)
{
//gotoxy(52,2);
puts("<<output data>>");
//gotoxy(4,3);
cout<<"\nname";
//gotoxy(17,3);
cout<<"\nfamily";
//gotoxy(29,3);
cout<<"\nstd-num";
//gotoxy(41,3);
cout<<"\nmath";
//gotoxy(47,3);
cout<<"\ncpp";
//gotoxy(54,3);
cout<<"\ndate";
//gotoxy(63,3);
cout<<"\ncode";
//gotoxy(69,3);
cout<<"\ndel";
//gotoxy(1,4);
cout<<"--------- -------- ---------";
cout<<"--- --- ------- --- --";
//gotoxy(1,i);
cout<<std.name;
//gotoxy(12,i);
cout<<std.family;
//gotoxy(28,i);
cout<<std.stdnum;
//gotoxy(40,i);
//precision(2);
cout<<std.math;
//gotoxy(47,i);
cout<<std.ccp;
//gotoxy(53,i);
cout<<std.date;
//gotoxy(64,i);
cout<<std.code;
//gotoxy(70,i);
cout<<std.del;
}
///////////////////////////////////////////////////////////////////////
void reorganize()
{
FILE *fp,*hfp;
student std;
fp=fopen("d:\\pcpp\\stud.txt","a+t");
if(fp==NULL)
{
cout<<"couldn't open the file.\n";
getch();
exit(0);
}
hfp=fopen("d:\\pcpp\\hstud.txt","a+t");
if(hfp==NULL)
{
cout<<"couldn't open the help file.\n";
getch();
exit(0);
}
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(std.del!='0')
fwrite(&std,sizeof(student),1,fp);
}
fclose(fp);
fclose(hfp);
remove("d:\\pcpp\\stud.txt");
rename("d:\\pcpp\\hstud.txt","d:\\pcpp\\stud.txt");
getch();
}
////////////////////////////////////////////////////////////////////
void update()
{
int j,i=6,c=0;
FILE *fp;
student std;
cout<<"\n enter number of your student : ";
cin>>j;
fp=fopen("d:\\pcpp\\stud.txt","r+t");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
c++;
}
if(j<c)
{
rewind(fp);
fseek(fp,j*sizeof(student),SEEK_SET);
fread(&std,sizeof(struct student),1,fp);
fclose(fp);
}
else
cout<<"\n it's not in file.";
getch();
}
//////////////////////////////////////////////////////////////////
void delet()
{
int j,i=6,c=0;
char r='y';
FILE *fp;
student std;
cout<<"\n enter number of your student for delet : ";
cin>>j;
fp=fopen("d:\\pcpp\\stud.txt","r+t");
if(fp==NULL)
{
cout<<"\ncouldn't open the file.\n";
getch();
exit(0);
}
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
c++;
}
if(j<c)
{
if(j>=0)
fseek(fp,j*sizeof(student),SEEK_SET);
fread(&std,sizeof(struct student),1,fp);
writes(std,i);
cout<<"\n delete this record (Y/N)? ";
cin>>r;
if((r!='n')&&(r!='N'))
{
std.del='0';
if(j>=0)
fseek(fp,j*sizeof(student),SEEK_SET);
fread(&std,sizeof(struct student),1,fp);
fclose(fp);
}
else
cout<<"\n it's not in file.";
// }
getch();
}
}
///////////////////////////////////////////////////////////////////
void search()
{
int i=6;
float j;
student std;
FILE *fp;
char choice,numstr[15];
//clrscr();
fp=fopen("d:\\pcpp\\stud.txt","r+t");
if(fp==NULL)
{
cout<<"couldn't open the file.\n";
getch();
exit(0);
}
//gotoxy(17,5);
cout<<" \ndo search? ";
//gotoxy(15,6);
cout<<" \n1)name ";
//gotoxy(15,7);
cout<<" \n2)family ";
//gotoxy(15,8);
cout<<" \n3)student number ";
//gotoxy(15,9);
cout<<" \n4)math ";
//gotoxy(15,10);
cout<<" \n5)cpp ";
//gotoxy(15,11);
cout<<" \n6)date ";
//gotoxy(15,12);
cout<<" \n7)code ";
//gotoxy(15,13);
cout<<" \nenter your choice 1-7 : ";
//gotoxy(40,13);
cin>>choice;
//clrscr();
switch (choice)
{
case '1':
cout<<"\n enter the name : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
if(!strcmp(std.name,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this name . ";
break;
case '2':
cout<<" \nenter the family : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(!strcmp(std.family,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this family . ";
break;
case '3':
cout<<" \nenter the student number : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(!strcmp(std.stdnum,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this student number . ";
break;
case '4':
cout<<" \nenter the math : ";
cin>>j;
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(std.math==j)
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this math number . ";
break;
case '5':
cout<<" \nenter the cpp : ";
cin>>j;
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(std.ccp==j)
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with cpp number . ";
break;
case '6':
cout<<" \nenter the date : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(student),1,fp);
if(!strcmp(std.date,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this date . ";
break;
case '7':
cout<<" \nenter the code : ";
gets(numstr);
while(!feof(fp))
{
fread(&std,sizeof(struct student),1,fp);
if(!strcmp(std.code,numstr))
{
writes(std,i);
i++;
}
}
if(i==6)
cout<<" \nthere is no student with this code . ";
break;
default:
cout<<"\nyour choice is wrong . ";
}
getch();
}
//////////////////////////////////////////////////////////////////////////////////
void sort()
{
int n=0,j,k,m;
student hstd[20],temp,std;
FILE *fp,*sf;
fp=fopen("d:\\pcpp\\stud,txt","r");
if(fp==NULL)
{
cout<<"\ncouldn't open the file !!! ";
getch();
}
while(!feof(fp))
{
fread(&hstd[n],sizeof(student),1,fp);
n++;
}
fclose(fp);
sf=fopen("d:\\pcpp\\sort.txt","a+t");
if (sf==NULL)
{
cout<<" \ncan not open sort file !!! ";
getch();
exit(0);
}
for(j=0;j<n;j++)
for(k=0;k<n-j;k++)
{
m=strcmp(hstd[k].family,hstd[k+1].family);
if(m>0)
{
temp=hstd[k];
hstd[k]=hstd[k+1];
hstd[k+1]=temp;
}
}
for(j=0;j<=n;j++)
{
fwrite(&hstd[j],sizeof(student),1,sf);
}
fclose(sf);
sf=fopen("d:\\pcpp\\sort.txt","r");
if (sf==NULL)
{
cout<<" \ncan not open sort file !!! ";
getch();
exit(0);
}
i=5;
//clrscr();
while(!feof(sf))
{
fread(&std,sizeof(struct student),1,sf);
writes(std,i);
i++;
}
fclose(sf);
remove("d:\\pcpp\\sort.txt");
getch();
return;
}
//***********************************************************
//////////////////////////////////////////////////////////////
main()
{
int retrnv;
char choice;
retrnv=menu();
while (retrnv!='0')
{
switch(retrnv)
{
case '1':
add();
break;
case '2':
//clrscr();
//gotoxy(17,5);
cout<<"\nmenu ";
//gotoxy(15,6);
cout<<" \n0)just display del=1 ";
//gotoxy(15,7);
cout<<" \n2)display all objects ";
//gotoxy(15,8);
cout<<" \nenter your choice 0 or 2 :";
cin>>choice;
display (choice);
break;
case '3':
calculate();
break;
case '4':
reorganize();
break;
case '5':
update();
break;
case '6':
delet();
break;
case '7':
search();
break;
case '8':
sort();
break;
default:
cout<<"\nyour choice is wrong!!!\n";
cout<<"\nplease enter new select.\n";
}
retrnv=menu();
}
return 0;
}
/////////////////////////////////////////////////////////////