Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PROGRAMMING HELP!!! Hello, i need help completing a program.. 'myStringClass.cpp' must be created to define each of the declared functions in 'myStringClass.h'. I have

C++ PROGRAMMING HELP!!!

Hello, i need help completing a program.. 'myStringClass.cpp' must be created to define each of the declared functions in 'myStringClass.h'.

I have provided main.cpp and myStringClass.h below. PLEASE DO NOT CHANGE ANYTHING IN THOSE FILES. I also attached a screenshot of the completed program. Any and all help is GREATLY appreciated!! Please and thank you so much in advanced.

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

FULL PROMPT:

Write your own string class (almost), the following are the requirements:

Use the enclosed .h and the enclosed main.cpp files (main.cpp & myStringClass.h)

Define each of the declared functions in the .h file. Comment your code & use meaningful or mnemonic variable names

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

RESTRICTIONS:

NO global variables | NO labels or go-to statements | NO infinite loops | NO break statements

DO NOT #include in any of your files; in other words, do NOT use the string class

MAY USE string literals, but do NOT use variables of type string.

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

main.cpp

#include

#include

#include "myStringClass.h"

using namespace std;

int main()

{

//object declaration

//default constructor

myStringClass last, first, age;

cout

cin >> first;//overloaded cin

myStringClass::validateUserInput(first);

cout

cin >> last;//overloaded cin

myStringClass::validateUserInput(last);

cout

cin >> age;

myStringClass::validateUserInt(age);

//overloaded cout

cout

//object declaration

//overloaded constructor

//leftside longer and less

myStringClass string1 = "abx";

myStringClass string2 = "ax";

//overloaded logical operators: ==,

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout "

}

cout

string1 = "axb";

string2 = "aa";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout "

}

cout

string1 = "ab";

string2 = "axb";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout "

}

cout

string1 = "ax";

string2 = "aax";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout "

}

cout

string1 = "abcz";

string2 = "abc";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout "

}

cout

string1 = "abc";

string2 = "abcz";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout "

}

cout

string1 = "abc";

string2 = "abc";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout "

}

cout

string1 = "abx";

string2 = "ax";

//overloaded logical operators: ==,

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout = "

}

cout

string1 = "axb";

string2 = "aa";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout = "

}

cout

string1 = "ab";

string2 = "axb";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout = "

}

cout

string1 = "ax";

string2 = "aax";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout = "

}

cout

string1 = "abcz";

string2 = "abc";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout = "

}

cout

string1 = "abc";

string2 = "abcz";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout = "

}

cout

string1 = "abc";

string2 = "abc";

if (string1 == string2)

{

cout

}

else if (string1

{

cout

}

else

{

cout = "

}

cout

//array of myStringClass

myStringClass arrayOfNames[5];

for (int x = 0; x

{

cout

cin >> arrayOfNames[x];

myStringClass::validateUserInput(arrayOfNames[x]);

}

cout

for (int x = 0; x

{

cout

}

string2 = "Hello ";

//object declaration

//copy constructor

myStringClass string3(string2);

myStringClass string4 = string3 + "World";

cout

cout

system("pause");

return 0;

}

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

myStringClass.h

#ifndef myStringClass_h

#define myStringClass_h

#include

using namespace std;

class myStringClass

{

//Overload the stream insertion and extraction operators

friend ostream& operator

friend ostream& operator

friend istream& operator>> (istream&, myStringClass&);

public:

//default constructor

myStringClass();

//overloaded constructors

myStringClass(const char* str);

//Choose one of the two below

//myStringClass(const myStringClass &obj); // copy constructor

myStringClass(const myStringClass* str); // copy constructor

//destructor

~myStringClass();

//getter

int stringLength() const;

//overload =

myStringClass& operator=(const myStringClass&);

//overload []

char& operator[](int index);

//const overload []

//const char& operator[](int index);

//overload +//the concatenation operator

myStringClass& operator+(const myStringClass&);

//the following all return a bool

//overload ==

bool operator==(const myStringClass&);

//overload !=

bool operator!=(const myStringClass&);

//overload

bool operator

//overload

bool operator

//overload >=

bool operator>=(const myStringClass&);

//overload >

bool operator>(const myStringClass&);

//overload +=

myStringClass operator+=(myStringClass& right);

//friend myStringClass& operator+=(myStringClass& left, const myStringClass& right);

static void validateUserInput(myStringClass& myStringClassObject);

static void validateUserInt(myStringClass& myStringClassObject);

private:

char* userInput; // Array to hold input

int userInputLength;

};

#endif

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

Completed Program Screenshot:

image text in transcribed

Enter your first name only Jen what is your last name? Ul enter your age hello Jen Lu, age: 17 axb aa ax aax abcz > abc abc - abc abc

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago