i'm a newbie in this structure function, string functions, and i have this project of mine due on tuesday, march 17. Our professor wants us to have a book information system with add, delete display and exit . how can i display the information that will be input?? how can it be save? and after it is saved, how can someone delete it?? i already finish the add choice.. please, i need assistance with this.. thank you very much in advance for someone who can help me.. thank you thank you
Another way to do this is to determinate a max number of objects, lets say 100, and then create an array from your class with 100 elements. A variable "size" can be used to keep track of the number of objects. A simple function could be used to 'remove' an object by transporting all objects after that object one place forward. Overloading a operator= could be usefull.
cout<<" BOOK INFORMATION SYSTEM "<<endl;
cout<<endl<<">>>>> MENU<<<<< "<<endl;
cout<<" ADD BOOK "<<endl;
cout<<"How many books you want to add?:";
cout<<"TITLE OF THE BOOK:";
cout<<"NUMBER OF PAGES:";
cout<<"TITLE OF THE BOOK YOU WANT TO DELETE:";
this are my codes so far..:]
how can i use the pointer here for the delete choice?
Then you can create an array to hold the books in (let's say up to 100), and a variable to keep track of the number of books:
int size = 0;
Now, adding a book is easy (add 1 to size and store the data into object book[size-1]). To remove an object, you could write a function. Let's say we have three books "a", "b" and "c", and the second book is removed. Now all the data of the objects after the second object, need to be moved one place forward (this can be done with a for-loop), so we'll get "a" and "c" in the first two objects. And of course you should substract one to size.
what i'm trying to ask is, after inputting some data at the add choice, it will be stored. (where will the data be stored?) then after that, for example, i want to display the data that are stored, it should get the data from what is stored from the add choice. and after that i want to delete an item there, after choosing delete, a new screen will appear then ask the title of the book that wants to be deleted. How will the program find that book? argh.. it's driving me crazy.. T.T pls.. thank you thank you
Book book; //array of the structure I showed before
int size = 0; //integer to keep track of the number of books
... //add books
string title; //string to store the title of the book that should be removed in
cout<<"Enter the title of the book you want to delete:\n";
getline(cin,title); //get title of book
//go through all books and find the book with the tilte
for (int i=0;i<size;i++)
if (book[i].Title == title) //if this is the book
//go through all books and place them one place back
for (int j=i;j<size-1;j++)
book[j].Title = book[j+1].Title;
book[j].Author = book[j+1].Author;
size--; //one book is deleted; substract one from size
break; //break out the loop
Well, it will probably work the same. But I recommend you to use the new version of the headers, and to download the newest version of your compiler. (I have never worked with the old headers, I don't know what differences there are)
The declaration of struct Book (line 12) should be before the declaration of the array (line 8). s (line 20) is missing a data-type.
Probably not nessecary for your compiler, but official C++: add usingnamespace std; after the headers, make main of type integer and use the modern headers (<iostream>, not <iostream.h>), replace clrscr() with system("cls");, replace exit(0); with return 0;
I haven't looked at the logic behind your program, but this are the most obvious errors.
thank you.. :]
but when i changed exit(0); to return(0); my program got more errors than before.. by the way, what is the prototype for getline? isnt it sys/type.h or geline.h?? and their asking me for an Lvalue?? what's that?? sorry sorry..>.< and may i ask what will be the output of your code?? :]
excuse me, but.. how will i return to the main page. like for example, i finished adding books in the add page, how will i go back to the main page without terminating the program and run it again? pls pls help... >.<