Click here to Skip to main content
15,917,328 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionallocating object in global storage Pin
ForNow7-May-12 15:21
ForNow7-May-12 15:21 
AnswerRe: allocating object in global storage Pin
Richard MacCutchan7-May-12 21:50
mveRichard MacCutchan7-May-12 21:50 
AnswerRe: allocating object in global storage Pin
ThatsAlok9-May-12 21:17
ThatsAlok9-May-12 21:17 
AnswerRe: allocating object in global storage Pin
Erudite_Eric9-May-12 21:27
Erudite_Eric9-May-12 21:27 
GeneralRe: allocating object in global storage Pin
ForNow10-May-12 2:50
ForNow10-May-12 2:50 
AnswerRe: allocating object in global storage Pin
Chuck O'Toole10-May-12 3:32
Chuck O'Toole10-May-12 3:32 
GeneralRe: allocating object in global storage Pin
Erudite_Eric13-May-12 21:02
Erudite_Eric13-May-12 21:02 
QuestionDigital Library system, Help needed Pin
ShayanTanwir7-May-12 13:32
ShayanTanwir7-May-12 13:32 
Here's my code for Digital Library system

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

//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************



class book
{
char bno[6];
char bname[50];
char aname[20];
public:
void create_book()
{
cout<<"\nNEW BOOK ENTRY...\n";
cout<<"\nEnter The book no.";
cin.getline(bno,6);
cout<<"\n\nEnter The Name of The Book ";
cin.getline(bname,50);
cout<<"\n\nEnter The Author's Name ";
cin.getline(aname,20);
cout<<"\n\n\nBook Created..";
}

void show_book()
{
cout<<"\nBook no. : "<<bno;
cout<<"\nbook="" name="" :="" "<<bname;
="" cout<<"author="" "<<aname;
="" }

="" char*="" retbno()
="" {
="" return="" bno;
="" void="" report()
="" {cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}


};="" class="" ends="" here


="" ***************************************************************
="" global="" declaration="" for="" stream="" object,="" object
="" ****************************************************************

fstream="" fp,fp1;
book="" bk;


="" function="" to="" write="" in="" file
="" ****************************************************************

void="" write_book()
{
="" char="" ch;
="" fp.open("book.txt",ios::out|ios::app);
="" do
="" system="" ("cls");
="" bk.create_book();
="" fp.write((char*)&bk,sizeof(book));
="" cout<<"\n\ndo="" you="" want="" add="" more="" record..(y="" n?)";
="" cin="">>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}

//***************************************************************
// function to read specific record from file
//****************************************************************


void display_spb(char n[])
{
cout<<"\nBOOK DETAILS\n";
int flag=0;
fp.open("book.txt",ios::in);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book();
flag=1;
}
}

fp.close();
if(flag==0)
cout<<"\n\nBook does not exist";
getch();
}

//***************************************************************
// function to delete record of file
//****************************************************************

void delete_book()
{
char n[6];
system ("cls");
cout<<"\n\n\n\tDELETE BOOK ...";
cout<<"\n\nEnter The Book no. of the Book You Want To Delete : ";
cin>>n;
fp.open("book.txt",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.txt",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(book));
}
}

fp2.close();
fp.close();
remove("book.txt");
rename("Temp.txt","book.txt");
cout<<"\n\n\tRecord Deleted ..";
getch();
}

//***************************************************************
// function to display Books list
//****************************************************************

void display_allb()
{
system ("cls");
fp.open("book.txt",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}

cout<<"\n\n\t\tBook LIST\n\n";
cout<<"=========================================================================\n";
cout<<"Book Number"<<setw(20)<<"book name"<<setw(25)<<"author\n";
="" cout<<"="========================================================================\n";

" while(fp.read((char*)&bk,sizeof(book)))
="" {
="" bk.report();
="" }
="" fp.close();
="" getch();
}

="" ***************************************************************
="" introduction="" function
="" ****************************************************************

void="" intro()
{
system="" ("cls");
="" gotoxy(35,11);
="" cout<<"library="" ";
="" gotoxy(35,14);
="" cout<<"management";
="" gotoxy(35,17);
="" system";
="" cout<<"\n\nmade="" by="" :="" team="" alpha";
="" cout<<"\n\ngiki";
="" getch();
}



="" administrator="" menu="" admin_menu()
{
system="" int="" ch2;
="" cout<<"\n\n\t1.create="" book="" cout<<"\n\n\t2.display="" all="" books="" cout<<"\n\n\t3.display="" specific="" cout<<"\n\n\t4.delete="" cout<<"\n\n\t5.back="" to="" main="" menu";
="" cout<<"\n\n\tplease="" enter="" your="" choice="" (1-5)="" cin="">>ch2;
switch(ch2)
{
case 1: system ("cls");
write_book();
break;
case 2: display_allb();
break;
case 3: {
char num[6];
system ("cls");
cout<<"\n\n\tPlease Enter The book No. ";
cin>>num;
display_spb(num);
break;
}
case 4: delete_book();break;
case 5: return;
default:cout<<"\a";
}
admin_menu();
}


//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************


int main()
{
char ch;
intro();
do
{
system ("cls");
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. ADMINISTRATOR MENU";
cout<<"\n\n\t02. EXIT";
cout<<"\n\n\tPlease Select Your Option (1-4) ";
ch=getche();
switch(ch)
{
case '1':admin_menu();
break;
case '2':exit(0);
default :cout<<"\a";
}
}while(ch!='4');
}

//***************************************************************
// END OF PROJECT
//***************************************************************


I'm unable to enter the books without skipping the book code (the program omits it). Also, once i create a book entry, when i try to display all the books, at times, the file does not open.
Please point out any mistakes and resolve them as this is my project due today.
Any help would be appreciated
my program need to be able to write, read, delete and search a database.
ST
VB 6 user!

AnswerRe: Digital Library system, Help needed Pin
Chris Losinger7-May-12 13:35
professionalChris Losinger7-May-12 13:35 
Questiontry and catch, not sure how to handle catch Pin
jkirkerx7-May-12 10:34
professionaljkirkerx7-May-12 10:34 
AnswerRe: try and catch, not sure how to handle catch Pin
Chuck O'Toole7-May-12 10:45
Chuck O'Toole7-May-12 10:45 
GeneralRe: try and catch, not sure how to handle catch Pin
jkirkerx7-May-12 10:50
professionaljkirkerx7-May-12 10:50 
AnswerRe: try and catch, not sure how to handle catch Pin
Chuck O'Toole7-May-12 12:13
Chuck O'Toole7-May-12 12:13 
GeneralRe: try and catch, not sure how to handle catch Pin
jkirkerx7-May-12 12:58
professionaljkirkerx7-May-12 12:58 
AnswerRe: try and catch, not sure how to handle catch Pin
Aescleal8-May-12 3:55
Aescleal8-May-12 3:55 
GeneralRe: try and catch, not sure how to handle catch Pin
jkirkerx8-May-12 6:55
professionaljkirkerx8-May-12 6:55 
QuestionCan not Find Functions In Static Library Pin
AmbiguousName7-May-12 1:37
AmbiguousName7-May-12 1:37 
AnswerRe: Can not Find Functions In Static Library Pin
Chris Meech7-May-12 4:10
Chris Meech7-May-12 4:10 
AnswerRe: Can not Find Functions In Static Library Pin
Albert Holguin7-May-12 7:33
professionalAlbert Holguin7-May-12 7:33 
GeneralRe: Can not Find Functions In Static Library Pin
AmbiguousName7-May-12 7:42
AmbiguousName7-May-12 7:42 
AnswerRe: Can not Find Functions In Static Library Pin
Chuck O'Toole7-May-12 8:09
Chuck O'Toole7-May-12 8:09 
AnswerRe: Can not Find Functions In Static Library Pin
AmbiguousName7-May-12 18:47
AmbiguousName7-May-12 18:47 
AnswerRe: Can not Find Functions In Static Library Pin
Chuck O'Toole7-May-12 19:41
Chuck O'Toole7-May-12 19:41 
GeneralRe: Can not Find Functions In Static Library Pin
AmbiguousName7-May-12 20:10
AmbiguousName7-May-12 20:10 
AnswerRe: Can not Find Functions In Static Library Pin
Chuck O'Toole8-May-12 3:46
Chuck O'Toole8-May-12 3:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.