Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need c++ format c - string problems need both .h and .cpp Wrap a C-Style String Now that you have seen what we can do

need c++ format

c - string problems

need both .h and .cpp

image text in transcribed

Wrap a C-Style String Now that you have seen what we can do by creating a relatively thin object wrapper around a raw C++ array, apply that to create a safer [if not "friendlier] version of a character string. Create the header file StringWrapper.h and implementation file StringWrapper.cpp. You will be defining a class Stringwrapper using the techniques you've just applied, but with a raw character array (C-Style string) as the underlying storage unit instead of an integer array. Your library should meet the following requirements: Add code to your main program to test the functionality of StringWrapper as you go. Remember: Compile and test often! Allow the underlying maximum capacity to be 1048576 bytes (IMiB in bytes 10242 bytes]. Since 1 char is 1 byte, the maximum capacity is exactly 1048576 characters. Use a const static attribute for this as you did for the ArrayWrapper earlier There is no need to also store a "logical size" attribute like we did with the integer array. The storage will be a valid C-Style string [null-terminated]. so it we can use functions intended for C-Strings with it. The constructor should take a const-qualified C-Style string as its argument. Use the strncpy) function from the library to copy it into the underlying storage Be sure to manually null-terminate the attribute after you copy to assure that it is a valid C-String (in case the parameter contained a much larger string]. The get () and set () methods work similarly to the ones you wrote above- they will allow the user to read/write individual characters in the string. Use the strlen() function to verify that the index they supply is not outside the logical bounds of the underlying string. Throw a std::out_of_range exactly as we did in the ArrayWrapper class if the index is invalid. Add a write() method matching the prototype shown below. The write method will take an output stream as an (optional) parameter and write the string into that stream. If no argument is given, the stream parameter will default to std::cout. Add a readline() method matching the prototype shown below. The first parameter is an input stream [defaulting to std: :cin) and the second parameter is a delimiter (defaulting to the newline!. The method will use the .getline) method belonging to the input stream to read from that stream and store the resulting input in the underlying C-string attribute. Be sure to control the maximum size correctly to prevent overflowing the underlying storage. Prototypes for write() and readline (): write(): void write(std : :ostream& strm=std ::cout) const; readline() void readline (std::istream& strm std::cin, char delim- Be sure you have tested your code thoroughly and reviewed the Grading Guidelines before you submit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago