7 Define a class String that could work as a user-defined string type. Include constructors that will enable us to create an uninitialized string: String s1; // string with length 0 And also initialize an object with a string constant at the time of creation like String s2("Well done!"); Include a function that adds two strings to make a third string. Note that the statement S2 = s1; will be perfectly reasonable expression to copy one string to another. Write a complete program to test your class to see that it does the following tasks: \(a\) Creates uninitialized string objects. \(b\) Creates objects with string constants. \(c\) Concatenates two strings properly. \(d\) Displays a desired string object.
Added by Steven K.
Close
Step 1
We will include private data members to hold the string and its length, and public member functions to perform the required operations. ```cpp #include <iostream> #include <cstring> class String { private: char* str; int len; public: // Default Show more…
Show all steps
Your feedback will help us improve your experience
Richelle Chappell and 95 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a c++ program to define a class member having data X & Y & perform mathematical operations like addition subtraction division multiplication on two numbers using constructor and destructor function
James K.
Create a class named 'Programming'. While creating an object of the class, if nothing is passed to it, then the message "I love programming languages" should be printed. If some String is passed to it, then in place of "programming languages," the name of that String variable should be printed. For example, while creating the object if we pass "cpp," then "I love cpp" should be printed.
Patricia H.
Write a program that asks the user to enter a string. The program should create a new string called new_string from the user's string such that the second character is changed to an asterisk and three exclamation points are attached to the end of the string. Finally, print new_string. Typical output is shown below: Enter your string: Qbert Q*ert!!!
Liam H.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD