Create a user-defined Abstract Data Type (ADT) that implements a character string using a C++ class named String along with an appropriate set of C++ header/implementation files as discussed in class. The String ADT is managed using one class attribute:

A pointer to a dynamic array of characters

  • Allocates the exact amount of storage for the current value
    • Allocated space needs to be updated as the value length changes
  • The actual array length is the string length + 1
    • The length of the string value is stored in position 0

The string values are NOT NULL TERMINATED - they are NOT C-style strings

The String ADT must define and implement the following data types and operations.

  • Do not add any additional data types or operations
  • Do not modify any of the defined data types or operations.

String Exportable Operations: (declared .h file and defined .cpp file)

explicit String: default/overloaded/parameterized/converting constructor function
( const char * = "" )

String: copy constructor function – makes an exact copy of an existing instance
( const String & ) // reuse: =

~String: destructor function – destroys the invoking instance

getLength: returns the number of characters in the invoking instance – unsigned
explicit inline // no setter

Overloaded Operators: = // test for self-assignment
+ (binary only) // concatenation without assignment
++ (prefix & postfix) // postfix reuse: prefix
// Abc12deF => Bcd23efG
! // uppercase to lowercase
// lowercase to uppercase
// Abc12deF => aBC12DEf

String Non-Exportable Operations: (declared .h file and defined .cpp file)

destroy: deallocates the storage

Non-Member Friend Operations: (declared .h file and defined .cpp file - String class)

Overloaded Operators: < // all
> // reuse: <
== // reuse: < >
-- (prefix & postfix) // postfix reuse: prefix
// Bcd23efG => Abc12deF
<< // insertion
>> // extraction reuse: =

Notes:

  • Operators should affect String instances similar to the way that they affect primitive types
    • e.g., a = ++b + c++;
    • prefix increment modifies b - modified value of b applied to addition
    • postfix increment modifies c - original value of c applied to addition
    • addition does not modify either b or c
    • assignment modifies a
  • Apply PITA everywhere possible.
    • Prefer Initialization To Assignment.
    • Apply to ALL attributes.
  • Apply function Reuse everywhere possible - the emphasis is on code reuse not on code performance
    • getLength should be used everywhere possible
    • apply infix notation when reusing operator functions
  • Apply the const keyword everywhere possible
    • functions - support for methods that do not modify instance state
    • arguments - support for IN ONLY argument usage
  • Use the new operator appropriately
    • Use std::nothrow: Exception Handling is NOT supported
    • Provide appropriate user feedback
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.