Description
You are going to become a junior student next semester and you expect your workload to be high as you plan to take some upper level technical electives. To better organize the tasks in all your future courses, you decide to use the skills you learned in VE280 and plan to write a program that can store, update and print all unfinished tasks in a course. Before starting to code, you need to choose a representation for tasks and courses.
For implementation details, please refer to the exercises below.
Ex.1
Related Topics: virtual function, interface
First of all, in order to hide all implementation details, you decide to realize the ADT Course as a homonym virtual base class in course.h . Regarding the implementation of this base class, you decide that the unfinished tasks are managed with an array tasks .
The three operations of this ADT are defined as follows in the base class:
1 void updateTask(const std::string &type, int index, int dueMonth, int dueDay);
2 // REQUIRES: dueMonth and dueDay are in normal range.
3 // MODIFIES: this 4 // EFFECTS: adds/updates Task index of type; throw exception if fails to add Task
5 void finishTask(const std::string &type, int index, int finishMonth, int finishDay);
6 // REQUIRES: Task index of type exists in tasks. finishMonth and finishDay are in normal range.
7 // MODIFIES: this 8 // EFFECTS: removes Task index of type
9 void print();
10 // EFFECTS: prints all unfinished tasks of this Course
print will print the course code and all elements in tasks in order. The implementation of print is already given to you, please do not modify it.
This ADT is implemented as a derived class TechnicalCourse in course.cpp . It has four protected data members:
1 Task *tasks; // Array of current unfinished tasks 2 int sizeTasks; // Maximum number of unfinished tasks in the array 3 int numTasks; // Number of current unfinished tasks in the array 4 std::string courseCode; // Course code, e.g. “VE280”
This derived class represents courses like VE280, which require to submit labs/projects via the online judgement system and submit other work via canvas.
When you create a new TechnicalCourse , numTasks should be initialized to 0, courseCode should be initialized according to the input. If the input argument size is specified, sizeTasks should be initialized as size ; otherwise, it should be initialized as the default value MAXTASKS , which is 4.
1 TechnicalCourse(const std::string &courseCode, int size = MAXTASKS);
As for the three methods:
updateTask takes the type , the index , the dueMonth and the dueDay of the task to be
updated as inputs. If the task already exists in the array tasks , you should update its dueMonth and dueDay . If it is a new task, inserts it at the end of tasks and throws an
exception of type tooManyTasks if tasks is full.
After inserting tasks whose type is “Lab” or “Project”, you need to print a message:
1 <courseCode> <type> <index> is released! Submit it via oj!
After inserting tasks of type other than “Lab” and “Project”, you need to print another message:
Example:
1 // ve281 is a pointer to an instance of TechnicalCourse with courseCode “VE281”
2 ve281->updateTask(“Assignment”, 1, 5, 10); 3 ve281->updateTask(“Lab”, 1, 5, 20); 4 ve281->updateTask(“Project”, 1, 5, 30);
5 ve281->updateTask(“Lab”, 1, 5, 15); // no message is printed since it already exists in tasks
Example:
Example output:
Ex.2
Related Topics: subclass, inheritance, virtual function
You will start to take upper level technical courses next semester. UpperLevelTechnicalCourse inherits from TechnicalCourse , while there are two differences between them.
First, there is a new type of tasks, “Team Project”. For this type of tasks, you need to cooperate with your teammates and share the codes through GitHub. So after inserting tasks of “Team Project”, a message should be printed:
Example:
Example output:
Testing
Since more than one instance of the class is needed, a function, with overload, is provided to create them dynamically:
1 Course *create(const std::string &classType, const std::string &courseCode); 2 Course *create(const std::string &classType, const std::string &courseCode, int taskSize);
classType could be either “Technical” or “Upper Level Technical”. courseCode specifies the
course code of the course you want to create. If classType is “Technical”, then it returns a pointer to an instance of TechnicalCourse with courseCode ; if classType is “Upper Level
Technical”, then it returns a pointer to an instance of UpperLevelTechnicalCourse with courseCode ; if classType is not “Technical” or “Upper Level Technical”, it returns a null pointer.
Besides, if taskSize is true, the maximum number of tasks in this course at a time is specified by taskSize ; otherwise, the maximum number of tasks is the default value MAXTASKS .
Example:
Example output:
This simpletest.cpp is just an example and you still need to write test cases yourself to get full scores.
Please make sure there is no memory leak!
You can use valgrind –leak-check=full ./lab7 to run the program and check memory leaks.
Or you can add -fsanitize=leak -fsanitize=address when compiling the program.
Submitting
You can find course.h and course.cpp in lab7Starter_files.zip . Please implement all the methods needed, compress these two files into a zip file and submit to JOJ.
Created by Yaxin Chen.
Modified by Jiayao Wu.
@UM-SJTU Joint Institute
Reviews
There are no reviews yet.