Write a program in C++ that defines a class named StringOps. Declare data members of this class as described below: • variable str of data type string. • variable size of data type integer which represents the length of the string str. Define member functions in StringOps as given below: parameterless and parameterized constructors that initialize the string variable str. void input () : This function accepts a string as input from the user and stores it in str. The length of this string is computed and stored in the variable size. • Overload operator + to create a new string obtained by concatenation of two StringOps class objects. The size of this new string should be appropriately set. Overload operator[] to return the character present at the specific index of the string variable str. The index specified begins from 1 and can range upto size. Index can also receive a negative value in which case -1 means the last character of the string variable str. The range in the negative side would be from -1 to -size. For example, if str = "hello"; then index 1 would correspond to character 'h'; index = -1 would correspond to character 'o', index = -2 for character '1' and so on. Zero index would stand invalid. • int findMatch (char set[0): This function searches the characters from the array set in the string str and returns the sum of frequency of matched characters in str. For example, if str "C++ programming" and set ('p', 'm', '+', 'h'}, then the value returned is 1+2+2 5. • void display () : This function should display the string object str and its size.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Write a program in C++ that defines a class named StringOps. Declare data members of
this class as described below:
variable str of data type string.
• variable size of data type integer which represents the length of the string str.
Define member functions in StringOps as given below:
parameterless and parameterized constructors that initialize the string variable str.
• void input () : This function accepts a string as input from the user and stores it in
str. The length of this string is computed and stored in the variable size.
• Overload operator + to create a new string obtained by concatenation of two
StringOps class objects. The size of this new string should be appropriately set.
• Overload operator[] to return the character present at the specific index of the string
variable str. The index specified begins from 1 and can range upto size. Index can
also receive a negative value in which case -1 means the last character of the string
variable str. The range in the negative side would be from -1 to -size. For example,
if str = "hello"; then index = 1 would correspond to character 'h'; index -1
would correspond to character 'o', index = -2 for character '1' and so on. Zero index
would stand invalid.
int findMatch (char set[]): This function searches the characters from the
array set in the string str and returns the sum of frequency of matched characters in
str. For example, if str = "C++ programming" and set = ('p', 'm',
'+', 'h'}, then the value returned is 1+2+2 = 5.
void display (): This function should display the string object str and its size.
Transcribed Image Text:Write a program in C++ that defines a class named StringOps. Declare data members of this class as described below: variable str of data type string. • variable size of data type integer which represents the length of the string str. Define member functions in StringOps as given below: parameterless and parameterized constructors that initialize the string variable str. • void input () : This function accepts a string as input from the user and stores it in str. The length of this string is computed and stored in the variable size. • Overload operator + to create a new string obtained by concatenation of two StringOps class objects. The size of this new string should be appropriately set. • Overload operator[] to return the character present at the specific index of the string variable str. The index specified begins from 1 and can range upto size. Index can also receive a negative value in which case -1 means the last character of the string variable str. The range in the negative side would be from -1 to -size. For example, if str = "hello"; then index = 1 would correspond to character 'h'; index -1 would correspond to character 'o', index = -2 for character '1' and so on. Zero index would stand invalid. int findMatch (char set[]): This function searches the characters from the array set in the string str and returns the sum of frequency of matched characters in str. For example, if str = "C++ programming" and set = ('p', 'm', '+', 'h'}, then the value returned is 1+2+2 = 5. void display (): This function should display the string object str and its size.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education