Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Problem 4 (4 points)  Create a C++ header file problems/problem4

Problem 4 (4 points)  Create a C++ header file problems/problem4

Computer Science

Problem 4 (4 points) 
Create a C++ header file problems/problem4.hpp and a C++ source file problems/problem4.cpp. 
In the header file, you'll write the interface of a class called DynamicPair. In the source file, write the implementation of that class. In deciding what belongs in the header file and what belongs in the source file, differentiate the way we did in the Classes and Well-Behaved Classes examples, with the basic goal being to say as little as possible in the header file while still making it possible to use the class in source files other than problems/problem4.cpp. 
The DynamicPair class should meet the following requirements: 
• A DynamicPair stores two values, one whose type is int and the other whose type is double. Both are (separately) dynamically allocated, rather than being stored in the DynamicPair object directly. • The DynamicPair is thought to own its two dynamically-allocated values; their lifetimes are identical. • The int value will never be positive; any attempt to make it positive should result in its value being 0. • The double value will never be less than 3; any attempt to make it be less than 3 should result in its value being 3. • It should be possible to copy a DynamicPair (e.g., by passing one by value) and that should provide C++'s usual copy semantics, which means that the copy will be separate from the original, so that changes to one will not affect the other. This should be true both for copy initialization and copy assignment. • It should be possible to ask a DynamicPair for its int value or its double value, in which case a copy of the corresponding value is returned. • It should be possible to ask a DynamicPair to change its int value or its double value, given an int or double value to change it to. 
Your implementation should be as simple as possible but no simpler. Only write things that need to be written in order to meet these requirements. We'll be happy to help you to understand these requirements, but we will not be able to answer questions about how to meet them in C++; that's what the question is asking you to consider for yourself. 
What to submit 
One C++ header file named problem4.hpp and one C++ source file named problem4.cpp, which you'll need to create in the problems directory, and which contain your declaration and implementation of the DynamicPair class. 
 

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE