I am creating a Library Management system. And Im having a problem.
I have a Main.cpp, Book.cpp, DVD.cpp and Student.cpp. I am creating a book and dvd object in the Main.cpp and also a student object in the Student.cpp. I am trying to use the dvd, book and student objects in the Book.cpp and DVD.cpp but unsure how to do it.
I have included some of the code from each of the .cpp files showing the use of the objects.
void DVD::issueDVD()
{
fstream file,file1;
char studentno[6],bookno[6];
int found=0,sys=0;
cout<<"Enter the Registration no. of the Student: "<<endl;
cin>>studentno;
file.open("student.dat",ios::in|ios::out);
file1.open("book.dat",ios::in|ios::out);
while(file.read((char*)&student3,sizeof(Student)) && found==0)
{
if(strcmp(student3.retregistrationNo(),studentno)==0)
{
found=1;
cout<<"Enter barcode of the Book you want to issue: "<<endl;
cin>>bookno;
while(file1.read((char*)&dvd1,sizeof(DVD))&& sys==0)
{
if(strcmp(retBarcode(),bookno)==0)
{
displayDVD();
sys=1;
student3.getstudentbookBar(retBarcode());
long pos=-1*sizeof(student3);
file.seekp(pos,ios::cur);
file.write((char*)&student3,sizeof(Student));
cout<<"Book issued";
}
}
if(sys==0)
cout<<"Error: Book barcode does not exist. "<<endl;
}
}
if(found==0)
cout<<"Error: Student does not exist in the system. "<<endl;
file.close();
file1.close();
}
For using the class or function declared in a .cpp (or .h) you must include his header file. So if for instance you want to use the book class, you must include his header file (Book.h, assuming that this is his name).