Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int NUMBER_OF_BOOKS = 3;
- struct Book {
- char title[30];
- char author[30];
- char isbn[10];
- };
- struct Library {
- Book books[1000];
- };
- Book readBook()
- {
- Book newBook;
- cout << "Give me a book title:" << endl;
- cin >> newBook.title;
- cout << "Give me a book author:" << endl;
- cin >> newBook.author;
- cout << "Give me a book isbn:" << endl;
- cin >> newBook.isbn;
- return newBook;
- }
- Library* readAndAddBook(Library* library,int indexOfBook)
- {
- Book newBook = readBook();
- library->books[indexOfBook] = newBook;
- return library;
- }
- void printBooksInLibrary(Library* library,int size)
- {
- for (int i = 0; i < size; i++)
- {
- cout << library->books[i].title << endl;
- cout << library->books[i].author << endl;
- cout << library->books[i].isbn << endl;
- }
- }
- int main()
- {
- Library* myLibrary = new Library;
- for (int i = 0; i < NUMBER_OF_BOOKS; i++)
- {
- myLibrary = readAndAddBook(myLibrary, i);
- }
- printBooksInLibrary(myLibrary, NUMBER_OF_BOOKS);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement