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 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 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 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 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);
}
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..