Ãëàâíàÿ Ðåôåðàòû ïî ðåêëàìå Ðåôåðàòû ïî ôèçèêå Ðåôåðàòû ïî ôèëîñîôèè Ðåôåðàòû ïî ôèíàíñàì Ðåôåðàòû ïî õèìèè Ðåôåðàòû ïî õîçÿéñòâåííîìó ïðàâó Ðåôåðàòû ïî öèôðîâûì óñòðîéñòâàì Ðåôåðàòû ïî ýêîëîãè÷åñêîìó ïðàâó Ðåôåðàòû ïî ýêîíîìèêî-ìàòåìàòè÷åñêîìó ìîäåëèðîâàíèþ Ðåôåðàòû ïî ýêîíîìè÷åñêîé ãåîãðàôèè Ðåôåðàòû ïî ýêîíîìè÷åñêîé òåîðèè Ðåôåðàòû ïî ýòèêå Ðåôåðàòû ïî þðèñïðóäåíöèè Ðåôåðàòû ïî ÿçûêîâåäåíèþ Ðåôåðàòû ïî þðèäè÷åñêèì íàóêàì Ðåôåðàòû ïî èñòîðèè Ðåôåðàòû ïî êîìïüþòåðíûì íàóêàì Ðåôåðàòû ïî ìåäèöèíñêèì íàóêàì Ðåôåðàòû ïî ôèíàíñîâûì íàóêàì Ðåôåðàòû ïî óïðàâëåí÷åñêèì íàóêàì Ïñèõîëîãèÿ è ïåäàãîãèêà Ïðîìûøëåííîñòü ïðîèçâîäñòâî Áèîëîãèÿ è õèìèÿ ßçûêîçíàíèå ôèëîëîãèÿ Èçäàòåëüñêîå äåëî è ïîëèãðàôèÿ Ðåôåðàòû ïî êðàåâåäåíèþ è ýòíîãðàôèè Ðåôåðàòû ïî ðåëèãèè è ìèôîëîãèè Ðåôåðàòû ïî ìåäèöèíå Ðåôåðàòû ïî ñåêñîëîãèè Ðåôåðàòû ïî èíôîðìàòèêå ïðîãðàììèðîâàíèþ Êðàòêîå ñîäåðæàíèå ïðîèçâåäåíèé |
Ðåôåðàò: Îò÷åò ïî ó÷åáíîé ïðàêòèêå ÎÀèÏ áàçà äàííûõ ñòóäåíòîâ (ñîçäàíèå, ïîèñê, óäàëåíèå, ñîðòèðîâêà, âñå, ÷òî íàäî íàïèñàííàÿ íà Ñ++)Ðåôåðàò: Îò÷åò ïî ó÷åáíîé ïðàêòèêå ÎÀèÏ áàçà äàííûõ ñòóäåíòîâ (ñîçäàíèå, ïîèñê, óäàëåíèå, ñîðòèðîâêà, âñå, ÷òî íàäî íàïèñàííàÿ íà Ñ++)
ÑÎÄÅÐÆÀÍÈÅ
2. Ïîñòàâëåííàÿ çàäà÷à Íàïèñàòü áàçó äàííûõ (ÁÄ) íà ÿçûêå Ñ++ ïîçâîëÿþùóþ õðàíèòü èíôîðìàöèþ î ñòóäåíòàõ (Ô.È.Î., íîìåð ãðóïïû, ñðåäíèé áàëë, óíèêàëüíûé êîä çàïèñè (ïîðÿäêîâûé ¹)). Áàçà äàííûõ äîëæíà ñîäåðæàòü îñíîâíûå ôóíêöèè : äîáàâëåíèå çàïèñè, óäàëåíèå çàïèñè, ðåäàêòèðîâàíèå çàïèñè, ïîèñê è ñîðòèðîâêó ïî çàäàííûì ïàðàìåòðàì. 3. Ôóíêöèîíàëüíîå ïðåäíàçíà÷åíèå ïðîãðàììû Äàííàÿ ïðîãðàììà ïðåäñòàâëÿåò ñîáîé áàçó äàííûõ ïîçâîëÿþùóþ õðàíèòü èíôîðìàöèþ î ñòóäåíòàõ (Ôàìèëèþ, Èìÿ, Îò÷åñòâî, ¹ ãðóïïû, ñðåäíèé áàëë). Ïðîãðàììà ïîçâîëÿåò èñïîëüçîâàòü ñëåäóþùèå âîçìîæíîñòè : ñîçäàíèå íîâîé ÁÄ, ëèáî îòêðûòèé óæå ñîçäàííîé, äîáàâëåíèå íîâûõ äàííûõ â ôàéë ÁÄ, óäàëåíèå çàïèñåé, ðåäàêòèðîâàíèå èìåþùèõñÿ çàïèñåé, ïîèñê ñóùåñòâóþùèõ çàïèñåé ïî èõ óíèêàëüíîìó êîäó, ïî ôàìèëèè, ïî èìåíè, òàêæå ïðåäóñìîòðåíà ñîðòèðîâêà çàïèñåé â ôàéëå ïî Ô.È.Î, ïî óíèêàëüíîìó êîäó, ïî íîìåðó ãðóïïû, ïî ñðåäíåìó áàëëó (ïðè÷åì â ýòîì ñëó÷àå çàïèñè ðàñïîëàãàþòñÿ îò ìàêñèìàëüíîãî ñðåäíåãî áàëëà âíèç, òî åñòü ïî óáûâàíèþ). Êàæäîé íîâîé çàïèñè ïðèñâàèâàåòñÿ ñâîé èíäèâèäóàëüíûé íîìåð (êîä), äëÿ óïðîùåíèÿ ââîäà ýòîò êîä ïðèñâàèâàåòñÿ àâòîìàòè÷åñêè : ôóíêöèé find_max_num(char *) íàõîäèò ìàêñèìàëüíûé íîìåð çàïèñè â ôàéëå è ïîñëåäóþùèé êîä ïðèñâàèâàåòñÿ ââåäåííîé çàïèñè .Òàêæå ïðåäóñìîòðåíà ïðîâåðêà ââîäèìûõ äàííûõ íà èäåíòè÷íîñòü , ïðè ââîäå èäåíòè÷íûõ äàííûõ ïîëüçîâàòåëþ áóäåò âûäàíî ïðåäóïðåæäåíèå è äàíà âîçìîæíîñòü ââåñòè íîâûå äàííûå . Ïðîãðàììà eBase v1.666 èñïîëüçóåò î÷åíü óäîáíûé è ïîíÿòíûé èíòåðôåéñ, îðãàíèçîâàíà ñèñòåìà ìåíþ è ïîäìåíþ, âíèçó îêíà ñïåöèàëüíî ñîçäàíà ãîðÿ÷àÿ ïîäñêàçêà. Òàê æå ïðåäóñìîòðåí òàê íàçûâàåìûé ñêðîëëèíã (ïðîêðóòêà) âûâîäèìîé èíôîðìàöèè êëàâèøàìè ââåðõ-âíèç, 4. Îïèñàíèå óïðàâëåíèÿ, èíòåðôåéñà, îñíîâíûõ ïåðåìåííûõ è ôóíêöèé. Âñå äàííûå ââîäÿòñÿ ñ êëàâèàòóðû. Èñïîëüçóåìûå êëàâèøè: Enter (äëÿ âûáîðà èëè ïîäòâåðæäåíèÿ), Esc (äëÿ îòìåíû, âûõîäà â ïðåäûäóùåå ìåíþ), ñòðåëêè âïðàâî, âëåâî (äëÿ ïåðåìåùåíèÿ ïî ìåíþ), ââåðõ, âíèç (äëÿ ñêðîëëèíãà äàííûõ). Îñíîâíûå ïåðåìåííûå: ñòðóêòóðà çàïèñåé :
typedef struct { int num; - óíèêàëüíûé ¹ (êîä) çàïèñè char lastName[16]; - ôàìèëèÿ ñòóäåíòà char firstName[11]; - èìÿ ñòóäåíòà char midName[16]; - îò÷åñòâî ñòóäåíòà char groupNumber[6]; - ¹ ãðóïïû ñòóäåíòà float mark; - ñðåäíèé áàëë ó÷àùåãîñÿ } data;
fn - èìÿ ðàáî÷åãî ôàéëà; Âûçûâàåìûå ôóíêöèè: void interface(char *) - ôóíêöèÿ îñíîâíîãî èíòåðôåéñà ïðîãðàììû.  êà÷åñòâå âõîäíîãî ïàðàìåòðà ïðèíèìàåò èìÿ ðàáî÷åãî ôàéëà fn êîòîðîå ïåðåäàåòñÿ ôóíêöèÿìè void create() èëè void open().  ýòîé ôóíêöèè ðåàëèçîâàíî âåñüìà óäîáíîå ìåíþ, ÷åðåç êîòîðîå è ïðîèñõîäèò âûçîâ ïîñëåäóþùèé ôóíêöèÿ äîáàâëåíèÿ, ñîðòèðîâêè, óäàëåíèÿ, ïîèñêà è ðåäàêòèðîâàíèÿ; void add(char *) - ôóíêöèÿ äîáàâëåíèå çàïèñè â ÁÄ. Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà. Èñïîëüçóåò ôóíêöèþ int find_max_num(char *) äëÿ ïðèñâàèâàíèÿ ââîäèìîé çàïèñè ñâîé óíèêàëüíûé íîìåð. void del(char *) - ôóíêöèÿ óäàëåíèå çàïèñè èç ÁÄ. Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà. Èñïîëüçóåò âðåìåííûé ôàéë temp.$$$, â êîíöå âûïîëíåíèÿ ôóíêöèè âðåìåííûé ôàéë ïåðåèìåíîâûâàåòñÿ â ôàéë ïîä èìåíåì ïåðåìåííîé fn; void edit(char *) - ôóíêöèÿ ðåäàêòèðîâàíèÿ ñóùåñòâóþùåé çàïèñè. Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà. Ïîçâîëÿåò èçìåíÿòü ¹ (êîä) çàïèñè, à òàêæå ëþáóþ èíôîðìàöèþ çàïèñè; void view(char *, int ) - ôóíêöèÿ âûâîäà äàííûõ íà ýêðàí. Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà; void find(char *) - ôóíêöèÿ ïîèñêà çàïèñè ïî (åå óíèêàëüíîìó ¹,ïî Ôàìèëèè, ïî Èìåíè). Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà; void sort(char *) - ôóíêöèÿ ñîðòèðîâêè çàïèñåé ÁÄ ïî (¹ çàïèñåé, Ô.È.Î, ñðåäíåìó áàëëó ó÷àùèõñÿ, ¹ ãðóïïû ñòóäåíòà). Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà. Èñïîëüçóåò “ïóçûðüêîâûé” ìåòîä ñîðòèðîâêè äàííûõ â ôàéëå. int find_max_num(char *) - ôóíêöèÿ ïîèñêà ìàêñèìàëüíîãî ¹ çàïèñè â ôàéëå ÁÄ. Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà. Âîçâðàùàåò çíà÷åíèå ¹ ìàêñèìàëüíîé çàïèñè â ôàéëå … äëÿ ôóíêöèè void add(char *); int get_number(char *) - âîçâðàùàåò êîëè÷åñòâî çàïèñåé â ôàéëå. Âõîäíîé ïàðàìåòð fn èìÿ ôàéëà; void create() - ñîçäàíèå ôàéëà ÁÄ. Èäåò çàïðîñ íà èìÿ ôàéëà , ïîñëå ýòîãî ê èìåíè ôàéëà àâòîìàòè÷åñêè äîáàâëÿåòñÿ ðàñøèðåíèå “.dat” èìÿ ýòîãî ôàéëà ñ÷èòàåòñÿ ðàáî÷èì äëÿ âñåé ïðîãðàììû. Ïðè óäà÷íîì ñîçäàíèè ôàéëà åãî èìÿ ïåðåäàåòñÿ â ôóíêöèþ void interface(char *) è ò.ä.; void open() - îòêðûòèå ôàéëà ÁÄ. Èäåò çàïðîñ íà èìÿ ôàéëà , ïîñëå ýòîãî ê èìåíè ôàéëà àâòîìàòè÷åñêè äîáàâëÿåòñÿ ðàñøèðåíèå “.dat” èìÿ ýòîãî ôàéëà ñ÷èòàåòñÿ ðàáî÷èì äëÿ âñåé ïðîãðàììû. Ïðè óäà÷íîì îòêðûòèè ôàéëà åãî èìÿ ïåðåäàåòñÿ â ôóíêöèþ void interface(char *) è ò.ä.; int check(char *, data) – ôóíêöèÿ ïðîâåðêè ïðè ââîäå èíôîðìàöèè íà åå èäåíòè÷íîñòü. Âûçûâàåòñÿ ôóíêöèÿìè äîáàâëåíèÿ çàïèñè void add(char *) è ðåäàêòèðîâàíèÿ çàïèñè void edit(char *).  êà÷åñòâå ïåðâîãî âõîäíîãî çíà÷åíèÿ èñïîëüçóåòñÿ èìÿ ðàáî÷åãî ôàéëà fn , â êà÷åñòâå âòîðîãî ñòðóêòóðà äàííûõ òèïà data (îïèñàííàÿ â ðàçäåëå îñíîâíûå ïåðåìåííûå).  êà÷åñòâå âîçâðàùàåìîãî ïàðàìåòðà èñïîëüçóåòñÿ ïåðåìåííàÿ pr, êîòîðàÿ ìîæåò ïðèíèìàòü çíà÷åíèÿ 0 èëè 1, äëÿ îïðåäåëåíèÿ èäåíòè÷íîñòè äàííûõ; Íåñòàíäàðòíûå è ñèñòåìíûå ñðåäñòâà, âðîäå áû, íå èñïîëüçóþòñÿÂñå, êðîìå äâóõ, àâàðèéíûå ñèòóàöèè, âðîäå áû, ëèêâèäèðîâàíû: 1) Åñëè äèñê çàïîëíåí èëè çàùèù¸í îò çàïèñè íåâîçìîæíî çàïèñàòü èíôîðìàöèþ â ôàéë; 2) Åñëè íåâîçìîæíî îòêðûòü ôàéë ïðîãðàììà âûäàåò ñîîáùåíèå îá ýòîì è çàêðîåòñÿ 5.Áëîê-ñõåìà ïî ÅÑÏÄ 19.003-80. void main() Ëèñò 01
|
|
|
|
fp – óêàçàòåëü íà ôàéë; s1,s2 – ñòðóêòóðû äàííûõ òèïà data;
oldfs,newfs – ôëàãè (ïðèçíàêè),
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <io.h>
#include <iostream.h>
#include <string.h>
#include <bios.h>
#define ENTER 7181
#define ESC 283
#define LEFT 19200
#define RIGHT 19712
#define UP 18432
#define DOWN 20480
typedef struct {
int num;
char lastName[16];
char firstName[11];
char midName[16];
char groupNumber[6];
float mark;
} data;
void interface(char *);
void add(char *);
void del(char *);
void edit(char *);
void view(char *, int );
void find(char *);
void sort(char *);
int find_max_num(char *);
int get_number(char *);
void create();
void open();
int check(char *, data);
void main()
{
int key=0,counter=0;
int color[]={0,4,4};
while (1) {
textbackground(1); textcolor(WHITE);
clrscr(); _setcursortype(_NOCURSOR); textcolor(10);
cprintf("::::::::::::::::::");
textcolor(15);
cprintf(" eBase v1.666 Copyright (C) Serj Sventitski ");
textcolor(10);
cprintf("::::::::::::::::::");
switch(key) {
case LEFT: if (counter>0) {
color[counter]=4;
color[--counter]=0;
}
break;
case RIGHT: if (counter<2) {
color[counter]=4;
color[++counter]=0;
}
break;
}
textbackground(4); cprintf(" ");
textcolor(WHITE);
textbackground(color[0]); cprintf(" Ñîçäàòü ");
textbackground(color[1]); cprintf(" Îòêðûòü ");
textbackground(color[2]); cprintf(" Âûõîä ");
textbackground(4); cprintf(" ");
textbackground(1);
key=bioskey(0);
if (key == ENTER) {
switch(counter) {
case 0:
create();break;
case 1:
open();break;
case 2:
exit(10);
}
}
}
}
void interface(char *fn)
{
FILE *fp;
data st;
int num=1,key=0,counter=0,color[]={0,4,4,4,4,4};
clrscr();
while(1) {
window(1,1,80,3);
textbackground(1); textcolor(WHITE);
_setcursortype(_NOCURSOR); textcolor(10);
cprintf("::::::::::::::::::");
textcolor(15);
cprintf(" eBase v1.666 Copyright (C) Serj Sventitski ");
textcolor(10);
cprintf("::::::::::::::::::");
switch(key)
{
case LEFT: if (counter>0) {
color[counter]=4;
color[--counter]=0;
}
break;
case RIGHT: if (counter<5) {
color[counter]=4;
color[++counter]=0;
}
break;
}
textbackground(4);cprintf(" ");
textcolor(WHITE);
textbackground(color[0]);cprintf(" Äîáàâèòü ");
textbackground(color[1]);cprintf(" Óäàëèòü ");
textbackground(color[2]);cprintf(" Ðåäàêòèðîâàòü ");
textbackground(color[3]);cprintf(" Ïîèñê ");
textbackground(color[4]);cprintf(" Ñîðòèðîâêà ");
textbackground(color[5]);cprintf(" Íàçàä ");
textbackground(4);cprintf(" ");
textbackground(1);
view(fn,num);
key=bioskey(0);
switch(key)
{
case UP: num--;if (num==0)
num++;
view(fn,num);
break;
case DOWN: num++;if (num+16>=get_number(fn))
num--;
view(fn,num);
break;
}
if (key==283)
return;
if (key == ENTER)
{
switch(counter) {
case 0: add(fn); clrscr(); break;
case 1: del(fn); break;
case 2: edit(fn); clrscr(); break;
case 3: find(fn); break;
case 4: sort(fn); break;
case 5: return;
}
}
}
}
void add(char *fn)
{
FILE *fp;
data st;
int pr;
while (1) {
st.num=find_max_num(fn)+1;
clrscr();
_setcursortype(_SOLIDCURSOR);
gotoxy(20,6); cout<<"Ôàìèëèÿ : "; cin>>st.lastName;
gotoxy(20,8); cout<<"Èìÿ : "; cin>>st.firstName;
gotoxy(20,10); cout<<"Îò÷åñòâî : "; cin>>st.midName;
gotoxy(20,12); cout<<"¹ ãðóïïû : "; cin>>st.groupNumber;
gotoxy(20,14); cout<<"Ñðåäíèé áàëë ñòóäåíòà : ";
fflush(stdin);scanf("%f",&st.mark);
if (!check(fn, st)) {
if ((fp = fopen(fn,"ab+")) == NULL) {
printf("File could not be opened.\n");
return;
}
fwrite(&st, sizeof(data),1,fp);
fclose(fp);
return;
}
else {
gotoxy(20,18);
cout<<"Òàêàÿ çàïèñü óæå ñóùåñòâóåò";
getch();
}
}
}
void del(char *fn)
{
FILE *fp,*temp;
data st;
int pr=1;
int number;
gotoxy(4,25);
textcolor(11);
cprintf("Ââåäèòå ¹ çàïèñè äëÿ óäàëåíèÿ : ");
textcolor(YELLOW);
gotoxy(36,25);
int key = 0;
cscanf("%d",&number);
textcolor(WHITE);
while(kbhit())
if (!(key=getch()))
key << 8;
if( key == '\r' ) {
if ((fp=fopen(fn,"rb")) == NULL) {
cout<<"error.file does not exist.";
return;
}
if ((temp=fopen("temp.$$$","wb")) == NULL) {
cout<<"error. temp file couldn't be create";
return;
}
while (fread(&st,sizeof(data),1,fp)) {
if (feof(fp))
break;
if (st.num != number)
fwrite(&st,sizeof(data),1,temp);
else
pr=0;
}
fclose(fp);
fclose(temp);
if (remove(fn) == -1) {
perror("remove");
return;
}
if (rename("temp.$$$",fn) == -1) {
perror("rename");
return;
}
if (pr) {
textcolor(11);
gotoxy(4,25);
cprintf("\r Îøèáêà. Íåò çàïèñè ñ òàêèì íîìåðîì ");
getch();
textcolor(WHITE);
}
}
clrscr();
}
void edit(char *fn)
{
FILE *fp;
data st;
int pr=1;
int number,size=sizeof(data);
fpos_t filepos;
gotoxy(4,25);
textcolor(11);
cprintf("Ââåäèòå ¹ çàïèñè äëÿ ðåäàêòèðîâàíèÿ : ");
textcolor(YELLOW);
gotoxy(44,25);
int key = 0;
cscanf("%d",&number);
textcolor(WHITE);
while( kbhit())
if( !(key = getch()))
key << 8;
if( key == '\r' )
{
if ((fp = fopen(fn,"rb+")) == NULL)
{
printf("File could not be opened.\n");
return;
}
while(fread(&st,size,1,fp))
{
if (feof(fp))
break;
if (st.num == number)
{
fseek(fp,-1*size,1);
fgetpos(fp,&filepos);
pr=1;
break;
}
else
pr=0;
}
if (pr)
{
while (1)
{
clrscr();
_setcursortype(_SOLIDCURSOR);
gotoxy(20,6);cout<<"Ôàìèëèÿ : ";
cin>>st.lastName;
gotoxy(20,8);cout<<"Èìÿ : ";
cin>>st.firstName;
gotoxy(20,10);cout<<"Îò÷åñòâî : ";
cin>>st.midName;
gotoxy(20,12);cout<<"¹ ãðóïïû : ";
cin>>st.groupNumber;
gotoxy(20,14);cout<<"Ñðåäíèé áàëë ñòóäåíòà : ";
scanf("%f",&st.mark);
if (!check(fn, st))
{
fsetpos(fp,&filepos);
fwrite(&st, sizeof(data),1,fp);
break;
}
else {
gotoxy(20,18);
cout<<"Òàêàÿ çàïèñü óæå ñóùåñòâóåò";
getch();
}
}
}
else {
textcolor(11);
gotoxy(4,25);
cprintf("\r Îøèáêà... Íåò çàïèñè ñ òàêèì íîìåðîì ");
getch();
textcolor(WHITE);
}
fclose(fp);
}
}
void view(char *fn,int n)
{
void ramka();
FILE *fp;
data st;
char c;
int counter=0;
if ((fp = fopen(fn,"rb")) == NULL) {
printf("File could not be opened.\n");
return;
}
ramka();
window(1,6,80,23);
fseek(fp,(n-1)*sizeof(data),SEEK_SET);
while (counter != 18)
{
fread(&st,sizeof(data),1,fp);
if (feof(fp))
break;
else
{
printf(" %4d %-16s %-12s %-17s %8s "
"%7.2f\n",st.num,st.lastName,st.firstName,
st.midName,st.groupNumber,st.mark);
counter++;
}
}
window(1,24,80,25);
cprintf("-----------------------------------"
"---------------------------------------------");
cprintf(" %c - ââåðõ, %c - âíèç , %c - âëåâî,"
" %c - âïðàâî, ESC - îòìåíà ",0x018,0x019,0x01B,0x01A);
textcolor(10); textbackground(1); cprintf("%14s",fn);
window(1,1,80,25); textcolor(15);
fclose(fp);
}
void sort(char *fn)
{
FILE *fp;
data s1,s2;
int num=1,size=sizeof(data),counter=0,key=0;
int oldfs,newfs,color[]={0,4,4,4,4};
while(1)
{
_setcursortype(_NOCURSOR); textcolor(10);
cprintf("::::::::::::::::::::::::: Ì å í þ ñ î ð ò è ð î â ê è "
":::::::::::::::::::::::::");
switch(key)
{
case LEFT: if (counter>0) {
color[counter]=4;
color[--counter]=0;
}
break;
case RIGHT: if (counter<4) {
color[counter]=4;
color[++counter]=0;
}
break;
}
textbackground(4); cprintf(" "); textcolor(WHITE);
textbackground(color[0]);cprintf(" ïî ¹ çàïèñè ");
textbackground(color[1]);cprintf(" ïî Ô.È.Î ");
textbackground(color[2]);cprintf(" ïî ¹ ãðóïïû ");
textbackground(color[3]);cprintf(" ïî ñð.áàëó ");
textbackground(color[4]);cprintf(" Íàçàä ");
textbackground(4);cprintf(" "); textbackground(1);
view(fn,num);
key=bioskey(0);
switch(key)
{
case UP: num--;if (num==0)
num=1;
view(fn,num); break;
case DOWN: num++;if (num+16>=get_number(fn))
num--;
view(fn,num); break;
}
if (key==283)
return;
if (key == ENTER)
{
if ((fp=fopen(fn,"rb+")) == NULL)
{
cout<<"error.file does not exist.";
return;
}
switch(counter) {
case 1: /*-----------ïî Ô.È.Î--------------------*/
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.lastName,s2.lastName) > 0) {
fseek(fp,-2*size,1);
fwrite(&s2,size,1,fp);
fwrite(&s1,size,1,fp);
newfs=1;
}
if (strcmp(s1.lastName,s2.lastName) == 0)
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;
}