COMP2710: Homework 2 solved

$25.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (2 votes)

Goals: • To learn how to define and implement a derived class with public inheritance • To learn creating multiple versions via conditional compilation • To use dynamic array • To learn basic operator overloading • To perform unit testing Description 1. Create a class named Doctor that has three member variables: • name – A string that stores the name of the doctor • numPatients – An integer that tracks how many patients the doctor must treat • patientList – A dynamic array of strings used to store the patient names Write appropriate constructor(s), mutator, and accessor methods for the Doctor class along with the following: • A method that inputs all values from the user, including the list of patient names. Note that this method has to support input for an arbitrary number of patient. • A method that outputs the names in the list of all patients. • A method that resets the number of patient to 0 and the patientList to an empty list. • An overloaded assignment operator that correctly makes a new copy of a Doctor object with the list of patients. • A destructor that releases all memory that has been allocated. 2. Create a class named HeartSurgeon that is derived from the Doctor class with public inheritance. In addition to the variables it inherits from the Doctor class, it also has the following variables: • numSurgeriesScheduled – An integer that tracks how many heart surgeries the doctor is scheduled • surgerySchedule – A dynamic array of objects used to store the patient names and the dates of the heart surgery. Define the appropriate new class for surgerySchedule objects. 2 Write appropriate constructor(s), mutator, and accessor methods for the HeartSurgeon class along with the following: • A method that inputs all values from the user, including the list of patient names and surgery schedules. Note that this method has to support input for an arbitrary number of patients and surgeries. • A method that outputs the names in the list of all patients and surgeries scheduled. • A method that resets the number of patient to 0 and the patientList to an empty list. • A method that resets the number of surgery scheduled to 0 and the surgerySchedule to an empty list. • An overloaded assignment operator that correctly makes a new copy of a HeartSurgeon object with the list of patients and the list of surgeries scheduled. • A destructor that releases all memory that has been allocated. Write a main method that tests (i.e., unit testing) all of your functions in both the Doctor and HeartSurgeon classes. Requirements: 1. Use comments to provide a heading at the top of your code containing your name, Auburn Userid, filename, and how to compile your code. Also describe any help or sources that you used (as per the syllabus). 2. Your source code file should be named as “_hw2.cpp”. 3. Your program must use dynamic arrays 4. Your program must use strings 5. Methods that input all values from the user 6. Methods that output the name and list of all patients and surgeries scheduled. 7. A method that reset the number of patient to 0 and the patientList to an empty list. 8. A method that reset the number of surgeries scheduled to 0 and the surgerySchedule to an empty list. 9. Overloaded assignment operators 10. Destructors 11. Correctly implement the main function (i.e., unit testing). 12. Creating two versions using conditional compilation. 13. You must limit the number of global variables and data 14. Usability of your program (e.g., user interface) 15. Readability of your source code. Note: You will lose points if there are compilation errors or warning messages when the TA compiles your source code. You will lose points if you: do not use the specific 3 program file name, or do not have a comment on each function in your program you hand in. How to Create Two Versions? You can use the preprocessor directive #ifdef to create and maintain two versions (i.e., a debugging version and a product version) in your program. If you have the sequence #ifdef UNIT_TESTING add your unit testing code here #else add your code for the product version here #endif in your program, the code that is compiled depends on whether a preprocessor macro by that name is defined or not. For example, if there has been a “#define UNIT_TESTING” macro line), then “ add your unit testing code here ” is compiled and “ add your code for the product version here ” is ignored. If the macro is not defined, “ add your code for the product version here ” is compiled and “ add your unit testing code here ” is ignored. These macros look a lot like if statements, but macros behave completely differently. More specifically, an “if” statement decides which statements of your program must be executed at run time; #ifdef controls which lines of code in your program are actually compiled. Unit Testing: Unit testing is a way of determining if an individual function or class works. You need to isolate a single function or class and test only that function or class. For each function in this homework, you need to check normal cases and boundary cases. Examples for tested values: • string – empty string, medium length, very long • Array – empty array, first element, last element • Int – zero, mid-value, high-value You must implement a unit test driver for each function implemented in your program. You may also use assert() to develop your unit test drivers if tested results are predictable. Programming Environment: Write a short program in C++. Compile and run it using the g++ compiler on a Linux box (either in computer labs in Shelby or through remote access, your home Linux machine, a Linux box on a virtual machine, or using an emulator like Cygwin), but your final 4 program must compile correctly and execute correctly in the Linux tux computers in Shelby 2125 or through remote access. Deliverables: • Submit your source code file named as “_hw2.cpp” through the Canvas system. Late Submission Penalty: • Twenty percent (20%) penalty per day for late submission. For example, an assignment submitted after the deadline but up to 1 day (24 hours) late can achieve a maximum of 80% of points allocated for the assignment. An assignment submitted after the deadline but up to 2 days (48 hours) late can achieve a maximum of 60% of points allocated for the assignment. • Assignment submitted more than 3 days (72 hours) after the deadline will not be graded.