ENB241 Programming Portfolio 1
This portfolio submission consists of the following 2 items:
- Part 1 ‐ Workbook (3 marks)
- Part 2 ‐ DateTime class implementation & testing (12 marks)
The description and requirements of each task are detailed over the following pages.Part 1 – Workbook
In the Workbook submission, you will choose ONE exercise which you have completed during the first 5 weeks of the semester and (retrospectively) provide some brief commentary on the learning outcomes you achieved from this exercise. This exercise can be:
- one of the computer laboratory exercises you have covered with your tutor;
- an exercise you covered in the lecture and later worked through in your own time;
- or any other related exercise you have completed related to ENB241.
It is important, however, that you choose an exercise which was significant for you (i.e. an exercise where you learnt something important related to C++ or object‐oriented programming).
The reflective comments provided in this Workbook Submission will be reviewed and marked as “satisfactory” or “unsatisfactory”. This workbook submission is worth 3% out of the total of 15% for this portfolio submission. Satisfactory submissions will receive full marks for this 3%. Unsatisfactory submissions will receive no marks for this 3%.
In order for this Workbook Submission to be considered satisfactory, the following elements must be present:
- Summary of activities undertaken in the exercise (compulsory)
- Commentary on activities including comments on some or all of the following:
o Overallsuccess
o Presenthurdles/limitations
o Actiontobetaken/Questionstobeinvestigated o Keylearningachieved(compulsory)
o Openquestionsforfuturepursuit - Plans for the coming weeks (compulsory)
This Workbook Submission can be handwritten if desired, but should be in ink and be clear and legible & then scanned and uploaded to Blackboard as part of your Portfolio submission. An example
of a basic workbook submission (minimum acceptable standard for a satisfactory submission) is provided on the next page.
Portfolio 1 is due on Friday, 27th March, 11pm.
Part 2 – DateTime
Following on from the Date class done as part of your computer lab session in Week 3, you are to implement a Time class, as well as a DateTime class. You are also to provide a test driver to verify your class implementations. Additionally, you will also be required to link your test driver with a provided Time and DateTime implementation in order to identify any errors that are present.
A file package is available to download from Blackboard for you to begin your implementation. You MUST use the files provided. Do not modify the file structure, nor add or remove files. You are only to edit the specified files. Do not modify any other files.
This component of the Portfolio is worth 12% out of a total 15% for the submission.
Date class
A modified version of the Date class from the computer lab has been provided. This class will be included as a member variable of your DateTime class, providing date functionality for it. A complete test driver has also been provided which performs testing on the Date class. You are free to use the provided code as a reference point to guide your development of the Time and DateTime class.
Certain assumptions have been made in the implementation of the Date class:
- All dates follow the Gregorian calendar, even for dates before the calendar’s invention.
- Dates are only valid since 1st of January, 1AD.
- Textural representation of the date is given in YYYY/MM/DD format (1/01/01, 2014/5/2). These assumptions carry on to your implementation of the DateTime class.
Time class (4 marks)
You are to implement a simple Time class to represent time in a day as hours, minutes and seconds. The time is internally stored in 24‐hour time, though it will provide interfaces for 12‐hour (AM/PM) format.
The time is represented in HH:MM:SS format, with values ranging from 00:00:00 (midnight) to 23:59:59. 12‐hour notation is also to use HH:MM:SS format flowed by AM or PM in upper case letters, with values ranging from 01:00:00 to 12:59:59 (AM or PM).
The definition of this class is provided for you in time1.h, which you must use. time1.h is used as time.h is an existing C header file. time.cpp contains blank implementations of the member functions. You are to edit this file to complete the following functions to the listed specifications:
Time::Time()
Constructs the object to the current time.
- Time::Time(const unsigned int h, const unsigned int m, const unsigned int s)
Constructs the object to the specified time. Invalid time values are to be set to 0.
- Time::Time(const string& timeString)
Constructs the object to the time specified in timeString. Invalid time values are to be set to 0. The time must be 24‐hour time and formatted as HH:MM:SS. - string Time::toString() const
Returns a string of the time formatted in HH:MM:SS 24‐hour time. - string Time::toString12() const
Returns a string of the time formatted in HH:MM:SS XM, where X is either ‘A’ or ‘P’, eg. “12:34:56 PM”. - int Time::compare(const Time& otherTime) const
Compares the object with otherTime. Returns a positive value if the object comes after the other time (ie. *this > otherTime), and negative if it comes before. Returns 0 if the times are equivalent. - int Time::calcSeconds(const Time& otherTime) const
Calculates and returns the number of seconds between the object and otherTime
(ie. *this – otherTime). A positive value indicates that the object comes after otherTime, while a negative value indicates it comes before. - int Time::increment(const int n)
Increments the object by n seconds. The number of seconds incremented can be positive or negative. The function also returns the number of days that have been rolled over. eg. If it is currently 01:00:00, and the time is incremented by ‐7200 seconds (‐2 hours), the new time will be 23:00:00 and the function will return ‐1. - void Time::setTime(const unsigned int h, const unsigned int m, const unsigned int s)
Sets the object to the time specified. Sets invalid time values to 0. The function is declared private and can not be used outside of the class. This function has already been implemented for you.Each function is worth 0.4 marks. Marks are only allocated for a complete and correct implementation of a function. No part marks will be given. The exceptions are for Time::setTime which is worth 0 as it has already been provided for you, and Time::increment, which is worth up to 1.2 marks; 0.4 for correct increment of positive number of seconds, 0.4 for correct increment of negative number of seconds, and 0.4 for correct return value given both positive and negative inputs.
The Time class implementation is worth a total of 4 marks.
DateTime class (4 marks)
The DateTime class uses the implementation of the Date and Time classes to represent the date and time. The DateTime class contains a Date class as a data member, as well as a Time class.
The definition of this class is provided for you in datetime.h, which you must use. datetime.cpp contains blank implementations of the member functions. You are to edit this file to complete the following functions to the listed specifications:
- DateTime::DateTime()
Constructs the object to the current date and time. - DateTime::DateTime(const Date& date, const Time& time) Constructs the object using the given date and time.
- DateTime::DateTime(const string& timeString)
Constructs the object to the time and date specified in timeString. The time must be 24‐hour time and formatted as YYYY/MM/DD HH:MM:SS. - string DateTime::toString() const
Returns a string of the date and time formatted in YYYY/MM/DD HH:MM:SS. The time is to be given in 24‐hour time. - string DateTime::toString12() const
Returns a string of the date and time formatted in YYYY/MM/DD HH:MM:SS XM, where X is either ‘A’ or ‘P’, eg. “12:34:56 PM”. - int DateTime::compare(const DateTime& otherTime) const
Compares the object with otherTime. Returns a positive value if the object comes after the other time (ie. *this > otherTime), and negative it comes before. Returns 0 if the times are equivalent. - int DateTime::calcSeconds(const DateTime& otherTime) const
Calculates and returns the number of seconds between the object and otherTime
(ie. *this – otherTime). A positive value indicates that the object comes after otherTime, while a negative value indicates it comes before. - int DateTime::calcDays(const DateTime& otherTime) const
Calculates and returns the number of days between the object and otherTime
(ie. *this – otherTime). A positive value indicates that the object comes after otherTime, while a negative value indicates it comes before. Only full days are counted. - void DateTime::increment(const int n)
Increments the object by n seconds. The number of seconds incremented can be positive or negative. The date of the object can be changed. - void DateTime::incrementDays(const int n)
Increments the object by n days. The number of days incremented can be positive or negative.Each function is worth 0.4 marks. Marks are only allocated for a complete and correct implementation of a function. No part marks will be given. The DateTime class implementation is worth a total of 4 marks.
Testing (4 marks)
You are to write a test driver which tests all 18 of the above functions in Time and DateTime (excluding Time::setTime). The program is to clearly list the inputs, initial state, outputs and resulting state, as well as the expected output and state of each test case, similar to the provided Date test driver, or the one shown in the computer labs. Each test case should be marked with the result of the test (pass or fail). You can use these examples as a base to develop your own test driver.
The test driver is to help ensure that your function implementations are correct. It is recommended that you develop your test driver before or concurrently with the implementation of the functions.
Additionally, you are to link your test driver against a provided object file (instructions given below). This file (badlib.o) contains a complete implementation of the Time and DateTime classes, however, with deliberate errors introduced. The errors are typical to those of common coding errors and basic algorithmic errors, and are not purposely convolutedly designed. If designed correctly, your test driver will show which functions in the provided object file are implemented correctly and which contains errors.
Fill out the test report provided (test_report.txt) by indicating which functions (both your own implementation, as well as the provided one) contain errors. Mark erroneous functions with an ‘x’.
Your test driver will be marked based on the quality of your test cases, as well as its ability to successfully detect any errors in your own implementation and errors in the provided object file. This testing component is worth a total of 4 marks.
Instructions
Download datetime.zip from Blackboard and extract these files to BEESHELL01. The files are organised in the following structure:
.
|‐‐ include
- | |‐‐ date.h
-
| |‐‐ datetime.h
-
| `‐‐ time1.h |‐‐ makefile |‐‐ obj |‐‐ src
-
| |‐‐ date.cpp
-
| |‐‐ testdate.cpp
-
| |‐‐ datetime.cpp
-
| |‐‐ testdriver.cpp
-
| |‐‐ time.cpp
-
| `‐‐ verification.cpp `‐‐ test_report.txt
You are to edit time.cpp, datetime.cpp, testdriver.cpp, and test_report.txt only. All other files must not be modified.
-
Instructions on editing these files are as follows:
time.cpp
datetime.cpp testdriver.cpp
test_report.txt
A starting template with blank implementations of all the functions have been provided to you. You are allowed to modify this file as you wish, including adding extra helper functions that you may deem necessary (the header file is not to be edited). However, do not remove any of the functions, even ones that are left blank. This is to ensure that your code successfully links against other test drivers. The makefile is designed to throw an error if any functions are removed.
Same as time.cpp.
Implement your test driver here. You are allowed to modify this file as you wish. Consider using testdate.cpp or the test driver given in the computer labs as a guide.
Summarise the results of your test driver in this file. Indicate erroneous functions with an ‘x’.
You will be provided with a compiled implementation of Time and DateTime (badlib.o). This file is not included in datetime.zip and instructions on how to obtain this file will be given separately. Once you have the file, copy it to the root directory for this project so that the file structure now looks like:
.
|‐‐ badlib.o |‐‐ include
- | |‐‐ date.h
-
| |‐‐ datetime.h
-
| `‐‐ time1.h |‐‐ makefile |‐‐ obj |‐‐ src
-
| |‐‐ date.cpp
-
| |‐‐ testdate.cpp
-
| |‐‐ datetime.cpp
-
| |‐‐ testdriver.cpp
-
| |‐‐ time.cpp
-
| `‐‐ verification.cpp `‐‐ test_report.txt
A makefile has been provided for you. The file contains the instructions for you to compile and run the various required components. The following make instructions can be executed from the command line:
make or make all
This will build the Date test driver as well as your test driver, producing testdate and testdriver. Verification tests will be performed to ensure that no functions are missing from time.cpp and datetime.cpp.
-
make testbad
This will build your test driver, linking it against badlib.o, creating testbad. This will require badlib.o to be present in the correct location.
make runtest
This will build your test driver (if necessary) and run testdriver. This should be your go‐to command when coding your assessment.
make runbad
This will build your test driver (linked with badlib.o) and run testbad.
make clean
Deletes all generated files (.o files under obj/ and executables) and restores your file structure to a ‘clean’ state.
The make process will generate the following files:
testdate testdriver testbad verification
Submission
Date class test driver
Your test driver (Time and DateTime classes) Your test driver (linked against badlib.o) Stub program to ensure correct linking.
Ensure that your program compiles on BEESHELL01. Code that does not compile will automatically lose 50% of the marks achieved for this assessment.
The quality of the code you submit will also be marked. Ensure that your code is clearly formatted and well commented. Use meaningful names for your functions and variables, while maintaining a consistent naming scheme. Poor quality code (very little formatting with no comments) will result in a loss of up to 50% of the marks achieved for this assessment.
You are to submit your portfolio via Blackboard as a single zip file. The contents of this zip file should be arranged in the following structure.
username.zip |‐‐ datetime
| |‐‐ include
- | |
- | |
- | |
-
| |‐‐ makefile
- | |‐‐ obj
|‐‐ date.h |‐‐ datetime.h `‐‐ time1.h
- | |‐‐ src
-
| | |‐‐ date.cpp
-
| | |‐‐ testdate.cpp
- | | |‐‐ datetime.cpp
- | |
- | |
- | |
- | `‐‐ test_report.txt
`‐‐ workbook.pdf (or .jpg, .png, etc…)
|‐‐ testdriver.cpp |‐‐ time.cpp
`‐‐ verification.cpp
Your workbook exercise should be a single PDF file or one (or more) image files placed in the root of your submission file. Please do not submit word documents but instead export it as a PDF file. If you are scanning a written document, ensure that your text can clearly be read, while limiting the size of the files so that they are not excessive.
The files for your Time/DateTime class should be placed in their own directory in your submission file. Ensure all the necessary files are included, along with corresponding makefiles, so the exercises can be built as is with the make command.
It is recommended that you submit your assignment well before the submission deadline as the submission link will automatically close on the specified time. Failure to submit before the due date without an approved extension will result in 0 marks awarded for this assignment. If special circumstances prevent you from meeting the assessment due date, you can apply for an extension. If you don’t have an approved extension you should submit the work you have completed by the due date and it will be marked against the assessment criteria.
This is an individual assessment. All submissions are to be of your own work. Portfolio 1 is due on Friday, 27th March, at 11pm.