Question
DONT COPY PASTE FROM OTHER QUESTIONS PLEASE ***THE THREE TEXT FILES TO UTILISE ARE GIVEN BELOW********** INCLUDE SAMPLE OUTPUT AND COMMENTS FOR UNDERSTANDING PLEASE ***********************************************************************************************************************************************
DONT COPY PASTE FROM OTHER QUESTIONS PLEASE
***THE THREE TEXT FILES TO UTILISE ARE GIVEN BELOW********** INCLUDE SAMPLE OUTPUT AND COMMENTS FOR UNDERSTANDING PLEASE
***********************************************************************************************************************************************
MYSTRING1.H
********************************************************************************************************************************************************
//File: mystring1.h
#ifndef _MYSTRING_H #define _MYSTRING_H #include
#define MAX_STR_LENGTH 200 class String
{ public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator >(const String &str) const; bool operator
******************************************************************************************************************************************************************************************************
MYSTRING1.CPP
*************************************************************************************************************************************************************************************
#include"mystring1.h String::String() { contents[0] = '\0'; len = 0; } String::String(const char s[]) { len = strlen(s); strcpy(contents, s); } void String::append(const String &str) { strcat(contents, str.contents); len += str.len; } bool String::operator >(const String &str) const { return strcmp(contents, str.contents) > 0; } bool String::operator = len) {
cerr
********************************************************************************************************************************************************************************************************
DRIVER.CPP IS GIVEN TO TEST YOUR NEW CLASS AND PRODUCE OUTPUT(USE AS GIVEN)
*****************************************************************************************************************************************************************************************************
#include
#include "mystring.h"
using namespace std;
int main() { String str1, str2("cat"); char s1[100], s2[100]; // Print out initial strings cout > s1; str1 = s1; cout > s2; str2 = s2; cout > i; cout > i; cout
cout > s1; // str1.append(s1); // Actually, the cstring is converted to String object here by the constructor str1 += s1; // same as above cout > s2; str2 += s2; cout str2) { cout
String str3(str2); cout > q; return 0;
}
Include Sample Output
Project Description: You are given two files mystring1.h the document and mystring1.cpp the document which define a String class implemented by using static array as the data member. The purpose of this assignment is to rewrite this class by replacing the static array with a pointer (dynamic array). You are required to modify the String class accordingly: Data: we wish to allow our String class to accommodate strings of different sizes. To that end, instead of storing a string's characters in a fixed-size array, each String object should contain the following data as part of its internal representation: (1) a character pointer meant to point to a dynamically-allocated array of characters. (2) a length field that will hold the current length of the string at any given moment. Operations: same as the methods in String class, plus the "big three"( destructor, copy constructor, and assignment operator overloading). Modularity: The String class code must be put in its own module, i.e., a file mystring2.h (the header file) should hold the class definition (use conditional compilation directives) and a file mystring2.cpp (the implementation file) should hold the method definitionsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started