So I am doing a C++ Project for one of my classes and I am completely lost on what this is asking for (More so on how to get the program off the ground as the language used is very weird to me in relation to the Constructors)
#ifndef MYSTRING_H
#define MYSTRING_H
#include <iostream> /* cout, endl */
class MyString {
public:
//Constructors
MyString();
MyString(constchar*);
//Destructor
~MyString();
int getString();
bool upper();
bool lower();
bool reverse();
int clear();
int set();
int length();
int substring();
int cat();
int count();
//Length Attribute
int Length;
};
But I am more or less lost on how to get the actual functions made as implementation is relatively easy for me, it's just the functions themselves.
(AKA, I am lost on how to make at least the starts of these functions in mystring.cpp, and if I can get at least some of the major ones down (like however the heck he wants the constructors and destructors to work), I should be able to get most of the rest done.)
AKA I have almost 0 clue on how to do the constructors for this, after that, the rest should be more or less painless.
class mystring should have a char*, Ill call it 'data'for now you can rename it.
then, you ctor might look like:
MyString::MyString(constchar* in)
: Length{strlen(in)} // add a comma and fill in other attributes that you want, if any
{
//do some work here that is beyond what you can do with just simple copies or derivation in the init list
data = newchar[something]; //something is maybe Length+1, or maybe something bigger, whatever
strcpy(data,in);
}
the default ctor (no params) probably won't do anything because you would set data and length to nullptr and 0 where they are declared instead. but you will have to provide the empty function one way or another, or you won't be able to make objects using it. I think there is a way to get the standard empty one to be made for you, if that is allowed?
> like however the heck he wants the constructors and destructors to work
you have a dynamic array that would store the characters
the constructor will allocate the memory and the destructor will release it
don't forget the copy constructor and assignment operator
> implementation is relatively easy for me,
> lost on how to get the actual functions made
¿is it easy or you have no idea?