mogesalmebit gtxovt damexmarot am programis dawerashi
* * *
Define the Book class with the following fields: a title, author list (being a list of strings, empty by
default), an edition year being an integer number and a unique positive sequential book number
(computed for each book using a static field counting all the books). Implement the following
public methods of the class:
• the constructor with parameters for a title and an edition year of the book (setting the book
number to the next free value),
• the copy-constructor and the assignment operator (ensuring that the books have different
sequential numbers),
• the destructor,
• getTitle, setTitle, getYear, setYear, getNumber methods,
• addAuthor – with an author as a parameter, adding a new author of the book as the last one,
• removeAuthor – with an author as a parameter, removing the author from the book's author
list (or throwing an error if the author is not in the author list),
• getAuthorCount – returning the number of authors of the book,
• the indexing operator ([]) – returning the book's author placed within the author list on the
position given as a parameter (1 means the first author, 2 means the second one, etc., an
error should be thrown for the position exceeding the number of authors),
• the shift operator (<<) – printing the book's title, year, its number, and the list of all its
authors.
Write a program which tests all the class capabilities, i.e. the following code should be enabled:
Book book1(“C++ Primer”, 2010);
cout << book1.getNumber(); //should be 1
cout << book1.getYear(); //should be 2010
book1.addAuthor(“Lipman”);
book1.addAuthor(“Lajoie”);
cout << book1.getAuthorCount(); //should be 2
book1[1] = “Lippman”; //changes the first author
cout << book1; //should print:
//Title: C++ Primer
//Year: 2010
//Number: 1
//Authors: Lippman, Lajoie
Book book2(“The C Programming”, 1985);
book2.addAuthor(“Kernignan”);
book2.addAuthor(“Smith”);
book2.addAuthor(“Ritchie”);
book2.setTitle(“The C Programming Language”);
cout << book2[2]; //should be Smith
book2.removeAuthor(“Smith”);
cout << book2[2]; //should be Ritchie
cout << book2.getAuthorCount(); //should be 2
cout << book2; //should print:
//Name: The C Programming Language
//Year: 1985
//Number: 2
//Authors: Kernighan, Ritchie
Book book3(book2);
cout << book3; //should print:
//Name: The C Programming Language
//Year: 1985
//Number: 3
//Authors: Kernighan, Ritchie
book3 = book1;
cout << book3.getTitle(); //should be C++ Primer
cout << book3.getNumber(); //should be 3
მიმაგრებული ფაილი ( Number of downloads: 130 )
test__3_.pdf