Implement the copy constructor for the StringVar class using the options given on the right side window. Place the code into the left side using the arrows. NOTE: Be careful! There are decoys! Assume that StringVar.h has the following declaration: #include class StringVar { public: StringVar() : max_length(20) { // Default constructor size is 20 value = new char[max_length+1]; value[0] = '\0'; } StringVar(int size); // Takes an int for size StringVar(const char cstr[]); // Takes a c-string and copies it StringVar(const StringVar& strObj); // Copy Constructor ~StringVar(); // Destructor int size() const { return max_length; } // Access capacity const char* c_str() const { return value; } // Access value int length() const { return strlen(value); } // Access length StringVar& operator= (const StringVar& rightObj); std::istream& operator>> (std::istream& in, StringVar& strVar); std::ostream& operator<< (std::ostream& out, const StringVar& strVar); private: int max_length; char* value; }; Organize blocks of code:
Implement the copy constructor for the StringVar class using the options given on the right side window. Place the code into the left side using the arrows. NOTE: Be careful! There are decoys!
Assume that StringVar.h has the following declaration:
#include <iostream>
class StringVar {
public:
StringVar() : max_length(20) { // Default constructor size is 20
value = new char[max_length+1];
value[0] = '\0';
}
StringVar(int size); // Takes an int for size
StringVar(const char cstr[]); // Takes a c-string and copies it
StringVar(const StringVar& strObj); // Copy Constructor
~StringVar(); // Destructor
int size() const { return max_length; } // Access capacity
const char* c_str() const { return value; } // Access value
int length() const { return strlen(value); } // Access length
StringVar& operator= (const StringVar& rightObj);
std::istream& operator>> (std::istream& in, StringVar& strVar);
std::ostream& operator<< (std::ostream& out, const StringVar& strVar);
private:
int max_length;
char* value;
};
Organize blocks of code:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps