Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа3
.CPP//Inclusion of library functions of C++
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
//definition of structure link used to form my book list
typedef struct link
{
char books[10];
char firstname[13];
char surname[13];
char date_pub[9];
int booknum;
int hall;
int num_books;
struct link *backward;
struct link *forward;
}DATA ; //link defined to DATA
//definition of the global variables used.
DATA *info,*first,*fur,*crec;
int i,j,n,num,srch;
char halls[4][11]={"Science","Literature","History","Law"};
DATA *copyelsearch(DATA *scol);//Copy individual fields(subfunction of search_for)
void main(void)
{
first=NULL;
//description of the functions used
void putd_text(int x,int y,char *word);//used to put strings to a particular position
void intowin (int x,int y,int d,int w,char *title,char *str,int len);//collects strings to window
int testnumber(int num,int lowl, int upl);//input number of lib. no. & hall no. & hall no. &rejects letters and numbers <=0
DATA *inp1(); //input of data to book's list
void outmain(DATA *rec);//outputs book's list ,main interface with user
int outsm(DATA *rec);//outputs data book's list and helps to simplify processing
DATA *inpadd(DATA *col);//create or adds new elements to data book's list
DATA *del(DATA *ncol);//deletes a specified element from data book's list
DATA *search_for(DATA *scol);//searches for element/s in data book's list
void savenew(DATA*tosav);//saves data book's list into a named file
DATA *loadfile();//opens file to read saved data book's list
char ch,mh;
clrscr();
_setcursortype(_NOCURSOR);
textbackground(BLACK);
window(10,5,70,20); //welcome window
textbackground(BLUE);
textcolor(WHITE);
gotoxy(1,1);
cprintf("ЙНННННННННННННННННННННННННННННННННННННННННННННННННННННННН»"); gotoxy(1,2);
cprintf("¶ St.Petersburg state Electrotechnical University ¶"); gotoxy(1,3);
cprintf("¶ Department of Computer Technology ¶"); gotoxy(1,4);
cprintf("¶ COURSEWORK ¶"); gotoxy(1,5);
cprintf("¶ ¶"); gotoxy(1,6);
cprintf("¶ written by: ¶"); gotoxy(1,7);
cprintf("¶ ¶"); gotoxy(1,8);
cprintf("З 1 ¶"); gotoxy(1,9);
cprintf("ИННННННННННННННННННННННННННННННННННННННННННННННННННННННННј"); gotoxy(1,10);
cprintf(" ..... PLEASE PRESS ANY KEY ..... ");
fflush(stdin);
getch();
clrscr();
window(1,1,80,25);
textbackground(BLACK);
clrscr();
//MAIN MENU
int l=1;
do
{
clrscr();
gotoxy(10,6);
printf("MAIN MENU");gotoxy(10,7);
printf("PLEASE MAKE A CHOICE");gotoxy(10,10);
printf("1. CREATE LIST");gotoxy(10,11);
printf("2. ADD NEW ELEMENT(S)");gotoxy(10,12);
printf("3. DELETE A SPECIFIC ELEMENT");gotoxy(10,13);
printf("4. SAVE IN FILE");gotoxy(10,14);
printf("5. OPEN FILE");gotoxy(10,15);
printf("6. SEARCH");gotoxy(10,16);
printf("7. EXIT");
switch(getch())
{
case '1':
{
clrscr();
int dl=1,p=0;
if(first)
fflush(stdin);
if(dl==1)
{
printf("\n Give Number of books to be considered...");
printf("\n Must be a Number greater than 0 ");
printf("\n NO:= ");
fflush(stdin);
if((scanf("%d",&n))&&n>0)
p=0;
else
if((n<=0)||(!scanf("%d",&n)))
{
do
{
printf("\n ERROR OF INPUT !!!!! \n PLEASE TRY AGAIN");
printf("\n\n Must be a NUMBER greater than 0 ");
printf("\n NO:= ");
fflush(stdin);
if((scanf("%d",&n))&&n>0)
p=0;
else
if((n<=0)||(!scanf("%d",&n)))
p=1;
} while(p==1);
}
fflush(stdin);
crec=inp1();
outmain(crec);
fflush(stdin);
getch();
clrscr();
}
break;
}
case '2':
{
clrscr();
crec=inpadd(crec);
outmain(crec);
getch();
break;
}
case '3':
{
clrscr();
crec=del(crec);
if(crec==NULL)
{
printf("\nYou have just deleted the final element in your list, but you");
printf("\n can still create a new list or open one from existing files");
getch();
clrscr();
}
else
{
outmain(crec);
}
getch();
break;
}
case '4':
{
clrscr();
savenew(crec);
getch();
break;
}
case '5':
{
clrscr();
crec=loadfile();
getch();
clrscr();
outmain(crec);
getch();
break;
}
case '6':
{
clrscr();
DATA *first11,*crec11;
first11=first;
crec11=crec;
crec=search_for(crec);
if(crec)
{
outmain(crec);
printf("\nTHIS IS YOUR SEARCH \n");
printf("\nPRESS ANY KEY TO CONTINUE \n");
getch();
clrscr();
}
first=first11;
crec=crec11;
getch();
break;
}
case '7':
{
clrscr();
gotoxy(5,11);
cprintf("ЙНННННННННННННННННННННННННННННННННННННННННННННННННННННННН»"); gotoxy(5,12);
cprintf("¶ YOU WILL LOSE ALL UNSAVED INFO ¶"); gotoxy(5,13);
cprintf("¶ CONFIRM EXIT ¶"); gotoxy(5,14);
cprintf("¶ ¶"); gotoxy(5,15);
cprintf("¶ (Y)-> YES (N)-> CANCEL ¶"); gotoxy(5,16);
cprintf("ИННННННННННННННННННННННННННННННННННННННННННННННННННННННННј"); gotoxy(5,20);
cprintf(" ..... PLEASE ENTER YOUR CHOICE ..... ");
fflush(stdin);
l=getch();
break;
}
default:
{
printf("\nPlease input a number from 1 to 4\n");
printf("Press any key to continue");
getch();
break;
}
}
}while(l!='y'&& l!='Y');
free(first);
//getch();
}
//function which verifies integer value of lib.no. & hall no. & book no.
int testnumber(int num,int lowl,int upl)
{
int p=0;
if(( scanf("%d",&num))&&num>lowl&&num<upl)
p=0;
else
if(num<=lowl||num>=upl||(!scanf("%d",&num)))//rejects non integers 0 and -ve numbers
{
do
{
printf("\n ERROR OF INPUT !!!!! PLEASE TRY AGAIN");
printf("\n Number must be btw %d and %d n:= ",lowl,upl);
fflush(stdin);
if(( scanf("%d",&num))&&num>lowl&&num<upl)
p=0;
else
if(num<=lowl||num>=upl||(!scanf("%d",&num)))
p=1;
} while(p==1);
}
return(num);
}
//function which creates operating list for books
DATA *inp1()
{
first=fur=info=NULL; //removes previous members of list
for(i=0;i<n;i++)
{
if(first==NULL)//creates head element of list
{
info=(DATA*)malloc(sizeof(DATA));
printf("\n Give title of no %d Book: ",i+1);
scanf("%s",info->books);
fflush(stdin);
printf("\n Give name of author: ");
scanf("%s",info->firstname);
fflush(stdin);
printf("\n Give surname of author: ");
scanf("%s",info->surname);
fflush(stdin);
printf("\n Date when book was published: ");
scanf("%s",info->date_pub);
fflush(stdin);
printf("\n Give book's identity number: ");
info->booknum=testnumber(num,0,999);
fflush(stdin);
printf("\n 1-Science , 2-Literature , 3-History , 4-Law");
printf("\n Give hall number to which the book belongs to: ");
info->hall=testnumber(num,0,5)-1;
fflush(stdin);
printf("\n Give number of copies of particular book: ");
info->num_books=testnumber(num,0,9999);
fflush(stdin);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;//creates subsequent elements
info=(DATA*)malloc(sizeof(DATA));
printf("\n Give title of no %d Book: ",i+1);
scanf("%s",info->books);
fflush(stdin);
printf("\n Give name of author: ");
scanf("%s",info->firstname);
fflush(stdin);
printf("\n Give surname of author: ");
scanf("%s",info->surname);
fflush(stdin);
printf("\n Date when book was published: ");
scanf("%s",info->date_pub);
fflush(stdin);
printf("\n Give book's identity number: ");
info->booknum=testnumber(num,0,999);
fflush(stdin);
printf("\n 1-Science , 2-Literature , 3-History , 4-Law");
printf("\n Give hall number to which the book belongs to: ");
info->hall=testnumber(num,0,5)-1;
fflush(stdin);
printf("\n Give number of copies of particular book: ");
info->num_books=testnumber(num,0,9999);
fflush(stdin);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
info=first;
return(info);
}
//function for main output of programme for books
void outmain(DATA *rec)
{
clrscr();
gotoxy(15,20);
printf(" ESC | ANY OTHER KEY ");
gotoxy(15,21);
printf(" TO EXIT | TO RETURN TO MAIN MENU");
n=0;
if(!rec)
n=10;
else
{
do
{
n++;
rec=rec->forward;
} while(rec!=NULL);
rec=first;
n=n+9;
}
gotoxy(1,2);
printf("BOOK NAME SURNAME DATE BOOK # HALL # No. books");
if(rec)
{
i=3;
do
{
gotoxy(1,i);
printf("%-11s",rec->books);
printf("%-12s",rec->firstname);
printf("%-11s",rec->surname);
printf("%-10s",rec->date_pub);
printf("%-7d",rec->booknum);
printf("%-12s",halls[rec->hall]);
printf("%-9d",rec->num_books);
rec=rec->forward;
i++;
} while(rec!=NULL);
rec=first;
}
else
{
gotoxy(15,1);
printf("EMPTY LIST PLEASE INPUT DATA FIRST!!!");
}
}
//frequently used function for output of selected strings
void putd_text(int x,int y,char *word)
{
gotoxy(x,y);
puts(word);
}
//function which outputs data for books into functions that process the data
int outsm(DATA *rec)
{
j=1;
if(!rec)
printf("\n NO ELEMENT IN YOUR LIST PLEASE .....\n");
else
do
{
printf("\n No %d book:",j);
printf(" %-12s",rec->books);
printf(" %-12s",rec->firstname);
printf(" %-12s",rec->surname);
printf(" %5s",rec->date_pub);
printf(" %-4d",rec->booknum);
printf(" %11s",halls[rec->hall]);
printf(" %-5d",rec->num_books);
j++;
rec=rec->forward;
} while(rec!=NULL);
rec=first;
return (j);
}
//function which adds new elements to data book's list after the first elemant
DATA *inpadd(DATA *ncol)
{
int m,p=0;
if(ncol==NULL)
{
printf("\n List is EMPTY you'll be creating one by adding new elements\n ");
printf("\n Give number of books to be considered...");
printf("\n Must be a number greater than 0 ");
printf("\n NO:= ");
fflush(stdin);
if((scanf("%d",&n))&&n>0)
p=0;
else
if((n<=0)||(!scanf("%d",&n)))
{
do
{
printf("\n ERROR OF INPUT !!!!! PLEASE TRY AGAIN");
printf("\n Must be a NUMBER greater than 0 ");
printf("\n NO:= ");
fflush(stdin);
if((scanf("%d",&n))&&n>0)
p=0;
else
if((n<=0)||(!scanf("%d",&n)))
p=1;
} while(p==1);
}
fflush(stdin);
ncol=inp1();
}
else
{
clrscr();
p=0;
printf("\n Here is the list you have chosen to add to:\n ");
outsm(ncol);
fflush(stdin);
printf("\n Give number of new books to be added ....");
printf("\n Must be a NUMBER greater than 0 ");
printf("\n NO:= ");
fflush(stdin);
if((scanf("%d",&m))&&(m>0))
p=0;
else
if((m<=0)||(!scanf("%d",&m)))
{
do
{
printf("\n ERROR OF INPUT !!!!! PLEASE TRY AGAIN");
printf("\n Must be a NUMBER greater than 0 n:= ");
printf("\n NO:= ");
fflush(stdin);
if((scanf("%d",&m))&&(m>0))
p=0;
else
if((m<=0)||(!scanf("%d",&m)))
p=1;
} while(p==1);
}
fflush(stdin);
ncol=first;
for(i=0;i<m;i++)
{
info=(DATA*)malloc(sizeof(DATA));
printf("\n Give title of no %d Book: ",i+1);
scanf("%s",info->books);
fflush(stdin);
printf("\n Give name of author: ");
scanf("%s",info->firstname);
fflush(stdin);
printf("\n Give surname of author: ");
scanf("%s",info->surname);
fflush(stdin);
printf("\n Date when book was published: ");
scanf("%s",info->date_pub);
fflush(stdin);
printf("\n Give book's identity number: ");
info->booknum=testnumber(num,0,999);
fflush(stdin);
printf("\n 1-Science , 2-Literature , 3-History , 4-Law");
printf("\n Give hall number to which the book belongs to: ");
info->hall=testnumber(num,0,5)-1;
fflush(stdin);
printf("\n Give number of copies of particular book: ");
info->num_books=testnumber(num,0,9999);
fflush(stdin);
info->forward=ncol->forward;
ncol->forward->backward=info;
info->backward=ncol;
ncol->forward=info;
}
}
return(ncol);
}
//function which deletes a specified element from data book's list
DATA *del(DATA *ncol)
{
int x,y,p=0;
clrscr();
if(!ncol)
return(NULL);
else
{
ncol=first;
printf("\n Here is the list you want to delete from :\n ");
//function outsm gives user the opportunity to choose
//the number of the book he wants deleted
//however choice must be only from those on screen!!!
y=outsm(ncol);
printf("\n Please give the BOOK'S NUMBER you want deleted");
printf("\n must be a NUMBER from those listed above ");
printf("\n No:= ");
fflush(stdin);
if((scanf("%d",&x))&&(x>0)&&(x<=y-1))
p=0;
else
if((x<=0)||(x>y-1)||(!scanf("%d",&x)))
{
do
{
printf("\n ERROR OF INPUT !!!!! PLEASE TRY AGAIN");
printf("\n Must be a NUMBER from those listed above ");
printf("\n No:= ");
fflush(stdin);
if((scanf("%d",&x))&&(x>0)&&(x<=y-1))
p=0;
else
if((x<=0)||(x>y-1)||(!scanf("%d",&x)))
p=1;
} while(p==1);
}
fflush(stdin);
for(j=0;j<x-1;j++)
ncol=ncol->forward;
if(first==ncol)
first=ncol->forward;
ncol->backward->forward=ncol->forward;
ncol->forward->backward=ncol->backward;
free(ncol);
ncol=first;
return(ncol);
};
}
//function used to write strings into window
void intowin(int x,int y,int d,int w,char *title,char *str,int len)
{
clrscr();
void *destin;
int i;
char *inp;
int xtmp,ytmp;
inp=(char *)malloc(sizeof(char)*30);
destin=(void *)malloc(2*d*w);
xtmp=wherex();
ytmp=wherey();
gettext(x,y,x+d-1,y+w-1,destin);
textcolor(WHITE);
clrscr();
//-------------
//Draws border:
gotoxy(x,y);
printf("Ъ");
for(i=0;i<d-2;i++)
printf("Д");
printf("ї");
for(i=0;i<w-2;i++)
{
gotoxy(x+d-1,y+i+1);
printf("і");
}
gotoxy(x+d-1,y+w-1);
printf("Щ");
gotoxy(x+1,y+w-1);
for(i=0;i<d-2;i++)
printf("Д");
for(i=0;i<w-2;i++)
{
gotoxy(x,y+i+1);
printf("і");
}
gotoxy(x,y+w-1);
printf("А");
//-------------
//fixes title at topcenter of window
gotoxy(x+(d-strlen(title))/2,y);
printf("%s",title);
inp[0]=len+1;
strcpy(str,gets(inp));
puttext(x,y,x+d-1,y+w-1,destin);
free(destin);
free(inp);
gotoxy(xtmp,ytmp);
}
//function for saving selected data book's list to file
void savenew(DATA*tosav)
{
FILE *fp;
int cre=0;
char str[30];
intowin(10,10,40,3,"SAVE AS",str,30);
fflush(stdin);
if((fp=fopen(str,"rb"))==NULL)
cre=1;
else
{
window(1,1,80,25);
int an;
gotoxy(10,10);printf("FILE ALREADY EXISTS OVERWRITE IT");
gotoxy(10,12);printf("ENTER");
gotoxy(10,13);printf("CANCEL");
gotoxy(10,15);printf("Please enter your choice :");
scanf("%d",&an);
if(an==2)
an=0;
else
cre=1;
}
if(cre==1)
{
if((fp=fopen(str,"wb"))==NULL)
{
gotoxy(10,15);
textcolor(RED);
cprintf("SYSTEM ERROR:CAN'T OPEN FILE - %s",str);
textcolor(YELLOW);
char *erob="PRESS ANY KEY TO RETURN TO MENU";
putd_text(10,16,erob);
getch();
clrscr();
textbackground(BLACK);
textcolor(WHITE);
fflush(stdin);
}
else
{
n=0;
do
{
n++;
tosav=tosav->forward;
} while(tosav!=NULL);
fwrite(&n,sizeof(int),1,fp);
tosav=first;
for(i=0;i<n;i++)
{
fwrite(tosav,sizeof(DATA)-2*sizeof(struct link*),1,fp);
tosav=tosav->forward;
}
fclose(fp);
gotoxy(10,15);
textcolor(RED);
cprintf("FILE { %s } SAVED.",str);
gotoxy(10,16);
textcolor(YELLOW);
cprintf("PLEASE PRESS ANY KEY TWICE TO RETURN TO MENU");
getch();
clrscr();
textbackground(BLACK);
textcolor(WHITE);
}
}
}
//function which reads data book's list from file
DATA *loadfile()
{
FILE *fp;
char rstr[30];
clrscr();
//intowin(10,10,40,3,"GIVE FILE NAME",rstr,30);
gotoxy(5,11);
printf("ЙННННННННННННННННННННННННННННННН»"); gotoxy(5,12);
printf("¶ GIVE FILE NAME: ¶"); gotoxy(5,13);
printf("¶ ¶"); gotoxy(5,14);
printf("¶ ¶"); gotoxy(5,15);
printf("ИНННННННННННННННННННННННННННННННј"); gotoxy(5,17);
printf("... PLEASE ENTER YOUR CHOICE ... ");
//clrscr();
textcolor(YELLOW);
gotoxy(15,14);
cscanf("%s",&rstr);
textbackground(BLACK);
textcolor(WHITE);
clrscr();
fflush(stdin);
if((fp=fopen(rstr,"rb"))==NULL)
{
gotoxy(10,15);
textcolor(RED);
cprintf("SYSTEM ERROR:CAN'T OPEN FILE -{ %s }",rstr);
gotoxy(10,16);
textcolor(YELLOW);
cprintf("PLEASE PRESS ANY KEY TO CONTINUE");
getch();
clrscr();
textbackground(BLACK);
textcolor(WHITE);
return(NULL);
}
//creates memory space and new list from the read data
else
{
fread(&n,sizeof(int),1,fp);
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
fread(info,sizeof(DATA)-2*sizeof(struct link*),1,fp);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
fread(info,sizeof(DATA)-2*sizeof(struct link*),1,fp);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
info=first;
fclose(fp);
_setcursortype(_NORMALCURSOR);
clrscr();
return(info);//returns a new list from read data
}
}
//function which searches for book/s of given properties
DATA *search_for(DATA *scol)
{
DATA **searcher,*sfirst;
char sname[17],ssurname[17],sbooks[17],sdate_pub[19];
int x,y,shall,snum_books,sbooknum;
clrscr();
if(!scol)
{
return(NULL);
}
else
{
scol=first;
n=0;
do
{
n++;
scol=scol->forward;
} while(scol!=NULL);
scol=first;
clrscr();
//sub menu for search
int an;
gotoxy(10,10);
printf(" SEARCH BY");gotoxy(10,12);
printf("1. ALL");gotoxy(10,13);
printf("2. BOOKS");gotoxy(10,14);
printf("3. NAMES");gotoxy(10,15);
printf("4. DATE PUBLISHED");gotoxy(10,16);
printf("5. IDENTITY NUMBER");gotoxy(10,17);
printf("6. HALL");gotoxy(10,18);
printf("7. NUMBER OF BOOKS");gotoxy(10,19);
printf("8. CANCEL");gotoxy(10,21);
printf("Please input your choice :");
switch(getch())
{
case '1':
{
clrscr();
//search for book by all parameters
intowin(10,10,30,3,"BOOKS",sbooks,20);
fflush(stdin);
intowin(10,10,30,3,"GIVE NAME",sname,20);
fflush(stdin);
intowin(10,10,30,3,"GIVE SURNAME",ssurname,20);
fflush(stdin);
intowin(10,10,30,3,"DATE PUBLISHED",sdate_pub,20);
fflush(stdin);
clrscr();
gotoxy(15,5);
printf(" IDENTITY NUMBER=");
fflush(stdin);
sbooknum=testnumber(num,0,9999);
fflush(stdin);
clrscr();
gotoxy(15,5);
printf(" HALL NUMBER=");
fflush(stdin);
shall=testnumber(num,0,5)-1;
clrscr();
gotoxy(15,5);
printf(" NUMBER OF BOOKS=");
fflush(stdin);
sbooknum=testnumber(num,0,9999);
clrscr();
srch=0;
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if((strcmp(scol->books,sbooks)==0)&&(strcmp(scol->firstname,sname)==0)&&(strcmp(scol->surname,ssurname)==0)&&(strcmp(scol->date_pub,sdate_pub)==0)
&&(scol->booknum==sbooknum)&&(scol->hall==shall))
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
scol=scol->forward;
}
info=first;
scol=info;
break;
};
case '2':
{
clrscr();
//searching for those with a given title
intowin(10,10,30,3,"GIVE BOOK'S TITLE",sbooks,20);
fflush(stdin);
srch=0;
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if(strcmp(scol->books,sbooks)==0)
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
scol=scol->forward;
}
info=first;
scol=info;
break;
};
case '3':
{
clrscr();
//search by names
intowin(10,10,30,3,"GIVE NAME",sname,20);
fflush(stdin);
intowin(10,10,30,3,"GIVE SURNAME",ssurname,20);
fflush(stdin);
srch=0;
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if((strcmp(scol->firstname,sname)==0)&&(strcmp(scol->surname,ssurname)==0))
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
scol=scol->forward;
}
info=first;
scol=info;
break;
};
case '4':
{
clrscr();
//searching for those with the same date being published
intowin(10,10,30,3,"DATE PUBLISHED",sdate_pub,20);
fflush(stdin);
srch=0;
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if(strcmp(scol->date_pub,sdate_pub)==0)
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
scol=scol->forward;
}
info=first;
scol=info;
break;
};
case '5':
{
clrscr();
// search for those with same book's identity number
gotoxy(20,5);
printf(" PLEASE GIVE BOOK'S IDENTITY NUMBER ");
gotoxy(20,7);
printf(" BOOK'S IDENTITY NUMBER= ");
sbooknum=testnumber(num,0,9999);
fflush(stdin);
srch=0;
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if((scol->booknum)==sbooknum)
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
scol=scol->forward;
}
info=first;
scol=info;
break;
};
case '6':
{
clrscr();
// search with those with same hallnumber
gotoxy(17,6);
printf(" PLEASE GIVE THE HALL NUMBER TO WHICH BOOK BELONGS ");
gotoxy(15,5);
printf("{ [1]-Science , [2]-Literature , [3]-History , [4]-Law } ");
gotoxy(20,8);
printf(" HALL NUMBER= ");
shall=testnumber(num,0,5)-1;
fflush(stdin);
srch=0;
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if((scol->hall)==shall)
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
scol=scol->forward;
}
info=first;
scol=info;
break;
};
case '7':
{clrscr(); // search with same copies of books
gotoxy(20,5);
printf(" GIVE NUMBER OF COPIES OF PARTICULAR BOOK ");
gotoxy(20,7);
printf(" NUMBER OF COPIES= ");
snum_books=testnumber(num,0,9999);
fflush(stdin);
srch=0;
first=fur=info=NULL;
for(i=0;i<n;i++)
{
if((scol->num_books)==snum_books)
{
if(first==NULL)
{
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=NULL;
info->forward=NULL;
first=info;
}
else
{
fur=info;
info=(DATA*)malloc(sizeof(DATA));
info=copyelsearch(scol);
info->backward=fur;
info->forward=NULL;
fur->forward=info;
}
}
scol=scol->forward;
}
info=first;
scol=info;
break;
};
case '8':
{
//cancels search
break;
};
default:
{
// default case cancels search
break;
};
}
textcolor(WHITE);
return(scol);
}
}
//function just to copy elements
DATA *copyelsearch(DATA *scol)
{
strcpy(info->books,scol->books);
strcpy(info->firstname,scol->firstname);
strcpy(info->surname,scol->surname);
strcpy(info->date_pub,scol->date_pub);
info->booknum=scol->booknum;
info->hall=scol->hall;
info->num_books=scol->num_books;
return(info);
}
Соседние файлы в предмете Программирование