STRUCT Library System

#include<iostream>
#include<string>
#include<iomanip>
#include<stdio.h>
#include<conio.h>

using namespace std;

void viewOneRecord();
void borrow();
void addStudent();
void viewAllRecords();
void viewOneRecord();
void display();
void deleteMechanism();
void editRecord();
void viewOneMechanism();
void deleteRecord();

void pass();
void menuDisplay();
void menuDisplay2();
void menuDisplay3();

void addbook();
void viewOnebook();
void viewAllbook();
void deletebook();
void editbook();
void deleteMecha();
void viewOneMecha();
void displaybook();

struct studinfo
{
int idno;
char name[25];
char mname[25];
char lname[25];
char course[25];
char address[25];

int booknum;
char book[25];
char description[25];
char author[25];
int publish;
int pages;

};


FILE *studfile;
FILE *tempfile;
FILE *bookfile;

int id;
bool found;

main()
{ pass();
int choice=0;

while(choice!=6)
{
system("cls");
menuDisplay();
cout<<"\nType the number of your choice: ";
cin>>choice;
switch(choice)
{
case 1:menuDisplay2();getch();break;
case 2:menuDisplay3();getch();break;
case 3:exit(1);getch();break;
case 4:exit(1);getch();;break;
case 5:exit(1);break;}
}

}

void menuDisplay()
{

system("cls");
cout<<"\n\n\t\t\t\tTHE LIBRARY SYSTEM";
cout<<"\n\n\t\t\t\tRick Stephen Gingo";
cout<<"\n\n\t\t\t\tMark Anthony Hernandez";
cout<<"\n\n\n- - - - - - - - - - - - - - -";
cout<<"\n1. Student Record";
cout<<"\n2. Book information";
cout<<"\n3. Borrow book";
cout<<"\n4. Return book";
cout<<"\n5. Exit";
cout<<"\n- - - - - - - - - - - - - - -";

}

void menuDisplay2()
{
int c1;

system("cls");
cout<<"\n- - - - - - - - - - - - - - -";
cout<<"\n1. ADD Student Record";
cout<<"\n2. VIEW ONE Student Record";
cout<<"\n3. VIEW ALL Records";
cout<<"\n4. DELETE Student Record";
cout<<"\n5 EDIT Student Record";
cout<<"\n6. EXIT";
cout<<"\n- - - - - - - - - - - - - - -";
cout<<"\nEnter your choice:";
cin>>c1;

if(c1==1)
{
system("cls");
addStudent();

}
else if(c1==2)
{
system("cls");
viewOneRecord();

}
else if(c1==3)
{
system("cls");
viewAllRecords();

}
else if(c1==4)
{
pass();
system("cls");
deleteRecord();

}
else if(c1==5)
{
pass();
system("cls");
editRecord();
}
else if(c1==6)
{
exit(1);

}
}

void menuDisplay3()
{
int c2;
system("cls");
cout<<"\n- - - - - - - - - - - - - - -";
cout<<"\n1. ADD Book Record";
cout<<"\n2. VIEW ONE Book Record";
cout<<"\n3. VIEW ALL Book Records";
cout<<"\n4. DELETE Book Record";
cout<<"\n5. EDIT Book Record";
cout<<"\n6. EXIT";
cout<<"\n- - - - - - - - - - - - - - -";
cout<<"\nEnter your choice:";
cin>>c2;

if(c2==1)
{
system("cls");
addbook();

}
else if(c2==2)
{
system("cls");
viewOnebook();

}
else if(c2==3)
{
system("cls");
viewAllbook();

}
else if(c2==4)
{
pass();
system("cls");
deletebook();

}
else if(c2==5)
{
pass();
system("cls");
editbook();
}
else if(c2==6)
{
exit(1);

}
}

void addStudent()
{
int idno,num;
found=false;
char name[25],mname[25],lname[25], course[25], address[25];
studinfo students;
cout<<"\nType the ID number:";
cin>>num;
studfile=fopen("students.txt","a+");
rewind(studfile);
while(!feof(studfile)&& found==false)
{
fscanf(studfile,"%d%s%s%s%s%s",&idno,&name,&mname,&lname,&course,&address);
if(idno==num)
{
cout<<"Student is Existing!..";
found=true;
}
}
if(found==false)
{
cout<<"\nType student's name: ";
cin>>name;
cout<<"\nType student's middle name: ";
cin>>mname;
cout<<"\nType student's last name: ";
cin>>lname;
cout<<"\nType student's course: ";
cin>>course;
cout<<"\nType student's address: ";
cin>>address;
fprintf (studfile,"\n%-5d %-20s %-20s %-20s %-20s %-20s",num,name,mname,lname,course,address);
cout<<"\nThe new record was successfully saved!";
}
getch();
fclose(studfile);
}

void viewAllRecords()
{

int idno;
char name[25],mname[25],lname[25], course[25], address[25];
studfile=fopen("students.txt","r");
rewind(studfile);
if(!feof(studfile))
{
system("cls");
cout<<"\nLIST OF STUDENTS";
display();
while(!feof(studfile))
{
if(fscanf(studfile,"%d%s%s%s%s%s",&idno,&name,&mname,&lname,&course,&address)>0)
cout<<setw(15)<<idno<<setw(15)<<name<<setw(15)<<mname<<setw(15)<<lname<<setw(15)<<course<<setw(15)<<address<<"\n";

}
}
else cout<<"No record found in the file!";
fclose(studfile);
getch();
}

void viewOneRecord()
{
viewOneMechanism();
getch();
}

void deleteRecord()
{
char cont;
viewOneMechanism();
if (found==true)
{
cout<<"Are you sure you want to delete this record(y/n)?: ";
cin>>cont;
if(cont=='y'||cont=='Y')
{
deleteMechanism();
cout<<"\n\nThe record was successfully deleted!";
}
else
{
cout<<"\nThe record was not deleted!";
}
getch();
}
}

void editRecord()
{
char cont;
char name[25],mname[25],lname[25], course[25], address[25];
viewOneMechanism();
if(found==true)
{
cout<<"\nAre you sure you want to update this record(y/n)?:";
cin>>cont;
if(cont=='y'||cont=='Y')
{
deleteMechanism();
studfile=fopen("students.txt","a+");
cout<<"\nType student's name: ";
cin>>name;
cout<<"\nType student's middle name: ";
cin>>mname;
cout<<"\nType student's last name: ";
cin>>lname;
cout<<"\nType student's course: ";
cin>>course;
cout<<"\nType student's address: ";
cin>>address;
fprintf (studfile, "\n%-5d %-20s %-20s %-20s %-20s %-20s",id,name,mname,lname,course,address);
fclose(studfile);
cout<<"\nThe record was successfully updated!";
}
else

{
cout<<"\nThe record was not updated!";
}
getch();
}
}


void deleteMechanism()
{
int idno;
char name[25],mname[25],lname[25], course[25], address[25];
studfile=fopen("students.txt","r");
tempfile=fopen("temporary.txt","w+");
rewind(studfile);
while(!feof(studfile))
{
if(fscanf(studfile,"%d%s%s%s%s%s",&idno,&name,&mname,&lname,&course,&address)>0)
{
if(idno!=id)
{
fprintf (tempfile, "\n%-5d %-20s %-20s %-20s %-20s %-20s",idno,name,mname,lname,course,address);
}
}
}
fclose(studfile);
fclose(tempfile);

studfile=fopen("students.txt","w+");
tempfile=fopen("temporary.txt","r");
rewind(tempfile);
while(!feof(tempfile))
{
if(fscanf(tempfile,"%d%s%s%s%s%s",&idno,&name,&mname,&lname,&course,&address)>0)
{
if(idno!=id)
{
fprintf (studfile, "\n%-5d %-20s %-20s %-20s %-20s %-20s",idno,name,mname,lname,course,address);
}
}
}
fclose(studfile);
fclose(tempfile);
}

Here's the continuation:


void viewOneMechanism()
{
int idno;
char name[25],mname[25],lname[25], course[25], address[25];
found=false;
cout<<"\n\nType ID Number of Student to be viewed:";
cin>>id;
studfile=fopen("students.txt","r");
rewind(studfile);
while(!feof(studfile)&&found==false)
{
if(fscanf(studfile,"%d%s%s%s%s%s",&idno,&name,&mname,&lname,&course,&address)>0)
{
if(idno==id)
{
display();
cout<<setw(15)<<idno<<setw(15)<<name<<setw(15)<<mname<<setw(15)<<lname<<setw(15)<<course<<setw(15)<<address<<"\n";
found=true;
}
}
}
if(found==false)
{
cout<<"\nStudent Record is not existing!";
}
fclose(studfile);
}

void display()
{
cout<<"\n"<<setw(15)<<left<<"ID Number"
<<setw(15)<<left<<"Name"
<<setw(15)<<left<<"Middle Name"
<<setw(15)<<left<<"Last Name"
<<setw(15)<<left<<"Course"
<<setw(13)<<left<<"Address"<<"\n";
}



void addbook()
{
int booknum,no;
found=false;
char b[25],d[25],a[25];
int p, pages;
studinfo students;
cout<<"\nType the Book number:";
cin>>no;
bookfile=fopen("book.txt","a+");
rewind(bookfile);
while(!feof(bookfile)&& found==false)
{
fscanf(bookfile,"%d%s%s%s%d%d",&booknum,&b,&d,&a,&p,&pages);
if(booknum==no)
{
cout<<"Book is Existing!..";
found=true;
}
}
if(found==false)
{
cout<<"\nType book's name:";
cin>>b;
cout<<"\nType book's description:";
cin>>d;
cout<<"\nType book's author:";
cin>>a;
cout<<"\nType the year published:";
cin>>p;
cout<<"\nType the number of pages:";
cin>>pages;
fprintf (bookfile, "\n%-5d %-20s %-20s %-20s %-5d %-5d",no,b,d,a,p,pages);
cout<<"\nThe new record was successfully saved!";
}
getch();
fclose(bookfile);
}

void viewAllbook()
{

int booknum;
char b[25],d[25],a[25];
int p, pages;
bookfile=fopen("book.txt","r");
rewind(bookfile);
if(!feof(bookfile))
{
system("cls");
cout<<"\nLIST OF BOOKS";
displaybook();
while(!feof(bookfile))
{
if(fscanf(bookfile,"%d%s%s%s%d%d",&booknum,&b,&d,&a,&p,&pages)>0)
cout<<setw(15)<<booknum<<setw(15)<<b<<setw(15)<<d<<setw(15)<<a<<setw(15)<<p<<setw(15)<<pages<<"\n";

}
}
else cout<<"No record found in the file!";
fclose(bookfile);
getch();
}

void viewOnebook()
{
viewOneMecha();
getch();
}

void deletebook()
{
char cnt;
viewOneMecha();
if (found==true)
{
cout<<"Are you sure you want to delete this record(y/n)?:";
cin>>cnt;
if(cnt=='y'||cnt=='Y')
{
deleteMecha();
cout<<"\n\nThe record was successfully deleted!";
}
else
{
cout<<"\nThe record was not deleted!";
}
getch();
}
}

void editbook()
{
char cnt;
char b[25],d[25],a[25];
int p, pages;
viewOneMecha();
if(found==true)
{
cout<<"\nAre you sure you want to update this record(y/n)?:";
cin>>cnt;
if(cnt=='y'||cnt=='Y')
{
deleteMecha();
bookfile=fopen("book.txt","a+");
cout<<"\nType book's name:";
cin>>b;
cout<<"\nType book's descrition:";
cin>>d;
cout<<"\nType book's author:";
cin>>a;
cout<<"\nType the year published:";
cin>>p;
cout<<"\nType number of pages:";
cin>>pages;
fprintf (bookfile, "\n%-5d %-20s %-20s %-20s %-5d %-5d",id,b,d,a,p,pages);
fclose(bookfile);
cout<<"\nThe record was successfully updated!";
}
else

{
cout<<"\nThe record was not updated!";
}
getch();
}
}


void deleteMecha()
{
int booknum;
char b[25],d[25],a[25];
int p, pages;
bookfile=fopen("book.txt","r");
tempfile=fopen("temporary.txt","w+");
rewind(bookfile);
while(!feof(bookfile))
{
if(fscanf(bookfile,"%d%s%s%s%d%d",&booknum,&b,&d,&a,&p,&pages)>0)
{
if(booknum!=id)
{
fprintf (tempfile, "\n%-5d %-20s %-20s %-20 %-5d %-5d",booknum,b,d,a,p,pages);
}
}
}
fclose(bookfile);
fclose(tempfile);

bookfile=fopen("book.txt","w+");
tempfile=fopen("temporary.txt","r");
rewind(tempfile);
while(!feof(tempfile))
{
if(fscanf(tempfile,"%d%s%s%s%d%d",&booknum,&b,&d,&a,&p,&pages)>0)
{
if(booknum!=id)
{
fprintf (bookfile, "\n%-5d %-20s %-20s %-20s %-5d %-5d",booknum,b,d,a,p,pages);
}
}
}
fclose(bookfile);
fclose(tempfile);
}

void viewOneMecha()
{
int booknum;
char b[25],d[25],a[25];
int p, pages;
found=false;
cout<<"\n\nType Book Number to be viewed:";
cin>>id;
bookfile=fopen("book.txt","r");
rewind(bookfile);
while(!feof(bookfile)&&found==false)
{
if(fscanf(bookfile,"%d%s%s%s%d%d",&booknum,&b,&d,&a,&p,&pages)>0)
{
if(booknum==id)
{
displaybook();
cout<<setw(15)<<booknum<<setw(15)<<b<<setw(15)<<d<<setw(15)<<a<<setw(15)<<p<<setw(15)<<pages<<"\n";
found=true;
}
}
}
if(found==false)
{
cout<<"\nBook Record is not existing!";
}
fclose(bookfile);
}

void displaybook()
{
cout<<"\n"<<setw(15)<<left<<"book Number"
<<setw(15)<<left<<"Book Title"
<<setw(15)<<left<<"Description"
<<setw(15)<<left<<"Author"
<<setw(15)<<left<<"published"
<<setw(15)<<left<<"pages"<<"\n";
}


void pass()
{
char c;
string password;
system("cls");
{
cout << "\nEnter Your Password: ";
while ((c=getch()) != 13) {
cout << "*";
password+=c;
}
if (password == "hergo")
{
cout<<"\n\n\nCorrect Password!\n\n\n";
system("PAUSE");
}
else
{
cout<<"\n\nPassword did not match!";
cout<<"\n\nEnter Password again!..\n";
system("pause");
pass();
}
}
}


I am looking forward for your replies. Please do help.. thanks
AGAIN..

I badly need to finish this program before wednesday nextweek :(
i am only a freshmen college student and i am still getting familiar of all the codes in c++. My only problem in this code is how to put a BORROWING and RETURNING process. I wanted to have a process like this:
1. After the user chooses BORROW, the program will ask for the ID No. of the student.
2. If the student ID No. is available, the program will display its info and ask if the user would like to borrow a book.
3. If the user chooses yes, the program will display the categories of books such as filipiniana etc.
4. Then the user will choose which kind of book.
5. After borrowing the program will display that the borrowing was successful.
The returning process goes the same way..

THANK YOU SO MUCH.
Topic archived. No new replies allowed.