C++

Write C++ program to create five object of book, get information of book using getdata() function including name, price, publication and author.
Then
Write search() function to search a specified book, if book is search return the complete information of book and print the information of book using putdata() function.
Question is how to search book name in program? Please help me
Try to explain what you know and how you want to approach the problem because now I am confused about what you already know, or how much C++ you can handle.

My suggestion would be use a class or struct that has a vector of strings. Write a getter function, and a setter function to set information and then retrieve it.

the get function can return the name of the book depending on the name of the book you write or the number you choose. Ex. 1, 2, 3, 4, 5. Then it returns the information that already exists about the book using a print function and couts.

Ex.
if (book #1){
print info about book 1
} else if (book #2){
print book 2 stuff
}

I hope this helps.
It is done by using class but i'm confused how to compare names of book
Basically, We are not going to do your homework for you. You say you've done some code already. Please post that code here, so we can look at it and help you. When you post your code use code tags - http://www.cplusplus.com/articles/jEywvCM9/
I'm not saying you to do my homework i just want a logic that how to compare char type values
You should look up the linear search algorithm.
This involves keeping a collection of books, and examining each one in turn until you find one which matches. Very straightforward stuff.

If your question is about how to compare strings, you can use < to do that.
Last edited on
Topic archived. No new replies allowed.