In the destructor, you need to perform a thorough cleanup. If there are dynamically allocated arrays or memories that have not been deleted, you need to delete them.

computer science

Description

You are to write a program that uses classes to read in information of books, print them (in unsorted order), sort them and print them (in sorted order) again.

 

There are two classes you will implement: CBook, and CLibrary.  There header files are provided below.

 

CBook.h

#pragma once

 

#include <string>

 

class CBook

{

    private:

        std::string     mTitle;

        std::string     mAuthor;

        int             mYearPublished;

 

    public:

        CBook();

        CBook(std::string Title, std::string Author, int YearPublished);

        ~CBook();

 

        std::string     GetTitle() const;

        std::string     GetAuthor() const;

        int             GetYearPublished() const;

        void            SetBook(std::string Title, std::string Author, int YearPublished);

        void            SetTitle(std::string Title);

        void            SetAuthor(std::string Author);

        void            SetYearPublished(int YearPublished);

        void            Swap(CBook &Book);

};

 

 

 


 

 

CLibrary.h

#pragma once

 

#include "CBook.h"

 

class CLibrary

{

    private:

        int             mNumBooks;

        CBook           *mBooks;

        std::string     mInputFileName;

        std::string     mOutputFileName;

 

    public:

        CLibrary();

        CLibrary(std::string InputFileName, std::string OutputFileName);

        ~CLibrary();

 

    private:

        void    Sort(CBook *Books, int Size);

 

    public:

        void    ReadBooks();

        void    Sort();

        void    PrintBooks(std::string Header);

};

 

 

 

 

Input spec:

            First line:                     Number of books

            Second line down:      Repetition of the following (Number of books) times:

Title,                (in a line by itself)

Author,                        (in a line by itself)

Year Published            (in a line by itself)

 

            •           In the destructor, you need to perform a thorough cleanup.  If there are dynamically allocated arrays or memories that have not been deleted, you need to delete them.  If there are files still opened, you need to close them.  This will be checked strictly.

            •           If you need to add member variables and/or member functions, make them private.

            •           Each book will be printed in one line.  The first character of Title should be lined up, and the same for the Author.

            •           In the first three lines of the output, print your name, section, and assignment number.

 

The official input will be available by 5/26/2020.

 

In every program file (.cpp and/or .h) you turn in, use comment lines to show the following:

            //Your name

            //Section

            //Assignment number

Submissions with no name, section, and assignment number will be asked to resubmit.

 

Turn in the following for credit.

            all .cpp files

            output file

 

 

Sample Input

 

8

C++

John

2019

Data Structures

Michael

2018

java

Alice

2014

Python

Lily

2008

java script

Albert

1998

C#

Mary

2015

Windows

James

2014

UNIX

Anna

1998

John Smith

Section 0112

Assignment #9

 

Sample Output

 

Unsorted

 

C++                 John                2019   

Data Structures     Michael             2018   

java                Alice               2014   

Python              Lily                2008   

java script         Albert              1998   

C#                  Mary                2015   

Windows             James               2014   

UNIX                Anna                1998   

 

 

Sorted

 

C#                  Mary                2015   

C++                 John                2019   

Data Structures     Michael             2018   

Python              Lily                2008   

UNIX                Anna                1998   

Windows             James               2014   

java                Alice               2014   

java script         Albert              1998   

 


Related Questions in computer science category