Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with this entire C++ lab example. I will provide the given codes

ID: 3866756 • Letter: P

Question

Please help me with this entire C++ lab example. I will provide the given codes below the pictured instructions. thank you so much

// StringDriver.h

#ifndef _STRINGDRIVER_H

#define _STRINGDRIVER_H

#include "String.h"

#include "ReverseString.h"

#include "CaseString.h"

int main();

void test1();

void test2();

void test3();

void test4();

void test5();

void test6();

void test7();

void test8();

void test9();

void test10();

void test11();

void test12();

void test13();

void test14();

void test15();

void test16();

void test17();

void test18();

void test19();

void test20();

void wait();

#endif

-------------------------------------------------------------------------------------------------------------------------

// StringDriver.cpp

#include <iostream>

#include <fstream>

#include <stdlib.h>

#include "StringDriver.h"

using namespace std;

ofstream csis;

int main() {

  

   csis.open("csis.txt");

   test1();

test2();

test3();

test4();

test5();

test6();

test7();

test8();

test9();

test10();

test11();

test12();

test13();

test14();

test15();

test16();

test17();

test18();

test19();

test20();

csis.close();

}

void test1() {

cout << "1. Testing S1: String default ctor." << endl << endl;

csis << "1. Testing S1: String default ctor." << endl << endl;

String s1;

s1.print();

wait();

}

void test2() {

cout << "2. Testing S2: String one arg (char *) ctor." << endl << endl;

csis << "2. Testing S2: String one arg (char *) ctor." << endl << endl;

String s2("ABC");

s2.print();

wait();

}

void test3() {

cout << "3. Testing S3: String one arg (char) ctor." << endl << endl;

csis << "3. Testing S3: String one arg (char) ctor." << endl << endl;

String s3('Z');

s3.print();

wait();

}

void test4() {

cout << "4. Testing S4: String one arg (int) ctor." << endl << endl;

csis << "4. Testing S4: String one arg (int) ctor." << endl << endl;

String s4(10);

s4.print();

wait();

}

void test5() {

cout << "5. Testing S5, T5: String copy ctor." << endl << endl;

csis << "5. Testing S5, T5: String copy ctor." << endl << endl;

String s5("Purple Rain");

s5.print();

String t5(s5);

t5.print();

wait();

}

void test6() {

cout << "6. Testing S6: String two arg (char, int) ctor." << endl << endl;

csis << "6. Testing S6: String two arg (char, int) ctor." << endl << endl;

String s6('*', 10);

s6.print();

wait();

}

void test7() {

cout << "7. Testing S7, T7, U7: String assignment." << endl << endl;

csis << "7. Testing S7, T7, U7: String assignment." << endl << endl;

String s7("Sally Ride"), t7, u7;

t7 = u7 = s7;

s7.print();

t7.print();

u7.print();

wait();

}

void test8() {

cout << "8. Testing S8: String assignment." << endl << endl;

csis << "8. Testing S8: String assignment." << endl << endl;

String s8("ABC");

s8 = s8;

s8.print();

wait();

}

void test9() {

cout << "9. Testing S9: Implicit type conversion." << endl << endl;

csis << "9. Testing S9: Implicit type conversion." << endl << endl;

String s9;

s9 = "ABC";

s9.print();

wait();

}

void test10() {

cout << "10. Testing S10, T10, U10: String concatenation." << endl << endl;

csis << "10. Testing S10, T10, U10: String concatenation." << endl << endl;

String s10("DEF");

String t10('H');

   String u10("ABC" + s10 + "G" + t10 + 'I');

u10.print();

   String v10('X' + u10);

v10.print();

wait();

}

void test11() {

cout << "11. Testing S11, T11: String concatenation." << endl << endl;

csis << "11. Testing S11, T11: String concatenation." << endl << endl;

String s11('A');

String t11("BC");

s11 += s11 += t11 += 'D';

s11.print();

t11.print();

wait();

}

void test12() {

cout << "12. Testing S12, T12: String unary operator." << endl << endl;

csis << "12. Testing S12, T12: String unary operator." << endl << endl;

String s12("Unary +");

String t12(+s12);

s12.print();

t12.print();

s12 = +s12;

s12.print();

wait();

}

void test13() {

cout << "13. Testing S13, T13: String comparison operators." << endl << endl;

csis << "13. Testing S13, T13: String comparison operators." << endl << endl;

String s13("ABC"), t13("ABCD");

s13.print();

t13.print();

cout << endl;

cout << "== " << (s13 == t13 ? "True" : "False") << endl;

cout << "!= " << (s13 != t13 ? "True" : "False") << endl;

cout << "< " << (s13 < t13 ? "True" : "False") << endl;

cout << "<= " << (s13 <= t13 ? "True" : "False") << endl;

cout << "> " << (s13 > t13 ? "True" : "False") << endl;

cout << ">= " << (s13 >= t13 ? "True" : "False") << endl;

csis << endl;

csis << "== " << (s13 == t13 ? "True" : "False") << endl;

csis << "!= " << (s13 != t13 ? "True" : "False") << endl;

csis << "< " << (s13 < t13 ? "True" : "False") << endl;

csis << "<= " << (s13 <= t13 ? "True" : "False") << endl;

csis << "> " << (s13 > t13 ? "True" : "False") << endl;

csis << ">= " << (s13 >= t13 ? "True" : "False") << endl;

wait();

}

void test14() {

cout << "14. Testing S14: Overloaded subscript operator." << endl << endl;

csis << "14. Testing S14: Overloaded subscript operator." << endl << endl;

String s14("C++ is fun.");

for (int i = -1; i <= s14.getLength(); i++) {

char& ch = s14[i];

if (ch != '')

++ch;

}

s14.print();

wait();

}

void test15() {

cout << "15. Testing S15: Pointer notation." << endl << endl;

csis << "15. Testing S15: Pointer notation." << endl << endl;

String s15("ABCDE");

for(int i = 0; i < s15.getLength(); i++)

++(*(s15+i));

for (int j = 0; j < s15.getLength(); j++) {

cout << *(j + s15);

csis << *(j + s15);

}

cout << endl;

csis << endl;

wait();

}

void test16() {

cout << "16. Testing S16, T16, U16, V16, W16, X16, Y16, Z16: Increment and decrement operators." << endl << endl;

csis << "16. Testing S16, T16, U16, V16, W16, X16, Y16, Z16: Increment and decrement operators." << endl << endl;

String s16("ABC");

String t16(++s16);

s16.print();

t16.print();

  

String u16("ABC");

String v16(u16++);

u16.print();

v16.print();

  

String w16("ABC");

String x16(--w16);

w16.print();

x16.print();

  

String y16("ABC");

String z16(y16--);

y16.print();

z16.print();

wait();

}

void test17() {

cout << "17. Testing S17, T17: Substr function." << endl << endl;

csis << "17. Testing S17, T17: Substr function." << endl << endl;

String s17("All You Need Is Love"), t17;

t17 = s17.substr(4, 8);

s17.print();

t17.print();

wait();

}

void test18() {

cout << "18. Testing S18, T18: Output function." << endl << endl;

csis << "18. Testing S18, T18: Output function." << endl << endl;

String s18("Red-");

String t18("Green-");

String u18("Blue");

cout << s18 << t18 << u18;

csis << s18 << t18 << u18;

cout << endl;

csis << endl;

wait();

}

void test19() {

cout << "19. Testing S19, T19, U19: ReverseString class." << endl << endl;

csis << "19. Testing S19, T19, U19: ReverseString class." << endl << endl;

ReverseString s19("Computer");

ReverseString t19;

t19 = ~s19;

s19.print();

t19.print();

  

ReverseString u19(~~s19);

u19.print();

wait();

}

void test20() {

cout << "20. Testing S20, T20, U20: CaseString class." << endl << endl;

csis << "20. Testing S20, T20, U20: CaseString class." << endl << endl;

CaseString s20("BaLLooN");

CaseString t20;

t20 = s20;

s20.print();

t20.print();

  

CaseString u20(s20);

u20.print();

wait();

}

void wait() {

char buf;

  

cout << endl << "Press any key to continue." << endl;

csis << endl << endl;

cin.get(buf);

}

u were to put this class into a library and nce its intuitive. Now suppose yo existence so could take advantage of it. But someone then says to you, "The so that use function so that users that I meant to overload the unary as a The class is fine, except uence of letters in the string and returnis that it reverses the sequence of letters in the str s case t shouldI would be new instance o for the user to derive a new class from the string class and add the reated the capabilities of the original class will still be there, plus the added capabi features, the new class really is a kind of String class. class, all of of more String class with Write a class called ReverseString that is publicly derived from the st class, with the following member functions: a default constructor function a copy constructor function a constructor function that takes a const char as its one argument an overloaded assignment operator . an overloaded unary operator-() function that reverses the letters of the string itself, and returns a new Reversestring instance by value (note that the actual contents of the string literal pointed to by buf are never modified) Write a class called Casestring, that is publicly derived from the String class, with the following data members: a pointer, upper, of type char*, which holds the contents of the string literal in upper case a pointer, lower, of type char, which holds the contents of the string literal in lower case Focus on Object-Oriented Programming with C++ Page 454

Explanation / Answer

Below is your program: -

// String.cpp

#include "String.h"
#include <fstream>
#include<cstring>

extern ofstream csis;

String::String()
{
buf = new char[1];
buf[0] = '';
length = 0;
}

String::String(const char* str)
{
length = int(strlen(str));
buf = new char[length+1];

for (int i = 0; i < length; i++) {
buf[i] = str[i];
}
buf[length] = '';
}

String::String(char ch)
{
buf = new char[2];

buf[0] = ch;
length = 1;
buf[length] = '';
}

String::String(int i)
{
int count = 0,
temp = i;

if (i < 0) {
i = 0;
}

while (temp > 0) {
temp /= 10;
count++;
}

buf = new char[count+1];
sprintf(buf, "%d", i);
length = count;
buf[length] = '';
}

String::String(const String& str)
{
length = str.length;
buf = new char[length];
buf = str.buf;
}

String::String(char ch, int i)
{
buf = new char[i];
char charArray[i];

for (int index = 0; index < i; index++) {
charArray[index] = ch;
}
charArray[i] = '';
buf = charArray;
length = int(strlen(buf));
}

String::~String()
{
//delete [] buf;
length = 0;
}

String& String::operator=(const String& str)
{
if (this == &str) {
return *this;
}

length = str.length;
buf = str.buf;

return *this;
}

String& String::operator=(const char* ch)
{
length = int(strlen(ch));
buf = (char*)ch;

return *this;
}

String operator+(const String& str1, const String& str2)
{
int i, j;
int combinedLength = str1.length + str2.length;
String temp(combinedLength);
temp.length = combinedLength;

for (i = 0; i < str1.length; i++) {
temp.buf[i] = str1.buf[i];
}

for (j = 0, i = str1.length; j < str2.length; j++, i++) {
temp.buf[i] = str2.buf[j];
}
temp[combinedLength] = '';

return temp;
}

String operator+(const String& str1, const char* ch)
{
int i, j;
int combinedLength = str1.length + int(strlen(ch));
String temp(combinedLength);
temp.length = combinedLength;

for (i = 0; i < str1.length; i++) {
temp.buf[i] = str1.buf[i];
}

for (j = 0, i = str1.length; j < int(strlen(ch)); j++, i++) {
temp.buf[i] = ch[j];
}
temp[combinedLength] = '';

return temp;
}

String operator+(const char* ch, const String& str1)
{
int i, j;
int combinedLength = str1.length + int(strlen(ch));
String temp(combinedLength);
temp.length = combinedLength;

for (i = 0; i < int(strlen(ch)); i++) {
temp.buf[i] = ch[i];
}

for (j = 0, i = int(strlen(ch)); j < str1.length; j++, i++) {
temp.buf[i] = str1.buf[j];
}

temp[combinedLength] = '';

return temp;
}

String operator+(const String& str1, const char ch)
{
int i;
int combinedLength = str1.length + 1;
String temp(combinedLength);
temp.length = combinedLength;

for (i = 0; i < str1.length; i++) {
temp.buf[i] = str1.buf[i];
}
temp[combinedLength-1] = ch;
temp[combinedLength] = '';

return temp;
}

String operator+(const char ch, const String& str1)
{
int i, j;
int combinedLength = str1.length + 1;
String temp(combinedLength);
temp.length = combinedLength;

temp[0] = ch;
for (i = 0, j = 1; i < str1.length; i++, j++) {
temp.buf[j] = str1.buf[i];
}
temp[combinedLength] = '';

return temp;
}

String& String::operator+=(const String& str)
{
int i, j;
int tempLength = length + str.length;
char* temp = new char[tempLength];

for (i = 0; i < length; i++) {
temp[i] = buf[i];
}

for (i = length, j = 0; j < str.length; i++, j++) {
temp[i] = str.buf[j];
}

delete [] buf;
buf = new char[tempLength];
length = tempLength;

for (i = 0; i < length; i++) {
buf[i] = temp[i];
}

delete [] temp;

return *this;
}

String String::operator+() const
{
String temp;
temp.buf = buf;
temp.length = length;

for (int i = 0; i < temp.length; i++) {
temp[i] = toupper(temp[i]);
}

return temp;
}

int operator==(const String& str1, const String& str2)
{
return str1.buf == str2.buf;
}

int operator!=(const String& str1, const String& str2)
{
return str1.buf != str2.buf;
}

int operator< (const String& str1, const String& str2)
{
return str1.buf < str2.buf;
}

int operator<=(const String& str1, const String& str2)
{
return str1.buf <= str2.buf;
}

int operator> (const String& str1, const String& str2)
{
return str1.buf > str2.buf;
}

int operator>=(const String& str1, const String& str2)
{
return str1.buf >= str2.buf;
}

char& String::operator[](int i)
{
static char ch = '';

if (i < 0 || i > length) {
cout << "Error: Index out of range" << endl;
return ch;
}
else {
return buf[i];
}
}

char* operator+(const String& str, int i)
{
return &str.buf[i];
}

char* operator+(int i, const String& str)
{
return &str.buf[i];
}

String& String::operator++()
{
for (int i = 0; i < length; i++) {
buf[i] = buf[i+1];
}

return *this;
}

String& String::operator--()
{
for (int i = length; i > 0; i--) {
buf[i] = buf[i-1];
}

return *this;
}

String& String::operator++(int val)
{
String temp(*this);
++(*this);

return temp;
}

String& String::operator--(int val)
{
String temp(*this);
--(*this);

return temp;
}

String String::substr(int start, int end)
{
String s;

for (int i = start, j = 0; j < end; i++, j++) {
s.buf[j] = buf[i];
s.length++;
}
return s;
}

int String::getLength()
{
return length;
}

void String::print()
{
cout << """ << buf << """ << " " << "Length = " << length << endl;
csis << """ << buf << """ << " " << "Length = " << length << endl;
}

ostream& operator<<(ostream& os, const String& str)
{
for (int i = 0; i < str.length; i++) {
os << str.buf[i];
}

return os;
}

// String.h

#ifndef __Inheritance_Lab__String__
#define __Inheritance_Lab__String__

#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

class String {
private:
char* buf;
int length;
public:
String();
String(const char*);
String(char);
String(int);
String(const String&);
String(char, int);
~String();
String& operator=(const String&);
String& operator=(const char*);
friend String operator+(const String&, const String&);
friend String operator+(const String&, const char*);
friend String operator+(const char*, const String&);
friend String operator+(const String&, const char);
friend String operator+(const char, const String&);
String& operator+=(const String&);
String operator+() const;
friend int operator==(const String&, const String&);
friend int operator!=(const String&, const String&);
friend int operator< (const String&, const String&);
friend int operator<=(const String&, const String&);
friend int operator> (const String&, const String&);
friend int operator>=(const String&, const String&);
char& operator[](int);
friend char* operator+(const String&, int);
friend char* operator+(int, const String&);
String& operator++();
String& operator--();
String& operator++(int);
String& operator--(int);
String substr(int, int);
int getLength();
void print();
friend ostream& operator<<(ostream&, const String&);
};

#endif

// ReverseString.h

#ifndef __Inheritance_Lab__ReverseString__

#define __Inheritance_Lab__ReverseString__

#include <iostream>

#include "String.h"

class ReverseString: public String {

private:

char* rstring;

public:

ReverseString();

ReverseString(const ReverseString&);

ReverseString(const char*);

ReverseString& operator=(const ReverseString&);

ReverseString operator~();

};

#endif

// ReverseString.cpp

#include <algorithm>
#include "ReverseString.h"

ReverseString::ReverseString() : String() {}

ReverseString::ReverseString(const ReverseString& rs) : String(rs) {}

ReverseString::ReverseString(const char* ch) : String(ch) {}

ReverseString& ReverseString::operator=(const ReverseString& rs)
{
if (&rs != this) {
String::operator=(rs);
}

return *this;
}

ReverseString ReverseString::operator~()
{
ReverseString rs(*this);
ReverseString reverse;
int count = 0;

/*for (int i = rs.getLength()-1; i >= 0; i--) {
reverse.rstring[count] = rs.rstring[i];
count++;
}*/

return reverse;
}

// CaseString.h

#ifndef __Inheritance_Lab__CaseString__
#define __Inheritance_Lab__CaseString__

#include <iostream>
#include "String.h"

class CaseString: public String {
private:
char* upper;
char* lower;
public:
CaseString();
CaseString(const CaseString&);
CaseString(const char*);
CaseString& operator=(const CaseString&);
void print();
~CaseString();
};

#endif

// CaseString.cpp

#include "CaseString.h"
#include <fstream>

extern ofstream csis;


CaseString::CaseString() : String() {}

CaseString::CaseString(const CaseString& cs) : String(cs){}

CaseString::CaseString(const char* ch) : String(ch) {}

CaseString& CaseString::operator=(const CaseString& cs)
{
if (&cs != this) {
String::operator=(cs);
}

return *this;
}

void CaseString::print()
{
cout << lower << " " << upper << endl;
csis << lower << " " << upper << endl;
}

CaseString::~CaseString()
{
//delete [] lower;
//delete [] upper;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote