c++ library system using vectors CSC 2110 Computer Science I Pregramming Project
ID: 3708019 • Letter: C
Question
c++ library system using vectors CSC 2110 Computer Science I Pregramming Project Due: 04/17/2018 11:00 PM 70 points+10 points extra credit-80 points Submission Format . The project should be subenitted using the Blackboard 2 Include all files in one folder and compress your folder using (zip) not rar 3. Includes all the following files in one folder A. The code and the files necessary to compile and test the project. B. Test Plan: Showing how you tested the program (show the steps of your testing procedure along with screen shots) (10 points) C. A short description of the design plan and general comments(S poiats) Final Project: Write a C+program to manage a library system. The main user is the librarian Build Specifikations (35 points) . The system should load a catalog of books, journals, and magazines at the start of the program (at lkast five of each) 2. A user can search the catalog: The user of the system can search the libeary's catalog by using the name of the item. Also, a user can list books by category (Book, Jourmal, or magazine If you are looking specifically for a book, you can search by the name of the author. 3. A user can check out books, joumals, or magazines: The user needs to find the item first, then they can check it out. A user cannot check out an item that is already checked out. 4 A user can return books, journals, or magazines: A user can return an item The user noeds to find the item first, then they can returm it 5. Add new boolks, journals, or magazines to the catalog.A librarian can add a new item to the catalogExplanation / Answer
C++ PROGRAM:
#include<fstream.h>// HEADER FILE
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>
class LibraryItem // Library Item include books, journal, magzine, papers
{
char bno[6];
char bname[50];
char aname[20];
public:
void create_LibraryItem()
{
cout<<" NEW LibraryItem ENTRY... ";
cout<<" Enter The LibraryItem no.";
cin>>bno;
cout<<" Enter The Name of The LibraryItem ";
gets(bname);
cout<<" Enter The Author's Name ";
gets(aname);
cout<<" LibraryItem Created..";
}
void show_LibraryItem()
{
cout<<" LibraryItem no. : "<<bno;
cout<<" LibraryItem Name : ";
puts(bname);
cout<<"Author Name : ";
puts(aname);
}
void modify_LibraryItem()
{
cout<<" LibraryItem no. : "<<bno;
cout<<" Modify LibraryItem Name : ";
gets(bname);
cout<<" Modify Author's Name of LibraryItem : ";
gets(aname);
}
char* retbno()
{
return bno;
}
void report()
{cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}
};
fstream fp,fp1;
LibraryItem bk;
void write_LibraryItem()
{
char ch;
fp.open("LibraryItem.dat",ios::out|ios::app);
do
{
clrscr();
bk.create_LibraryItem();
fp.write((char*)&bk,sizeof(LibraryItem));
cout<<" Do you want to add more record..(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
void display_spb(char n[])
{
cout<<" LibraryItem DETAILS ";
int flag=0;
fp.open("LibraryItem.dat",ios::in);
while(fp.read((char*)&bk,sizeof(LibraryItem)))
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_LibraryItem();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<" LibraryItem does not exist";
getch();
}
// -------- function to modify record of file
void modify_LibraryItem()
{
char n[6];
int found=0;
clrscr();
cout<<" MODIFY LibraryItem REOCORD.... ";
cout<<" Enter The LibraryItem no. of The LibraryItem";
cin>>n;
fp.open("LibraryItem.dat",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(LibraryItem)) && found==0)
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_LibraryItem();
cout<<" Enter The New Details of LibraryItem"<<endl;
bk.modify_LibraryItem();
int pos=-1*sizeof(bk);
fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(LibraryItem));
cout<<" Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<" Record Not Found ";
getch();
}
void delete_LibraryItem()
{
char n[6];
clrscr();
cout<<" DELETE LibraryItem ...";
cout<<" Enter The LibraryItem no. of the LibraryItem You Want To Delete : ";
cin>>n;
fp.open("LibraryItem.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&bk,sizeof(LibraryItem)))
{
if(strcmpi(bk.retbno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(LibraryItem));
}
}
fp2.close();
fp.close();
remove("LibraryItem.dat");
rename("Temp.dat","LibraryItem.dat");
cout<<" Record Deleted ..";
getch();
}
void display_allb()
{
clrscr();
fp.open("LibraryItem.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
cout<<" LibraryItem LIST ";
cout<<"==== ";
cout<<"LibraryItem Number"<<setw(20)<<"LibraryItem Name"<<setw(25)<<"Author ";
cout<<"===== ";
while(fp.read((char*)&bk,sizeof(LibraryItem)))
{
bk.report();
}
fp.close();
getch();
}
void LibraryItem_issue()
{
char sn[6],bn[6];
int found=0,flag=0;
clrscr();
cout<<" LibraryItem ISSUE ...";
cout<<" Enter The student's admission no.";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("LibraryItem.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),sn)==0)
{
found=1;
if(st.rettoken()==0)
{
cout<<" Enter the LibraryItem no. ";
cin>>bn;
while(fp1.read((char*)&bk,sizeof(LibraryItem))&& flag==0)
{
if(strcmpi(bk.retbno(),bn)==0)
{
bk.show_LibraryItem();
flag=1;
st.addtoken();
st.getstbno(bk.retbno());
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<" LibraryItem issued successfully Please Note: Write current date
in backside of LibraryItem and submit within 15 days fine Rs. 1 for each day
after 15 days period";
}
}
if(flag==0)
cout<<"LibraryItem no does not exist";
}
else
cout<<"You have not returned the last LibraryItem ";
}
}
if(found==0)
cout<<"Student record not exist...";
getch();
fp.close();
fp1.close();
}
void LibraryItem_deposit()
{
char sn[6],bn[6];
int found=0,flag=0,day,fine;
clrscr();
cout<<" LibraryItem DEPOSIT ...";
cout<<" Enter The student’s admission no.";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("LibraryItem.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),sn)==0)
{
found=1;
if(st.rettoken()==1)
{
while(fp1.read((char*)&bk,sizeof(LibraryItem))&& flag==0)
{
if(strcmpi(bk.retbno(),st.retstbno())==0)
{
bk.show_LibraryItem();
flag=1;
cout<<" LibraryItem deposited in no. of days";
cin>>day;
if(day>15)
{
fine=(day-15)*1;
cout<<" Fine has to deposited Rs. "<<fine;
}
st.resettoken();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<" LibraryItem deposited successfully";
}
}
if(flag==0)
cout<<"LibraryItem no does not exist";
}
else
cout<<"No LibraryItem is issued..please check!!";
}
}
if(found==0)
cout<<"Student record not exist...";
getch();
fp.close();
fp1.close();
}
MAIN.C
void main()
{
int ch;
do
{
clrscr();
cout<<" MAIN MENU";
cout<<" 1.DISPLAY CATALOG ";
cout<<" 2.SEARCH SPECIFIC ITEM ";
cout<<" 3. CHECKOUT";
cout<<" 4. RETURN";
cout<<" 5. EXIT";
cout<<" Please Enter Your Choice (1-5) ";
cin>>ch;
switch(ch)
{
case 1: display_allb();
break;
case 2: {
char num[6];
clrscr();
cout<<" Please Enter The Item No. ";
cin>>num;
display_spb(num);
break;
}
case 3: {
LibraryItem_issue();
break;
}
case 4:LibraryItem_deposit();
break;
case 5:exit(0);
default :cout<<"";
}
}while(ch!= 5);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.