Ðåôåðàò: Îò÷åò ïî ó÷åáíîé ïðàêòèêå ÎÀèÏ áàçà äàííûõ ñòóäåíòîâ (ñîçäàíèå, ïîèñê, óäàëåíèå, ñîðòèðîâêà, âñå, ÷òî íàäî íàïèñàííàÿ íà Ñ++)
if (strcmp(s1.firstName,s2.firstName) > 0) {
fseek(fp,-2*size,1);
fwrite(&s2,size,1,fp);
fwrite(&s1,size,1,fp);
newfs=1;
}
if (strcmp(s1.firstName,s2.firstName) == 0)
if (strcmp(s1.midName,s2.midName) > 0) {
fseek(fp,-2*size,1);
fwrite(&s2,size,1,fp);
fwrite(&s1,size,1,fp);
newfs=1;
}
else
s1=s2;
else
s1=s2;
}
break;
case 0: /*------------ÏÎ ÍÎÌÅÐÓ ÇÀÏÈÑÈ-----------*/
oldfs=1; newfs=0;
fread(&s1,size,1,fp);
while(oldfs) {
fread(&s2,size,1,fp);
if(feof(fp)) {
if(!newfs)
break;
oldfs=1; newfs=0;
rewind(fp);
fread(&s1,size,1,fp);
continue;
}
if (s1.num > s2.num) {
fseek(fp,-2*size,1);
fwrite(&s2,size,1,fp);
fwrite(&s1,size,1,fp);
newfs=1;
}
else
s1=s2;
}
break;
case 2: /*----------ÏÎ ÍÎÌÅÐÓ ÃÐÓÏÏÛ---------------*/
oldfs=1; newfs=0;
fread(&s1,size,1,fp);
while(oldfs) {
fread(&s2,size,1,fp);
if(feof(fp)) {
if(!newfs)
break;
oldfs=1; newfs=0;
rewind(fp);
fread(&s1,size,1,fp);
continue;
}
if (strcmp(s1.groupNumber,s2.groupNumber) > 0) {
fseek(fp,-2*size,1);
fwrite(&s2,size,1,fp);
fwrite(&s1,size,1,fp);
newfs=1;
}
else
s1=s2;
}
break;
case 3: /*---------ÏÎ ÑÐ.ÁÀËÓ----------------*/
oldfs=1; newfs=0;
fread(&s1,size,1,fp);
while(oldfs) {
fread(&s2,size,1,fp);
if(feof(fp)) {
if(!newfs)
break;
oldfs=1; newfs=0;
rewind(fp);
fread(&s1,size,1,fp);
continue;
}
if (s1.mark < s2.mark) {
fseek(fp,-2*size,1);
fwrite(&s2,size,1,fp);
fwrite(&s1,size,1,fp);
newfs=1;
}
else
s1=s2;
} break;
case 4:
fclose(fp);
return;
}
fclose(fp);
}
}
}
void find(char *fn)
{
void ramka();
FILE* fp;
data st;
char string[15];
int pr,prs;
int key=0,counter=0;
int color[]={0,4,4,4};
while (1) {
clrscr(); textcolor(10);
cprintf("::::::::::::::::::::::::::::: Ì å í þ Ï î è ñ ê à "
":::::::::::::::::::::::::::::");
textcolor(WHITE);
textbackground(4);
cprintf(" ");
switch(key)
{
case LEFT: if (counter>0) {
color[counter]=4;
color[--counter]=0;
} break;
case RIGHT: if (counter<3) {
color[counter]=4;
color[++counter]=0;
} break;
}
textbackground(color[0]); cprintf(" ïî ¹ çàïèñè ");
textbackground(color[1]); cprintf(" ïî Ôàìèëèè ");
textbackground(color[2]); cprintf(" ïî Èìåíè ");
textbackground(color[3]); cprintf(" Îòìåíà ");
textbackground(4);
cprintf(" ");
textbackground(1);
key=bioskey(0);
if (key==283)
return;
if (key == ENTER)
{
if((fp=fopen(fn,"rb"))==NULL) {
puts("File couldn't be open");
return;
}
switch(counter)
{
case 0:
int number;
pr=0;
prs=1;
cout<<"ÂÂÅÄÈÒÅ ÍÎÌÅÐ ÇÀÏÈÑÈ : ";
fflush(stdin);
scanf("%d",&number);
rewind(fp);
while(fread(&st,sizeof(data),1,fp)) {
if (feof(fp)) {
break;
}
if(st.num == number) {
if (prs) {
ramka();
gotoxy(1,6);
prs=0;
}
printf(" %4d %-16s %-12s %-17s %8s "
"%7.2f\n",st.num,st.lastName,st.firstName,
st.midName,st.groupNumber,st.mark);
pr=1;
}
}
if(!pr) {
cout<<"\nÇÀÏÈÑÈ Ñ ÒÀÊÈÌ ÍÎÌÅÐÎÌ ÍÅ ÑÓÙÅÑÒÂÓÅÒ";
}
getch();
break;
case 1:
prs=1;
pr=0;
cout<<"ÂÂÅÄÈÒÅ ÔÀÌÈËÈÞ : ";
fflush(stdin);
cin>>string;
rewind(fp);
while(fread(&st,sizeof(data),1,fp)) {
if (feof(fp))
break;
if(!strcmp(st.lastName,string)) {
if (prs) {
ramka();
gotoxy(1,6);
prs=0;
}
printf(" %4d %-16s %-12s %-17s %8s "
"%7.2f\n",st.num,st.lastName,st.firstName,
st.midName,st.groupNumber,st.mark);
pr=1;
}
}
if(!pr) {
cout<<"\nÍÅÒ ÄÀÍÍÛÕ";
}
getch();
break;
case 2:
prs=1;
pr=0;
cout<<"ÂÂÅÄÈÒÅ ÈÌß : ";
fflush(stdin);
cin>>string;
rewind(fp);
while(fread(&st,sizeof(data),1,fp)) {
if (feof(fp))
break;
if(!strcmp(st.firstName,string)) {
if (prs) {
ramka();
gotoxy(1,6);
prs=0;
}
printf(" %4d %-16s %-12s %-17s %8s "
"%7.2f\n",st.num,st.lastName,st.firstName,
st.midName,st.groupNumber,st.mark);
pr=1;
}
}
if(!pr) {
cout<<"\nÍÅÒ ÄÀÍÍÛÕ";
}
getch();
break;
case 3:
fclose(fp);
return;
}
fclose(fp);
}
}
}
void ramka()
{
window(1,3,80,6);
cprintf("------------------------------------"
"--------------------------------------------");
textcolor(14);
cprintf("%5s %-16s %-12s %-17s %-8s %12s ",
"¹","Ôàìèëèÿ","Èìÿ","Îò÷åñòâî","¹ ãðóïïû","Ñð.áàëë");
textcolor(WHITE);
cprintf("------------------------------------"
"--------------------------------------------");
window(1,1,80,25);
}
int find_max_num(char *fn)
{
FILE *fp;
data st;
int max;
if ((fp = fopen(fn,"rb")) == NULL) {
printf("File could not be opened.\n");
return -1;
}
max=0;
while (fread(&st,sizeof(data),1,fp)) {
if (feof(fp))
break;
if (st.num>max)
max=st.num;
}
fclose(fp);
return max;
}
int get_number(char *fn)
{
FILE *fp;
int fd,n=0;
if ((fp = fopen(fn,"rb")) == NULL)
{
printf("File could not be opened.\n");
return -1;
}
fd=fileno(fp);
n=filelength(fd)/sizeof(data);
fclose(fp);
return n;
}
void create()
{
FILE *fp;
char *fn;
cout<<"Ââåäèòå èìÿ íîâîé ÁÄ : ";
fflush(stdin);
cin>>fn;
strcat(fn,".dat");
if ((fp=fopen(fn,"wb")) == NULL) {
cout<<"Îøèáêà...Ôàéë íå ìîæåò áûòü ñîçäàí\n";
getch();
exit(10);
}
fclose(fp);
interface(fn);
}
void open()
{
FILE *fp;
char *fn;
cout<<"Ââåäèòå èìÿ ÁÄ : ";
fflush(stdin);
cin>>fn;
strcat(fn,".dat");
if (!(fp=fopen(fn,"rb"))) {
cout<<"Îøèáêà...Ôàéë íå ìîæåò áûòü îòêðûò\n";
getch();
exit(10);
}
fclose(fp);
interface(fn);
}
int check(char *fn, data st)
{
FILE *fp;
data temp;
int pr=0;
if ((fp = fopen(fn,"rb")) == NULL) {
printf("File could not be opened.\n");
return 0;
}
while ( fread( &temp, sizeof( data ), 1, fp)) {
if (feof(fp))
break;
if (!strcmp(st.lastName,temp.lastName)
&& !strcmp(st.firstName,temp.firstName)
&& !strcmp(st.midName,temp.midName)
&& !strcmp(st.groupNumber,temp.groupNumber)
&& (st.mark == temp.mark)) {
pr=1;
break;
}
} fclose(fp);
return pr;
}
ÑÏÈÑÎÊ ËÈÒÅÐÀÒÓÐÛ
- Õàðâè Äåéòåë, Ïîë Äåéòåë “Êàê ïðîãðàììèðîâàòü íà Ñè”
- Å. Ì. Äåìèäîâè÷ “Îñíîâû àëãîðèòìèçàöèè è ïðîãðàììèðîâàíèÿ”, Ìèíñê 1999 ã.
- Êåðíèãàí Á., Ðèò÷è Ä. “ßçûê ïðîãðàììèðîâàíèÿ Ñè”, Ôèíàíñû è ñòàòèñòèêà, 1992 ã.