Question
C++ PROGRAMMING HELP!!! Hello, i need help completing a program.. myStringClass.cpp was created and i need help to fix it. Error : static void validateUserInput(myStringClass&
C++ PROGRAMMING HELP!!!
Hello, i need help completing a program.. myStringClass.cpp was created and i need help to fix it. Error: "static void validateUserInput(myStringClass& myStringClassObject);" in the myStringClass.h; line 66 is not in the myStringClass.cpp file and i need help implementing it into myStringClass.cpp. So in short: Please complete the myStringClass.cpp by adding the code to "static void validateUserInput(myStringClass& myStringClassObject);". I'm getting an error without it...
I have provided main.cpp and myStringClass.h below. PLEASE DO NOT CHANGE ANYTHING IN THOSE FILES. I also attached the myStringClass.cpp below and 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.
--------------------------
myStringClass.cpp
#include
#include "myStringClass.h"
myStringClass::myStringClass()
{
userInput = nullptr;
userInputLength = 0;
}
//overloaded constructor
myStringClass::myStringClass(const char* str)
{
if (nullptr != str)
{
//delete userInput;
//allocating memory also taking care of the null character
userInput = new char[strlen(str) + 1];
//perform string copy taking the length of the string from the argument
strcpy_s(userInput, strlen(str) + 1, str);
userInputLength = strlen(str);
}
}
//myStringClass(const myStringClass &obj); //copy constructor
myStringClass::myStringClass(const myStringClass * str)
{
if (nullptr != str)
{
if (!userInput)
{
//allocating memory also taking care of the null character
userInput = new char[strlen(str->userInput) + 1];
}
//perform deep copying of the objects(Element by Element copying)
strcpy_s(userInput, strlen(str->userInput) + 1, str->userInput);
userInputLength = str->userInputLength;
}
}
//destructor
myStringClass:: ~myStringClass()
{
//if memory is allocated then only delete
if (userInput)
{
delete[] userInput;
}
userInputLength = 0;
}
//getter
int myStringClass::stringLength() const
{
return userInputLength; //or return strlen(userInput);
}
//overload =
myStringClass& myStringClass::operator = (const myStringClass& str)
{
if (!userInput)
{
//allocating memory also taking care of thenull character
userInput = new char[strlen(str.userInput) + 1];
}
//perform deep copying of the objects (Element by Element copying)
strcpy_s(userInput, strlen(str.userInput) + 1, str.userInput);
userInputLength = str.userInputLength;
return *this;
}
//overload []
char& myStringClass:: operator[](int index)
{
//return the character as specified by the index
return userInput[index];
}
//const overload[]
//const char& operator[](int index);
//overload + //the concatenation operator
myStringClass& myStringClass:: operator + (const myStringClass& str)
{
//reallocation of memory
realloc(userInput, userInputLength + str.userInputLength + 1);
strcat_s(userInput, userInputLength + str.userInputLength, str.userInput);
userInputLength += str.userInputLength;
//return the invoking object
return *this;
}
//the folling all return a bool
//overlad ==
bool myStringClass::operator == (const myStringClass& str)
{
if (strcmp(userInput, str.userInput) == 0)
{
return true;
}
else
{
return false;
}
}
//overload !=
bool myStringClass::operator != (const myStringClass& str)
{
//string not equal checking because strcmp returns 0 if strings are equal
if (strcmp(userInput, str.userInput))
{
return true;
}
else
{
return false;
}
}
//overload
bool myStringClass::operator
{
if (strcmp(userInput, str.userInput)
{
return true;
}
else
{
return false;
}
}
//overload
bool myStringClass::operator
{
if (strcmp(userInput, str.userInput)
{
return true;
}
else
{
return false;
}
}
//overload >= (const myStringClass& str)
bool myStringClass::operator >= (const myStringClass& str)
{
if (strcmp(userInput, str.userInput) >= 0)
{
return true;
}
else
{
return false;
}
}
//overload >
bool myStringClass:: operator > (const myStringClass & str)
{
if (strcmp(userInput, str.userInput) > 0)
{
return true;
}
else
{
return false;
}
}
//overload +=
//same as concatenation
myStringClass myStringClass::operator += (myStringClass& right)
{
//reallocationg of memory
realloc(userInput, userInputLength + right.userInputLength + 1);
strcat_s(userInput, userInputLength + right.userInputLength, right.userInput);
userInputLength += right.userInputLength;
//return the invoking object
return *this;
}
//friend myStringClass& operator +=(myStringClass& left, const myStringClass& right);
void myStringClass::validateUserInt(myStringClass& myStringClassObject)
{
if (strlen(myStringClassObject.userInput))
{
cout
}
else
{
cout
}
}
ostream& operator
{
cout userInput;
return cout;
}
ostream& operator
{
cout
return cout;
}
istream& operator >> (istream& cin, myStringClass& str)
{
str.userInput = new char[20];
cin >> str.userInput;
return cin;
}
--------------------------
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); //ERROR HERE. MISSING IN myStringClass.cpp
static void validateUserInt(myStringClass& myStringClassObject);
private:
char* userInput; // Array to hold input
int userInputLength;
};
#endif
--------------------------
COMPLETED PROGRAM SCREENSHOT:
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 abcStep 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