LAB4 (20pts) - The BlogEntry ADT
Purpose: The purpose of this lab is to explore the implementation and applications of a BlogEntryADT, which is built on the Date class and the Text ADT class of Lab3.
This lab is found at pg. 16 in your lab manual, which can be accessed through our Libraries --> Databases --> Safari Tech Books Online -->C++ Data Structures A Laboratory Course
Pre-lab: Implement methods for Date ADT.
- Carefully read pg. 16-23 in your lab manual. `
- Download the starting packet, Lab4.zip, for this lab, and use it to create a BlogEntry CLion project. This folder contains
- config.h - a header file used to turn certain debugging tests on and off
- test2.cpp - the test driver for your implementation of the BlogEntry ADT
- BlogEntry Worksheets.pdf - print this file (if not provided) and provide answers for the testing scenarios in the document. A hard copy of the worksheets must be turned into the TA or instructor.
- BlogEntry.h - starting header file for the BlogEntry ADT. Completing the implementation of BlogEntry.cpp is part of this lab exercise.
- Date.h - starting header file for the Date ADT. Completing the implementation of Date.cpp is the prelab exercise and you should start on this before the lab session.
- Text.h - header file for Text.h from Lab3. Use your own implementation of Text.cpp from Lab3. If you need help fixing this file, ask the instructor or the TA for help.
- show2.cpp - code stubs to display a Date object and a BlogEntry object. Do NOT include this file in your project, just copy and paste its content in approriate files as needed.
Note1: before you implement any method, make sure your project compiles. This might require adding method stubs in the Date.cpp. For example, if in Date.h you have a method "int getAverage();", in Date.cpp you may add something like
int Date::getAverage()
{
return 999;
}
Note2: Document with pre and post conditions all methods you are implementing. As usual, write this documentation first in .cpp, BEFORE you implement the methods, then optionally you may copy the documentation in the .h file. The method descriptions from the lab manual will help you a lot with the documentation.
3. Implement and test the Date ADT, following the steps in the Implementation Notes and Testing sections. Before lab, get through at least Test Plan 3.
Notes:
- Whenever a function’s requirements (preconditions) are not met, the function should throw an exception. If your program doesn’t do this, it will lose points for correctness of output. The error message in the exception should make sense to the user.
- Notice that the showStructure function is provided in show2.cpp.
- For the isLeapYear and daysInMonth functions, the requirement about the year 1901 has to do with Programming Exercise 2, which you won’t be doing. Instead, consider January 1, 1 AD to be the earliest date that a Date object can represent.
- For the isLeapYear function, look up the formula for leap years. It may be trickier than you think.
- To get the current date, use the following code:
#include <ctime>
using namespace std;
...
time_t now = time(NULL);
struct tm *current = localtime(&now);
day = current->tm_mday;
month = current->tm_mon + 1;
year = current->tm_year + 1900; |
- If not having it already, add the following code to the Text class:
// In Text.h, after the other function declarations...
// (See Date.h for an example of where this declaration goes.)
friend ostream & operator<< (ostream& output, const Text& outputText); |
// In Text.cpp...
/* Requirements: The specified output stream must not be in an error
* state (not checked).
* Results: Inserts (outputs) outputText in the specified output stream
* and returns the resulting output stream.
*/
ostream & operator << ( ostream &output, const Text &outputText )
{
output << outputText.buffer;
return output;
} |
Make sure it compiles. Notice that you can use the argument output just like you’d use cout. Use this code as an example when implementing operator<< for the Date class.
- The test plan and test2.cpp are slightly inconsistent. Where they differ, modify the test plan (on paper), not the test2.cpp file. For instance, the test2.cpp output for Test Plan 2-1looks like t1.png. So modify your test plan in your BlogEntry Worksheets.pdf similarly to
Test case---------------------Parameters---------Expected result
Last day of 20th century -----31, 12, 200 ------12/31/2000
Curent date -------------------None-------------9/8/2019
Last leap day-----------------29, 2, 2096-------2/29/2096
- Notice that you have to add your own test inputs to the test plan, in addition to writing in the expected results. Also, checking out the main in your test.2cpp and my own outputs (as .png) for each test case might help you with implementation and testing.
Note: Possible outputs of tests 2-1 up to 2-7 can be found here: t1, t2, t3, t4, t5, t6, t7.
In-lab: Complete your Date class and Test Plans 2-1 through 2-7, and do Analysis Exercise 2.
1. Complete your Date class and Test Plans 2-1 through 2-5. You should do this within the first 1.5 hours of lab. If any test cases for your Date class are not working, ask the instructor for help.
2. Implement the BlogEntry ADT and complete the rest of the test plan up to 2-7. (If helpful to you, check my possible outputs for these tests - they are posted above.)
Notes:
- Notice that the showStructure function is provided in show2.cpp.
- For setAuthor and setContents, one of the results should be that the modification date is updated.
- The getters are boring, so here’s the code:
Text BlogEntry::getAuthor() const {
return author;
}
Text BlogEntry::getContents() const {
return contents;
}
Date BlogEntry::getCreateDate() const {
return created;
}
Date BlogEntry::getModifyDate() const {
return modified;
} |
3. Do Analysis Exercise 2. (Your Blog ADT doesn’t need to be fancy: 2-3 private members and 3-4 public methods are enough. Just provide the basic functionality that anyone using the Blog ADT would require. The Bag.h at pg. 100 from your textbook might help you.)
4. You are recommended to start the post-lab.
Post-lab: Programming Exercise 1
- Do Programming Exercise 1.
- A possible output for this activity is at t8.
On Friday hand your Text Worksheet.pdf to the instructor.
By Wednesday midnight submit your project in the following way:
- Zip your BlogEntrya CLion folder (Control-click on the folder and select Compress).
- Use the link Lab4 to upload it on woodle. (Note: if link does not seem to work, try "Right-Click" and "Open-in-New-Window".)
Grading:
- Text Worksheet.pdf: 5pts (2 pts the tests and 3 pts the Analysis Exercise 2)
- Date.cpp: 5pts (correctnes of methods; have pre and post; throw execptions when needed)
- BlogEntry.cpp: 5pts (correctnes of methods; have pre and post)
- Programming Exercise 1: 5pts