Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the code in C++.Kindly use the given details Implementation of String Class Implementation of String Class Your goal is to implement a generic String

Write the code in C++.Kindly use the given details

Implementation of String Class Implementation of String Class Your goal is to implement a generic String class using cstring, i.e. you will need to write three files (string.h, string.cpp and Q5.cpp). Your implemented class must fully provide the definitions of following class (interface) functions. Please also write down the test code to drive your class implementation.

class String{

private: // think about the private data members... public: // provide definitions of following functions... String();// default constructor String(char *str);// initializes the string with constant cstring String(const String &);// copy constructor String(int x);// initializes a string of pre-defined size char getAt(int i);// returns the character at index [x] void setAt(int i, char c);// set the character at index [x] String substr(int pos, int len);// returns a substring of length len from pos String substr(int pos);// returns substring from the given position to the end. void append(char a);// append a char at the end of string void append(String str );// append a String at the end of string void append(char *str );// append a constant c string at the end of string int length();// returns the length of string char * tocstring();// converts a String to c-string void display();// displays the string .. bool isEmpty();// returns true if string is empty.. void copy(const String&);// Copy one string to another ... void copy(const char *);// copy cstring to String... int find(char);// returns the index of character being searched. bool equal(String);// should return true if both strings are same int stoi();// function for converting a string to integer. String();// destructor... };

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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