Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writingthis code in c++, please use alot of comments so i can understand better. Thank you. In this assignment you will implement

I need help writingthis code in c++, please use alot of comments so i can understand better. Thank you.

In this assignment you will implement a class called string_class. Place the class declaration in the file string_class.h and the class implementation in the file string_class.cpp. The class has the following characteristics

  1. A private string variable current_string.
  2. A default constructor that sets current_string to an empty string ().
  3. An explicit-value constructor that sets current_string equal to the argument that is passed to the explicit-value constructor when a string_class object is declared.
  4. A public member Boolean function called palindromethat returns true if the current_string reads the same forward as it does backwards; otherwise it return false. For example madam, 463364,and ABLEWASI ERE I SAWELBA are all palindromes.
  5. A public member void function called replace_all that accepts two string arguments, old_substring and new_substring. The function will replace each occurrence of old_substring with new_substring in

current_string. For example, when the function is invoked, if current_string = aaabbacceeaaa, old_substring= aa, and new_substring= zzz,then after execution of the function, current_string = zzzabbacceezzza. Note special cases: If current_string is empty, or if old_substring is larger than current_string, or if old_substring is not located in current_string, then the value of current_string will not change. DO NOT USETHE STRING CLASS FUNCTIONS find, replace,or substr.

  1. Overload the insertion operator (<<) as a friend function of the class with chaining to print the contents of a string_class objects current_string.
  2. You may implement other class member functions if necessary.

Call the driver to test the functionality of string_class, stringclass_driver.cpp. You should submit the files string_class.h, string_class.cpp, and stringclass_driver.cpp

See the sample main program below

sample_main_program(driver)_for_stringclass:

#include

#include

#include #include "string_class.h" using namespace std;

int main()

{

/*string_class s;

cout << "****************************************" << endl

<< "Test#1: tesing default constructor and overloaded operator<< with chaining "

<< s << "1st blank line" << endl << s << "2nd blank line" << endl

<< "Test#1 Ended" << endl

<< "****************************************" << endl; string_class r("hello");

cout << "****************************************" << endl

<< "Test#2: tesing explicit-value constructor and overloaded operator<< with

chaining "

<< r << endl << "1st blank line" << endl << r <

<< "Test#2 Ended" << endl

<< "****************************************" << endl; cout << "****************************************" << endl

<< "Test#3: tesing palindrome "

<< "****************************************" << endl; string response = "Y"; string ss;

while (response == "Y" || response == "y")

{ cout << "Enter String: "; getline(cin, ss); string_class main_string(ss);

if (main_string.palindrome())

{

cout << ss << " is a palindrome ";

} else

{

cout << ss << " is not a palindrome ";

} cout << "Would you like to try another string? (Y or N): "; getline( cin,response);

}

cout << "Test#3 Ended" << endl

<< "****************************************" << endl; cout << "****************************************" << endl

<< "Test#4: tesing replace_all "

<< "****************************************" << endl; response = "y"; string current, old_substring, new_substring; while (response == "Y" || response == "y")

{ cout << "Enter value for current_string: "; getline(cin, current);

string_class current_string(current); cout << "Enter old_substring: "; getline(cin, old_substring); cout << "Enter new_substring: "; getline(cin, new_substring);

cout << "Current Value in Current string = " << current << endl; current_string.replace_all(old_substring, new_substring);

cout << "New value in Current String = " << current_string << endl; cout<< endl;

cout << "Would you like to try another string? (Y or N): "; getline(cin, response); cout << endl;

}

cout << "****************************************" << endl

<< "End Test#4: tesing replace "

<< "****************************************" << endl;*/ return 0; }

Use the program header:

#pragma once #include using namespace std; class string_class { private: string current_string; public: string_class(); string_class(string temp); bool palindrome(); string replace_all(string Old, string New); friend ostream& operator<<(ostream& os, string_class& temp); };

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

Students also viewed these Databases questions

Question

please dont use chat gpt or other AI 9 2 5 .

Answered: 1 week ago

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

Know when firms should not offer service guarantees.

Answered: 1 week ago

Question

Recognize the power of service guarantees.

Answered: 1 week ago