首页 > > 详细

COMP26020辅导、辅导C++程序设计

COMP26020 Part 1– Assignment 2:
Library Management Software in C++
The goal of this assignment is to implement a set of C++ classes that aim to be used in a library management
software. The library holds documents of different types (novels, comics and magazines) with various attributes
(title, author, etc.) and users can borrow and return documents. You are given a header file library.h with the
different classes definitions including inheritance relationships as well as the prototypes for all classes’ methods. A
first task is to implement each of these methods in a single C++ source file, library.cpp. To test your
implementation, you are given a test suite in the form of a program that instantiates the classes in question, and
performs various sanity checks. A second task is to write a Makefile to automate the build of that test program.
You can download an archive with the library header file as well as the test suite sources here:
https://olivierpierre.github.io/comp26020/labs/lab2/comp26020p1-lab2.zip
Class Hierarchy
The library.h header defines 5 classes which are briefly presented below. Note that more detailed information
about the methods to implement is present in the header’s source code in the form of comments.
• Document is an abstract class defining attributes and methods common to all the documents that can be
held in the library. Attributes include the document’s title, year of release, and quantity held in the library.
It defines various methods for printing the document’s information on the standard output, getting its
concrete type (novel/comic/magazine), and various getters/setters including methods for
borrowing/returning the document from/to the library.
• Novel, Comic and Magazine represent the concrete types of
documents. Each inheritates from Document as depicted on the
figure on the right. They differ slightly in attributes: a novel and a
comic have an author, comics and magazines have an issue number,
and a magazines do not have an author. Each class also defines the
relevant getters/setters.
• The last class, Library, represents the library i.e. a collection of documents, held in a vector attribute.
The library class defines various methods for actions such as adding, removing, searching, borrowing,
returning documents, printing the library content on the standard output or dumping it in a CSV file.
Test Suite
To test your implementation you are given a basic test suite in the form of a C++ file, test-suite.cpp. It’s a C++
program (i.e. it contains a main function) that includes library.h. It instantiates/manipulates objects from all the
aforementioned classes, and performs many sanity checks. This program uses the Catch1
test framework and
requires two additional source files to be compiled: catch.cpp and catch.h. You can compile and run the test
program as follows:
$ g++ test-suite.cpp library.cpp catch.cpp -o test-suite
$ ./test-suite
Obviously the compilation command will fail as long as you don’t implement all of the methods invoked in the test
suite. Once it compiles and run, the program will list the tests executed and which test succeeded/failed. It is a
good idea to investigate the suite source file test-suite.cpp in order to understand what is checked for each
test. The suite is divided into tests cases enclosed into TEST_CASE() { ... } statements. A test case will fail
when one of the REQUIRE( ) or CHECK( ) statements it contains fails, i.e. when
condition evaluates to false. To complete the assignment you do not need to understand the content of catch.h
and catch.cpp, these files implement the Catch engine and are rather complicated.
1 https://github.com/catchorg/Catch2
Document class hierarchy
To avoid typing the long build command, automate dependency management, and speed up the test suite build,
you should write a Makefile as presented in the course.
The test suite is not fully comprehensive and, although passing all the tests it contains means that a good chunk of
the assignment has been accomplished and that the implementation seems functional, it does not mean that
everything is perfect. When marking, an extended test suite will be used, and other good C/C++ programming
practices mentioned in the course will be taken into account such as proper memory management, code style, etc.
Documents/Library Printing and CSV Output Formats
The print() method, when called on a novel, should print on the standard the novel’s attributed following this
format:
Novel, title: Harry Potter, author: J. K. Rowling, year: 1997, quantity: 1
For a comic:
Comic, title: Watchmen, author: Alan Moore, issue: 1, year: 1986, quantity: 10
And for a magazine:
Magazine, title: The New Yorker, issue: 1, year: 1925, quantity: 20
The print() method called on a library containing these 3 documents should produce:
Harry Potter, author: J. K. Rowling, year: 1997, quantity: 1
Comic, title: Watchmen, author: Alan Moore, issue: 1, year: 1986, quantity: 10
Magazine, title: The New Yorker, issue: 1, year: 1925, quantity: 20
Finally, the dumpCSV() method called on the same library should use low level file I/O functions (open, etc.) to
produce a file with the following format:
novel,Harry Potter,J. K. Rowling,,1997,1
comic,Watchmen,Alan Moore,1,1986,10
magazine,The New Yorker,,1,1925,20
Because of the cohort’s size, the exercise will be partially marked using automated tools and for that reason it is
very important to respect these formats to the letter to avoid loosing points.
Deliverables, Submission & Deadline
There are two deliverables: the completed library.cpp file, as well as the Makefile automating the build of the
test suite. The submission is made through the CS Department’s Gitlab. You should have a fork of the repository
named “26020-lab2-library_”. Make sure you push to that precise repository and not another
one, failure to do so may result in the loss of some/all points. Submit your deliverables by pushing the
corresponding files on the master branch and creating a tag named lab2-submission to indicate that the
submission is ready to be marked.
The deadline for this assignment is 11/11/2021 5pm London time.
Marking Scheme
The exercise will be marked out of 10, using the following marking scheme:
• The program is functional, and passes the basic test suite /5
• The program passes extended tests /2
• The Makefile is functional and properly written /1
• The program follows the good C programming practices covered in the course regarding dynamic; memory
allocation, parameter management, code style /2

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!