consider the following specification file that simulates the string class library "string.h":
//i named it aa.h
#include<iostream>
#include<cstring>
using namespace std;

const int SIZE=100;
class MyString
{
public:

MyString();
MyString(char arr[]);
MyString operator+(MyString oString);//concatenation
bool operator==(MyString oString);//are equal strings
int MyString::length() const;//returns the number of characters stored in the object.
int Find(char arr[]) const;// finds the position of the first occurence for the paseed string
MyString SubStr(int start, int length);//extarcts a substring from the current string

consider the following specification file that simulates the string class library "string.h":
//i named it aa.h

Code:

#include<iostream>
#include<cstring>
using namespace std;

const int SIZE=100;
class MyString
{
public:

MyString();
MyString(char arr[]);
MyString operator+(MyString oString);//concatenation
bool operator==(MyString oString);//are equal strings
int MyString::length() const;//returns the number of characters stored in the object.
int Find(char arr[]) const;// finds the position of the first occurence for the paseed string
MyString SubStr(int start, int length);//extarcts a substring from the current string

has three errors in it, so there are no doubt numerous bugs in the more complicated methods. Run this method through the debugger (plus look at the compiler warnings as mine - g++ - gives one for the 'for' line) and check whether the 'text' array ends up as it should.

October 8th, 2011, 05:34 AM

aynsar

Re: help C++ code

Quote:

Originally Posted by VictorN

Well, to fix the problems "in executing" you have to use the debugger, run your code step by step and see what and where goes wrong.

Besides, better approach would be passing your MyString instance in some of the class methods by const reference to prevent unneeded copying. example:

has three errors in it, so there are no doubt numerous bugs in the more complicated methods. Run this method through the debugger (plus look at the compiler warnings as mine - g++ - gives one for the 'for' line) and check whether the 'text' array ends up as it should.

Hi!
thank you so much! yes trying to code one method at a time has showed me where exactly the program got stuck, actually invoking the constructor and how i implemented them was the major problem . thanks again :)