Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The class you are going to create for this assignment is called Library The Library class is going to incorporate the std::vector logic from today's

  • The class you are going to create for this assignment is called Library
  • The Library class is going to incorporate the std::vector logic from today's lesson
  • m_Books of type std::vectorThe Library class will have 1 private member variable:
  • There should be a public constructor, the constructor should not take any parameters
  • The Library class will have 3 public methods:
  • Output, with a return type of void and takes zero parameters
  • CheckInBook, with a return type of void and takes 3 parameters: (title of type std::string, author of type std::string, dateOfPublication of type Date)
  • NumberOfBooks, with a return type of unsigned int and takes zero parameters
  • The Library's Output method should output the text "The Libary currently has ** books:",(replace ** with the actual number of books currently in the m_Books std::vector), followed by the list of books sorted by publication date (sorted oldest to most recent)
  • The Library's CheckInBook should make a Book object using the parameters and push_back the Book object onto the m_Books std::vector, then output the title of the book that has been checked in, lastly sort the m_Books std::vector by publication date (sorted oldest to most recent)
  • The Library's NumberOfBooks method should return the number of books in the m_Books std::vector
  • The Library class should be broken up into the appropriate .h and .cpp files

main .cpp

#include "library .h"

int main()

{

Library library ;

Library.CheckBookIn("TheHobbit","J.R.R.Tokien",Date(21,9,1937));

Library.CheckBookIn("Dracula","BramStoker",Date(26,5,1897));

Library.CheckBookIn("JaneEyre","CharlotteBronte",Date(16,10,1847));

Library.CheckBookIn("ToKillaMockingbird","HarperLee",Date(11,7,1960));

Library.CheckBookIn("TheGreatGatsby","F.ScottFitzgerald",Date(10,4,1925));

system("pause");

system("cls");

Library.Output();

System("pause");

System("cls");

Library.CheckBookIn("1984","GeorgeOrwell",Date(8,6,1949));

Library.CheckBookIn("The grapes of Wrath, "John Steinbeck", Date(14, 4 , 1939));

System("pause");

System("cls");

return 0;

}

Date.cpp

#include"Date.h"

#include

#include

#include

Date::Date():

m_Day(0),

m_Month(0),

m_Year(0)

{

}

Date::Date(intday,intmonth,intyear):

m_Day(day),

m_Month(month),

m_Year(year)

{

}

voidDate::Set(intday,intmonth,intyear)

{

m_Day=day;

m_Month=month;

m_Year=year;

}

intDate::GetDay()

{

returnm_Day;

}

intDate::GetMonth()

{

returnm_Month;

}

intDate::GetYear()

{

returnm_Year;

}

voidDate::Output()

{

std::cout<

}

DateDate::CalculateAge(DatepresentDay)

{

constintNUM_MONTHS=12;

constintDAYS_IN_A_MONTH[NUM_MONTHS]={31,28,31,30,31,30,31,31,30,31,30,31};

intday=0;

intmonth=0;

intyear=presentDay.GetYear()-GetYear();

if(presentDay.GetMonth()

{

year--;

month=NUM_MONTHS-(GetMonth()-presentDay.GetMonth());

}

else

{

month=presentDay.GetMonth()-GetMonth();

}

if(presentDay.GetDay()

{

month--;

day=DAYS_IN_A_MONTH[presentDay.GetMonth()-1]-(GetDay()-presentDay.GetDay());

}

else

{

day=presentDay.GetDay()-GetDay();

}

returnDate(day,month,year);//muchbetter

}

DateDate::Today()

{

std::chrono::time_pointnow=std::chrono::system_clock::now();

std::time_tnowTime=std::chrono::system_clock::to_time_t(now);

std::tmcalender={};

localtime_s(&calender,&nowTime);

returnDate(calender.tm_mday,calender.tm_mon+1,calender.tm_year+1900);

}

std::stringDate::MonthToString()

{

if(m_Month>0&&m_Month<=12)

{

conststd::stringmonths[]={"January","February","March","April","May","June","July","August","September","October","November","December"};

intmonthIndex=m_Month-1;

returnmonths[monthIndex];

}

return"Unknown";

}

Date.h

#pragmaonce

#include

classDate

{

public:

Date();

Date(intday,intmonth,intyear);

voidSet(intday,intmonth,intyear);

intGetDay();

intGetMonth();

intGetYear();

voidOutput();

DateCalculateAge(DatepresentDay);

staticDateToday();

private:

std::stringMonthToString();

intm_Day;

intm_Month;

intm_Year;

};

BOOK.CPP

#include"Book.h"

#include

Book::Book(std::stringtitle,std::stringauthor,DatepublicationDate):

m_Title(title),

m_Author(author),

m_PublicationDate(publicationDate)

{

}

voidBook::Output()

{

std::cout<

m_PublicationDate.Output();

std::cout<

}

std::stringBook::GetTitle()

{

returnm_Title;

}

std::stringBook::GetAuthor()

{

returnm_Author;

}

DateBook::GetPublicationDate()

{

returnm_PublicationDate;

}

boolBook::CompareBooks(Book&bookA,Book&bookB)

{

returnDate::CompareDates(bookA.m_PublicationDate,bookB.m_PublicationDate);

}

BOOK.h

#pragmaonce

#include

#include"Date.h"

classBook

{

public:

Book(std::stringtitle,std::stringauthor,DatepublicationDate);

voidOutput();

std::stringGetTitle();

std::stringGetAuthor();

DateGetPublicationDate();

staticboolCompareBooks(Book&bookA,Book&bookB);

private:

//Membervariables

std::stringm_Title;

std::stringm_Author;

Datem_PublicationDate;

};

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Describe the benefits of using self-managed teams in organizations.

Answered: 1 week ago

Question

What are the strengths and limitations of cost-benefit analysis?

Answered: 1 week ago