473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Cant debug that error is in adding recored or in displayig

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

using namespace std;
class library
{
private:
struct lib
{
char flag;
int id;
string title;
string subject;
}books;

fstream file;

public:
library();
void addrec();
void listrec();
void modifyrec();
void delrec();
void recallrec();
void packrec();
void searchid();
void searchttl();
void exit();
};
//Zero argument constructor
library::library()
{
file.open("library",ios::binary|ios::in|ios::out);
if(!file)
{
cout<<endl<<"Unable to open file.";
exit();
}
}

//Add record
void library::addrec()
{
char ch;
file.seekp(0L,ios::end);
do
{
cout<<endl<<"Enter book id :";
cin>>books.id;
cout<<endl<<"Enter book title :";
cin>>books.title;
cout<<endl<<"Enter book subject :";
cin>>books.subject;

books.flag=' ';
file.write((char *)&books,sizeof(books));
cout<<"Add another record? (Y/N)";
cin>>ch;

}
while(ch=='y'||ch=='Y');
}

//List all records
void library::listrec()
{
int j=0;

file.seekg(0L,ios::beg);

while(file.read((char*)&books,sizeof(books)))
{
if(books.flag!='*')
{
cout<<endl<<"Record NO:"<<j++;
cout<<endl<<"ID is "<<books.id;
cout<<endl<<"Subject is "<<books.subject;
cout<<endl<<"Title is "<<books.title;
}
}
file.clear();
cout<<endl<<"Press any key...";
getch();
}

//Modify a record
void library::modifyrec()
{
int tempid;
int count=0;
long int pos;
cout<<"Enter id of book to modify"<<endl;
cin>>tempid;

file.seekg(0L,ios::beg);

while(file.read((char*)&books,sizeof(books)))
{
if(books.id==tempid)
{
cout<<"Enter new record"<<endl;
cout<<endl<<"Enter book id"<<endl;
cin>>books.id;
cout<<endl<<"Enter book title"<<endl;
cin>>books.title;
cout<<endl<<"Enter book subject"<<endl;
cin>>books.subject;
books.flag=' ';

//place pointer at record which has to
//be over written

pos=count*sizeof(books);
file.seekp(pos,ios::beg);
file.write((char*)&books,sizeof(books));
return;
}
count++;
}

cout<<endl<<"No book with id "<<tempid<<" is in record";
cout<<endl<<"Press any key...";
getch();

file.clear();
}

//Mark a record for deletion
void library::delrec()
{
int tempid;
int count=0;
long int pos;
cout<<"Enter id of book to delete"<<endl;
cin>>tempid;

file.seekg(0L,ios::beg);

while(file.read((char*)&books,sizeof(books)))
{
if(books.id==tempid)
{
books.flag='*';

pos=count*sizeof(books);
file.seekp(pos,ios::beg);
file.write((char*)&books,sizeof(books));
return;
}
count++;
}

cout<<endl<<"No book with id "<<tempid<<" is in record";
cout<<endl<<"Press any key";
getch();

file.clear();
}

//Recall the record
void library::recallrec()
{
int tempid;
int count=0;
long int pos;
cout<<"Enter id of book "<<endl;
cin>>tempid;

file.seekg(0L,ios::beg);

while(file.read((char*)&books,sizeof(books)))
{
if(books.id==tempid)
{
books.flag=' ';

pos=count*sizeof(books);
file.seekp(pos,ios::beg);
file.write((char*)&books,sizeof(books));
return;
}
count++;
}

cout<<endl<<"No book with id "<<tempid<<" is in record";
cout<<endl<<"Press any key.....";
getch();

file.clear();
}

//Removes all record permanently
void library::packrec()
{
//temp file
ofstream outfile;
outfile.open("temp",ios::out);

file.seekg(0L,ios::beg);

while(file.read((char*)&books,sizeof(books)))
{
if(books.flag!='*')
outfile.write((char*)&books,sizeof(books));
}

outfile.close();
file.close();
remove("library");
rename("temp","library");
//file.open("library.dat",ios::binary|ios::in|ios::o ut|ios::nocreate);
file.open("library",ios::binary|ios::in|ios::out);
}
//Search by id

void library::searchid()
{

int tempid;
cout<<"Enter id of book to search"<<endl;
cin>>tempid;

file.seekg(0L,ios::beg);

while(file.read((char*)&books,sizeof(books)))
{
if(books.id==tempid)
{
cout<<endl<<"Record NO:";
cout<<endl<<"ID is "<<books.id;
cout<<endl<<"Subject is "<<books.subject;
cout<<endl<<"Title is "<<books.title;
}

}

cout<<endl<<"Press any key...";
getch();

file.clear();
}
void library::searchttl()
{

string tempttl;
cout<<"Enter title of book to search"<<endl;
cin>>tempttl;

file.seekg(0L,ios::beg);

while(file.read((char*)&books,sizeof(books)))
{
if(books.title==tempttl)
{
cout<<endl<<"Record NO:";
cout<<endl<<"ID is "<<books.id;
cout<<endl<<"Subject is "<<books.subject;
cout<<endl<<"Title is "<<books.title;
}

}
cout<<endl<<"Press any key...";
getch();

file.clear();
}

void library::exit()
{
file.close();
}
void main()
{
char choice;
library book;

do
{
//clrscr();
cout<<endl<<"1.Add record"<<endl;
cout<<"2.List records"<<endl;
cout<<"3.Modify records"<<endl;
cout<<"4.Delete records"<<endl;
cout<<"5.Recall records"<<endl;
cout<<"6.Pack records"<<endl;
cout<<"7.Search by ID"<<endl;
cout<<"8.Search by title"<<endl;
cout<<"0.EXIT"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
//clrscr();

switch (choice)
{
case '1':
book.addrec();
break;

case'2':
book.listrec();
break;

case'3':
book.modifyrec();
break;

case'4':
book.delrec();
break;

case'5':
book.recallrec();
break;

case'6':
book.packrec();
break;

case'7':
book.searchid();
break;

case'8':
book.searchttl();
break;
case'0':
book.exit();
exit(1);
}
}

while (choice != 0);
}
Jul 19 '05 #1
0 1941

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: SÁRINGER Zoltán | last post by:
hi, When I open the connection to a JET database, I get 80004005 "unknown error". I know, it's usually permission problem, but I added all users to the db directory, and have this error only if...
0
by: IanT | last post by:
Hi I'm using Visual C++ .net I'm getting the linker error that one of my object files cant be found It seems that my compiler isnt producing .obj files (or at least not putting them in the debug...
3
by: Dan | last post by:
I get nothing but problems when trying to debug an ASP.Net project on our development server (I can debug projects locally on my computer fine). It keeps giving me this error when trying to debug...
2
by: dee | last post by:
Hi I am running .NET 1.0 on an Windows XP Pro and cant debug my VB web application. I get the following error message: "Error while trying to run project: Unable to start debugging on the web...
2
by: NAGY | last post by:
hello, I created an asp.net web app in C# from a non administrative account in Visual Studio 2003, .net 1.1. when i try to run the application in debug mode from Debug start menu option, i get an...
6
by: mike11d11 | last post by:
I cant seem to filter down my dataset table by criteria in expression. Can someone tell me why I still have the same amount of rows after I use this filter select option. Private Sub...
3
by: arun.hallan | last post by:
Hi, I'm having problems with authentication. I have a set of users that are allowed to use a webpage. They are in domain A. My goal is to get the username of these users and then check them...
1
by: arun2k3 | last post by:
hello, I installed dot net in my windows2000server system yesterday.. Whenever I try to open an ASP.NET Application and debug ASP.NET Application it returns errors. .. Whenever I try to open an...
0
by: tkatny | last post by:
How I Include External Input In Recored Macro. I Need The Macro To Pause Two (2) Times In Each Run And Repet Macro 20 Times. Thanks, Tad
2
by: CGatto | last post by:
Hi, We have just started getting the following error during compiles of our forms-based application. We are developing in VS2008, VB.Net, with Team Foundation Server-based source control. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.