#include "structs.h" using namespace std; //this function initialize the array of authors void authors_init(string *a, int size_au){ for (int i = 0; i < size_au; ++i) { a[i] = "Authors..."; } } // this funciton initialize ONE book within the book array, at index idx void book_init_one_book(Book* book_arr, int idx){ book_arr[idx].pages = 200 * (idx+1); book_arr[idx].title = "Some title"; book_arr[idx].num_authors = idx+1; book_arr[idx].authors = new string [book_arr[idx].num_authors]; } //this function initialize the ENTIRE array of books void book_init (Book* book_arr, int size) { for (int i = 0; i < size; ++i) { //initialize book_arr[i] book_arr[i].pages = 200 * (i+1); book_arr[i].title = "Some title"; book_arr[i].num_authors = i+1; book_arr[i].authors = new string [book_arr[i].num_authors]; //initailize the authors of book_arr[i] authors_init(book_arr[i].authors, book_arr[i].num_authors); } } //print a single book object void print_book (Book &b){ cout << "----------------" << endl; cout << "Pages: " << b.pages << endl; cout << "Title: " << b.title << endl; for (int i = 0; i < b.num_authors; ++i) { cout << "Author " << i+1 << ": "; cout << b.authors[i] << endl; } cout << "----------------" << endl; } //free the dynamic memory void delete_books(Book* &arr, int size){ for (int i = 0; i < size; ++i) { delete [] arr[i].authors; arr[i].authors = nullptr; } delete [] arr; arr = nullptr; cout << "inside delete: " << arr << endl; }