10. void findStudentByName();
int searchGmail(char[]);
/************************ BOOK *****************/
void addBook();
void printAllBooksList();
int findBookById(int);
void findBookById1();
void findBookByISBN();
void findBookByName();
/********************** Enter Studente Details
******************************/
void enterStudentDetails()
{
int roll,ch,res;
char name[50],email[50];
int flag=0,flag1=0;
11. FILE *fp;
clrscr();
fp = fopen("student.txt","a");
printf("n ENTER ROLL NUMBER : ");
scanf("%d",&roll);
flag=findStudentByRoleNumber(roll);
if(flag!=1)
{
printf("ENTER NAME :n");
scanf("%s",&name);
printf("ENTER EMAIL:n");
scanf("%s",&email);
flag1=searchGmail(email);
if(flag1!=1)
{
12. fprintf(fp,"%d %s %sn",roll,name,email);
}
else
{
printf("n email already registered, take a new
Emailn");
}
}
else
{
printf("This Student Number already registered .If u
want add new student take another New RoleNumber :n");
}
fclose(fp) ;
}
/******************* Search gmail
************************/
13. int searchGmail(char semail[50])
{
int i,ch,roll;
char email[50],name[50];
FILE *fm;
fm = fopen("student.txt","r");
i=0;
while(! feof(fm))
{
fscanf(fm,"%d%s%sn",&roll,&name,&email);
if(strcmp(email,semail)==0)
{
i=1;
printf("nROLLNO. NAME GMAILn ");
printf(" %d %s %s",roll,name,email);
break;
}
14. }
fclose(fm);
return i;
}
/********************Print All Students
Details**************/
void printAllstudentsDetails()
{
int rollno[100],x[100],i;
char name[100][50],email[100][50];
FILE *fp;
clrscr();
fp = fopen("student.txt","r");
i=0;
printf("ROLLNO NAME EMAILn");
while(!feof(fp))
15. {
fscanf(fp,"%d %s %sn",&rollno[i],&name[i],&email[i]);
printf(" %d %s
%sn",rollno[i],name[i],email[i]);
i=i+1;
}
fclose(fp);
printf("nnnPRESS ANY KEY");
getch();
}
/************************* Print Student Details using
RoleNumber ***************************/
int findStudentByRoleNumber(int roll1)
{
int i,ch,roll,mark,sroll;
char name[50],email[50];
17. {
printf("n%d",roll1);
printf(" Rolenumber does not exit in the recordn");
}
fclose(fm);
return i;
}
/************************* To find Student information
using student name***************************/
void findStudentByName()
{
int i=0,roll,ch,mark,roll1;
char name[50],email[50],sname[50];
FILE *fm;
ch=1;
18. while(ch)
{
fm = fopen("student.txt","r");
printf(" n ENTER STUDENT NAME ");
scanf("%s",&sname);
while(! feof(fm))
{
fscanf(fm,"%d%s%sn",&roll,&name,&email);
if(strcmp(sname,name)==0)
{
i=1;
printf("nROLLNO. NAME GMAILn ");
printf(" %d %s %s",roll,name,email);
break;
}
}
24. /* ---------------------- find book by ID --------------------*/
void findBookById1()
{
int i,ch,bid,isbn,quantity,sbid;
char bname[50],author[50];
FILE *fm;
ch=1;
while(ch)
{
fm = fopen("book.txt","r");
printf(" n ENTER BOOK ID :");
scanf("%d",&sbid);
i=0;
while(! feof(fm))
{
25. //printf("------- find book by ID while 1-----n");
fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity,
&isbn);
if(sbid==bid)
{
printf("n bookID BookName Author quantity
ISBNnumbern ");
printf(" %d %s %s %d
%dn",bid,bname,author,quantity,isbn);
break;
}
else
i=i+1;
}
printf("nnpress 1 to see another book info, 0 to return to
main menun");
scanf("%d",&ch);
fclose(fm);
}
28. while(ch)
{
fm = fopen("book.txt","r");
printf(" n ENTER BOOK ISBN :");
scanf("%d",&sisbn);
i=0;
while(! feof(fm))
{
fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity,
&isbn);
if(isbn==sisbn)
{
printf("n bookID BookName Author quantity
ISBNnumbern ");
printf(" %d %s %s %d
%dn",bid,bname,author,quantity,isbn);
break;
}
else
29. i=i+1;
}
printf("nnpress 1 to see another book info, 0 to return to
main menu :");
scanf("%d",&ch);
fclose(fm);
}
}
/*--------------------------- find Book By its name-----------------
*/
void findBookByName()
{
int ch,bid,isbn,quantity;
char bname[50],author[50],sbname[50];
FILE *fm;
ch=1;
while(ch)
30. {
fm = fopen("book.txt","r");
printf(" n ENTER BOOK NAME :");
scanf("%s",&sbname);
while(!feof(fm))
{
fscanf(fm,"%d %s %s %d
%sn",&bid,&bname,&author,&quantity,&isbn);
if(strcmp(sbname,bname) == 0)
{
printf("n bookID BookName Author quantity
ISBNnumbern ");
printf(" %d %s %s %d
%dn",bid,bname,author,quantity,isbn);
break;
}
}
printf("nnpress 1 to see another Book info, 0 to return to
31. main menu :");
scanf("%d",&ch);
fclose(fm);
}
}
/**************** FUNC.
ENDS************************/
void main()
{
int i,rollno[100],x[100],n,j,roll,c,roll1,sroll,res,sbid;
char ch,name[100][10],email;
while(c!=10)
{
printf("GIVE CHOICE--n");
printf(" 1 TO ENTER STUDENT INFORMATIONn");
printf(" 2 TO SEE ALL STUDENTS INFORMATIONn");
32. printf(" 3 TO PRINT STUDENT INFOORMATION USING
ROLL NOn");
printf(" 4 TO PRINT STUDENT INFO. USING HIS
NAMEn");
printf(" 5 TO ENTER New Book INFO.n");
printf(" 6 TO PRINT ALL BOOKS INFO.n");
printf(" 7 TO Find BOOK INFO by BookById.n");
printf(" 8 TO Find Book Info By ISBN number.n");
printf(" 9 TO Find Book Info By its Name.n");
printf(" 10 QUIT nn--");
scanf("%d",&c);
clrscr();
switch(c)
{
case 1:
enterStudentDetails();
break;
case 2:
33. printAllstudentsDetails();
break;
case 3:
do
{
res=0;
printf("Enter Student Roll Number-----> ");
scanf("%d",&roll1);
res=findStudentByRoleNumber(roll1);
printf("nDo u want search again if yes
PRESS 1 else PRESS 0 :");
scanf("%d",&i);
}while(i!=0);
if(res==0)
{
printf("nThis RoleNumberis not yet
registered");
36. }
S14_CSCI 6610
Assignment 3
Enhance your library system with the following set of
requirements:
1) Use dynamic memory allocation for the book array and
student array. This will help your program to expand without
any limitation on fixed number of books or students.
2) Use binary files to store the data instead of using text files.
You’ll be using binary modes instead of a text mode.
3) Data has to be encrypted before it gets stored in file. Use 8
bits key encryption using “exclusive or” operator (^) as we
discussed in the class. Data has to be decrypted before loading
the arrays again.