Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#pragma once * Date: December 19, 2022 * Topic: Lab 4 - Dynamic Memory * File name: Book.h * YOUR NAME, YOUR ID NUMBER *

#pragma once

* Date: December 19, 2022

* Topic: Lab 4 - Dynamic Memory

* File name: Book.h

* YOUR NAME, YOUR ID NUMBER

* This file declares a class named Book

*/

// Which header files should be included?

class Book {

private:

static int booksCreated;

string title;

int pages;

int bookNumber;

public:

Book();

Book(Book&);

~Book();

void setTitle(string);

void setPages(int);

int getBooksCreated() const;

string getTitle() const;

int getPages() const;

int getBookNumber() const;

void printBook() const;

};

/*

* Date: December 19, 2022

* Topic: Lab 4 - Dynamic Memory

* File name: Book.cpp

* YOUR NAME, YOUR ID NUMBER

* This file defines a class named Book

*/

// Which header files should be included?

// The class variable is initialized to 0

// The default constructor initializes the title to the

// empty string and pages to 0. bookNumber is initialized

// to one more than the current value of booksCreated,

// and booksCreated is incremented.

// The copy constructor initializes bookNumber to one more

// than the current value of booksCreated, and booksCreated

// is incremented. It initializes the title and pages to the

// same value as that of the title and pages of the parameter.

// The destructor prints the phrase "Book number [number] has

// been removed from the collection"

// define the setters and getters

// The printBook method uses printf to print the book's state

// in a table ready format. It prints the book number aligned

// to the left in a 3-space column, the number of pages also

// aligned to the left in an 8-space column, and finally the

// book's title (no column size).

/*

* Date: December 19, 2022

* Topic: Lab 4 - Dynamic Memory

* File name: lab04.cpp

* YOUR NAME, YOUR ID NUMBER

* This file implements a class named Book

*/

// Which header files should be included?

int main() {

// declare a pointer to a Book object named myCollection

// and initialize it to the null pointer

// declare an integer variable named books and initialize it to 0

// prompt the user for the amount of books using the phrase

// "Enter the amount of books in your collection: ", and store

// the value in the previously declared integer variable

// The value used must be greater then 3

// Create a Book array using the number of books as the size

// Implement a for iteration control structure to prompt the user

// for the title and number of pages of each book in the collection

// The last book in the array is initialized using the copy constructor

// using the reference of the second book.

// print the following header using the same column sizes as in printBook

// The data to be printed is the # symbol, PAGES, and TITLE

// Using a for iteration control structure call the print method for each book

// Release the memory allocated to the Book array

// print a statement with your personal information using the phrase

// "--- Program developed by [YOUR NAME], ID# [YOUR ID NUMBER] ---"

// where the square brackets and the text within is substituted with your personal

// information. Make sure to add a blank line before and after the phrase is printed.

system(" pause"); // For Visual Studio only!

return 0;

}

Can you finish the code please

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions