C++语言 code Help代写题目 ：Simple Assignment CS2201 Spring 2018 Assignment No. 0
Assignment No. 0
Purpose: This assignment has several goals:
1. This is a relatively simple assignment, meant to get you back into programming after the semester break.
2. Make sure you can edit/compile/run C++ code in whatever IDE you will be using this semester (preferably CLion).
3. Gain experience in using and manipulating objects in C++.
4. Gain experience in writing test code that will thoroughly test a C++ class.
5. Make sure you can correctly submit code for grading via Brightspace.
You will be provided a C++ class that represents some type of object and you will write a program that exercises that class as fully as possible. Note: your task is only to test the supplied class; not to implement the class.
Assignment: This assignment deals with a calendar which stores a collection of reminders. The reminders will be storedin sorted (chronological) order. The Calendar class is able to contain up to MAX_REM (currently defined to be 50) reminders. The Calendar.h file describes all the functions provided by the class.
You will be provided with the source code that supports the reminders and object code (pre-compiled code) that supports the calendar. Your task will be to test the provided Calendar class as fully as possible to ensure it works as expected. This is known as test-driven development : we write code to test that a class works as expected, and afterward we write the class such that it passes all tests (the only difference is that I am giving you working code so that you can see if your tests are correct or not). Note: your task is to only test the Calendar class, not to implement the Calendar class. All the functions that you are to test are fully described in the Calendar.h file.
Functional Specifications: You will be supplied seven files:
• Date.h: declaration of the Date class (do not change)
• Date.cpp: definition of the Date class (do not change)
• Reminder.h: declaration of the Reminder class (do not change)
• Reminder.cpp: definition of the Reminder class (do not change)
• Calendar.h: declaration of the Calendar class (do not change)
• Calendar.cpp.obj or Calendar.cpp.o: compiled object code of the Calendar class which implements all the classfunctions [it was produced from a properly working Calendar.cpp file]
• CalTest.cpp: initial test program. Your job is to add code to the CalTest.cpp file to fully test/exercise theCalendar class.
The Calendar.h file contains the declaration of a set of functions to manipulate a calendar, which is implemented as a collection of Reminder objects. A predetermined maximum size of the collection is defined by the constant identifier MAX_REM. You will also be supplied a compiled object file, Calendar.cpp.obj or Calendar.cpp.o, which implements all the functions [it was created from a properly working Calendar.cpp file]. You will also be provided with an initial test program: CalTest.cpp. Your job is to add code to the CalTest.cpp file to fully test/exercise the Calendar class. Note: your task is to only test the Calendar class, not to implement the Calendar class. You are not to test the Date or Reminder classes – you can assume they work as given (if you think you have found a bug in either the Date or Reminder classes, please report them to the instructor or post them on Piazza).
Here are the methods/features of the Calendar class that you are to test (see the Calendar.h file for descriptions that are more complete):
Default constructor – creates an empty Calendar
Return the total number of Reminders in the Calendar
addRem(const Reminder &r)
Add a reminder to the Calendar
Returns the reminder at the specified index
Return a string of all reminders
Return a string of the reminder at a particular index
Return a string of all reminders whose message matches the
displayRem(const Date& d)
Return a string of all reminders for a given date
displayRem(const Date& d1,
Displays reminders in a range of two given dates
const Date& d2)
findRem(const Date& d)
Find first reminder for the given date and return its index
findRem(const string& str)
Find first reminder with the given message and return its index
Deletes all reminders earlier than today’s date
Deletes reminder object at a provided index position
Delete all reminders whose message matches a given string
deleteRem(const Date& d)
Deletes all reminders on a particular date
deleteRem(const Date& d1,
Deletes all reminders between a range of two given dates
const Date& d2)
Implementation details: Here are a few notes that might be helpful:
1. You are to download a zip file which is provided with this specification – be sure to download the correct one for your platform. The zip file contains a CLion project that includes starter code for this project. You must unzip/extract the files before you work on them. Once you unzip the file, you can open the project by starting CLion, then specify that you want to “Open Project”, and then navigate to the folder you just extracted. When you open the project, let CLion do its initialization work and load symbols (there are more details later in this document). The code as provided compiles cleanly (no errors or warnings) and executes successfully – though it only performs minimal testing in its distributed form. Again, you must unzip/extract the files before you work on them.
2. The test code that you write should be fully automated, as demonstrated in the small segment of provided test code. That means your test code should not depend upon reading any input from a user nor should it require the user to visually inspect any output. Relying on the user to enter all special cases to be tested is prone to omissions. Plus anyone else who uses such test code would not know what data to enter so that the class is fully tested.
3. You will likely be performing some operations with C++ strings. C++ string operations are described here. You will only need a few of the available operations in this assignment, such as length, at (or use [ ]), assignment, equality operator or compare method, substr, and maybe others.
4. The length() method of the string class returns a value of type size_t (an unsigned integer type). We also use variables and parameters of type size_t whenever we expect the value to be non-negative (e.g., parameters that represent an array index are declared to be size_t variables). The compiler may give you conversion warning messages if you attempt to assign/compare these values to a value of type int. Your homework submissions are expected to have clean compiles (no errors or warnings). To eliminate this particular warning, you can cast the size_t values to an int, or cast the int values to type size_t if you know the integer values are not negative. Note: all grading will be done with CLion and the clang compiler, which may produce different warning & error messages than other compilers – if you are developing with something other than CLion/clang, it is your responsibility to ensure you code compiles cleanly with CLion/clang.
5. The Calendar.h specifies that some methods throw an exception if someone attempts to perform an operation that is not allowed (e.g., adding a reminder to a full calendar). When an exception is thrown it will cause your program to stop executing if the exception is not handled. You will want to test the class to make sure exceptions are thrown appropriately, so you need to know how to handle the exceptions. To handle exceptions you use what is known as try-catch blocks, which can catch the thrown exceptions. The distributed CalTest.cpp file contains a try-catch block that you can duplicate to test the exception throwing capabilities of the Calendar class. Your test program must use try-catch blocks whenever it expects an exception to be thrown – this will allow your program to continue executing. You should write a new try-catch block for each exception you are testing. More information on C++ exceptions can be found on pages 228-237 in our text.
6. Note that if you do not understand how a method of the class is supposed to act from its description/specification, then you can simply try it out – you were supplied a working class as a part of the assignment.
7. To be perfectly clear, your job in this assignment is to fully test the Calendar class to the best of your ability. Your job is not to write the Calendar class – that code has been provided to you in the form of a compiled object file.
reminder and an associated date). Reminders are created/supported through two classes: the Date class and the Reminder class. Again, you may assume the Date & Reminder classes are bug-free. The purpose of this assignment is to only test the Calendar class.
In this program, a date is recognized in the MM/DD/YYYY format (Note: We have a four -digit year, which indicates that “18” would indicate the year 18, and not 2018, and so on. Also, it is assumed that the year cannot be more than four digits long). A reminder is a string message associated with a date. Since the reminder is essentially a date with an added feature (the associated message), the Reminder class is derived from the Date class by using inheritance.
The properties of the Date and Reminder classes (which are already provided to you) are given below (note: a Date object contains a month, day, and year, and is a very simplified class and so it does not handle leap year issues):
Default constructor – creates a date object having today’s date
Date(int m, int d, int y)
Overloaded constructor that creates a Date object with the values of
month, day and year corresponding to the passed values of m, d, and y
Date(const string& dateStr)
Overloaded constructor that parses a string in mm/dd/yyyy form and
creates a Date object
void setDate(const Date &d)
Sets the date of current Date object to the date of the passed Date object
void setDate(int m, int d, int y)
Sets the date of the current Date object with the values of month, day
and year corresponding to the passed values of m, d, and y
void setDate(const string&
Sets the date of the current Date object by parsing a string in
Changes the date to the next day
Changes the date to the previous day
Changes the date to the next month
Changes the date to the previous month
Changes the date to the next year
Changes the date to the previous year
Returns the integer value of the month of the date
Returns the integer value of the day of the date
Returns the integer value of the year of the date
Returns a formatted string (mm/dd/yyyy) of the date object
Date operator+= (int n)
Adds ‘n’ days to current date
Date operator-= (int n)
Subtracts ‘n’ days to current date
Date operator+(int n)
Adds ‘n’ days to current date and returns the value
Date operator-(int n)
Subtracts ‘n’ days from current date and returns the value
int operator-(const Date& d)
Finds the difference between two dates (overloaded operator)
Pre- and Post-increment
Pre- and Post-decrement
bool operator==(const Date& d)
Compares date to d. If the two dates are equal, returns true, else returns
bool operator!=(const Date& d)
Compares date to d. If the two dates are not equal, returns true, else
bool operator< (const Date& d)
Compares date to d. If date < d, returns true, else returns false
bool operator<=(const Date& d)
Compares date to d. If date <= d, returns true, else returns false
bool operator> (const Date& d)
Compares date to d. If date > d, returns true, else returns false
bool operator>=(const Date& d)
Compares date to d. If date >= d, returns true, else returns false
Note on using overloaded operators: In the above class description you see that several operators have been overloaded for the class; for example “operator==” has been defined. You can use these like any other method of the class; for
However, it is much easier to simply use them as the operators you know and love; for example: d1==d2.
As the Reminder class is derived from the Date class, all the functions in the Date class can also be used with the Reminder class. There are a few added functionalities, as described below:
Default constructor – creates a Reminder object having today’s date
and an empty string
Reminder(const Date& d,
Overloaded constructor that creates a Date object with d as the date
const string& str)
and str as the message
void setMsg (const string& msgStr)
Sets the message of the reminder to the string msgStr that was passed
in the argument
Returns the message of the reminder in form of a string
Returns the date of the reminder in form of a date object
Returns the reminder in form of a formatted string:
On mm/dd/yyyy: Message
(Where mm/dd/yyyy is the formatted date, and Message is the string
message of the reminder)
Reminder operator+(int n)
Adds ‘n’ days to current reminder and returns the value
Reminder operator-(int n)
Subtracts ‘n’ days from current reminder
bool operator==(const Reminder& r)
Compares two reminders by comparing their dates and messages.
Note that the Reminder class has a getDate() method that returns the date of the reminder. However you should rarely need to use it. Because the Reminder class is derived from the Date class, every Reminder object is also a Date object and can be treated as a Date object (ah, the beauty of inheritance and polymorphism). So when you want to compare the dates of two Reminders, you do not need to extract the dates first before comparing, rather you can use the relational operators to directly compare the two Reminders. This works when comparing Reminders with the relational operators (< , <= , >, >=). Note that the Reminder class overrides the equality operator == so that when two Reminders are compared the date and the message of the two Reminders are compared. But using the == operator between a Reminder object and a Date object will only compare the dates.
Many of the methods of the Date and Reminder classes are declared to be const methods; indicating that they do not modify the object on which they are called. Both the Date and Reminder classes have overloaded insertion operators so that the objects can easily be displayed with the << insertion operator.
You should NOT make any changes to the Date or Reminder classes.
Submission for grading: When you have completed your work on this assignment, please submit your CalTest.cpp file for grading, as that is the only file you should have changed while working on this assignment. Submit ONLY the single source file – please do not submit a zip file containing your entire project, and do not submit the other Calendar/Reminder/Date files. You can submit the files by visiting the assignment page in Brightspace (click on the assignment name), scroll down to the “Submit Files” section, and add the file by clicking on the “Add a file” button and finding the file to attach.
Grading: This project is worth 25 points (half of a normal assignment). Your grade on this project will be based on the thoroughness of your testing of the Calendar class performed by your CalTest.cpp file.
You should also review the syllabus regarding the penalties for late programming assignments.
Opening a CLion project:
1. Unzip the provided zip file; use the one appropriate for your platform. This will create a folder named project0-Windows or project0-MacOS that contains a set of files.
3. From the CLion welcome screen, select “Open Project”
4. Navigate to the project0-Windows or project0-MacOS folder that you unzipped in step 1. Select the folder and press OK.
5. At this point, CLion will open up and display to you the CalTest.cpp file. At the bottom of the screen you will see status messages as it loads necessary symbols, etc. When the status messages stop, it should look something like this:
6. You now should be able to build the project and run it.
本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝或者Upwork交易！
E-mail:email@example.com 微信：BadGeniuscs 工作时间：无休息工作日-早上8点到凌晨3点
• Date.h: declaration of the Date class (do not change) • Date.cpp: definition of the Date class (do not change) • Reminder.h: declaration of the Reminder class (do not change) • Reminder.cpp: definition of the Reminder class (do