0

Hi, i'm having some problems with my inheritance homework. It consists on writing a progrma that mimics the String lib by overloading different operands and then create two derive classes that will revert a string and that will change the cases to lower and upper. This is as far as i got, but now i get error messages indicating that the members in the String.cpp file are not in the String.h file. Could i get some feed back on what i am missing or doing wrong? Thanks in advance

[LIST=1]
[*]//String.h
[*]#ifndef _STRING_H
[*]#define _STRING_H

[*]class String 
[*]{
[*]	protected:
[*]		int length;
[*]		char* buf;
[*]		char *name;

[*]	public:
[*]		String();
[*]		String(char* ch01);
[*]		String(char ch02);
[*]		String(int ch03);
[*]		String(const String& str01);
[*]		String(char ch04, int n);
[*]		~String();
[*]		void setName(char *nm);
[*]		int getLength(); 
[*]		void print();
[*]		String& operator=(const String& str02);
[*]		String& operator=(const char* ch04);
[*]		friend String operator+(const String& str01, const String& str02);
[*]		friend String operator+(const String& str01, const char* ch01);
[*]		friend String operator+(const char* ch01, const String& str01);
[*]		friend String operator+(const String& str01, char ch01);
[*]		friend String operator+(char ch01, const String& str01);
[*]		String& operator+=(const String& str01);
[*]		//String operator+(const String str01);
[*]		String operator+() const;
[*]		friend int operator==(const String& str01, const String& str02);
[*]		friend int operator!=(const String& str01, const String& str02);
[*]		friend int operator< (const String& str01, const String& str02);
[*]		friend int operator<=(const String& str01, const String& str02);
[*]		friend int operator> (const String& str01, const String& str02);
[*]		friend int operator>=(const String& str01, const String& str02);
[*]		char& operator[](int n);
[*]		friend char* operator+(const String& str01, int n);
[*]		friend char* operator+(int n, const String& str01);
[*]		String& operator++();
[*]		String& operator--(); 
[*]		String operator++(int n);
[*]		String operator--(int n);
[*]		String substr(int n1, int n2);
[*]		friend ostream& operator<<(ostream& os, const String& str01);
[*]};
[*]#endif
[/LIST]
[LIST=1]
[*]// String.cpp

[*]#include <iostream>
[*]#include <fstream>
[*]#include <stdlib.h>
[*]#include "string.h"

[*]using namespace std;
[*]extern ofstream csis;

[*]//Ctr overload
[*]String::String()
[*]{
[*]	buf = new char[1];
[*]	length = 0;
[*]}
[*]String::String(char* ch01)
[*]{
[*]	buf = new char[sizeof(ch01)+1];
[*]	strcpy_s(buf,(sizeof(ch01)+1),ch01);
[*]	length = sizeof(ch01);
[*]}
[*]String::String(char ch02)
[*]{
[*]	//buf = ch02;
[*]	buf = new char[1];
[*]	buf[0] = ch02;
[*]	length = 1;
[*]}
[*]String::String(int ch03)
[*]{
[*]	if (ch03 <= 0)
[*]	{
[*]		ch03 = 0;
[*]		String();
[*]	}
[*]	else
[*]	{
[*]		buf = new char[ch03+1];
[*]	}
[*]	buf[0] = NULL;
[*]	length = ch03;
[*]}
[*]String::String(char ch04, int n)
[*]{
[*]	buf = new char[n];
[*]	for (int c = 0; c < n; c++)
[*]		buf[c] = ch04;
[*]	length = n;
[*]}
[*]//Copy Ctr
[*]String::String(const String &str01)
[*]{
[*]	buf = new char[sizeof(str01.buf)+1];
[*]	strcpy_s(buf,(sizeof(str01.buf)+1),str01.buf);
[*]	length = sizeof(str01.buf);
[*]}
[*]String::~String()
[*]{
[*]	delete [] name;
[*]	delete [] buf;
[*]}
[*]int String::getLength()
[*]{
[*]	return length;
[*]}
[*]void String::setName(char *nm)
[*]{
[*]	name = new char[sizeof(nm)+1];
[*]    strcpy_s(name, sizeof(nm)+1, nm);
[*]	length = sizeof(nm);
[*]}
[*]void String::print()
[*]{
[*]	cout << name;
[*]	csis << name;
[*]}
[*]String& String::operator =(const String& str02)
[*]{
[*]	String temp(str02);
[*]	delete [] buf;
[*]	buf = new char[sizeof(temp.buf)+1];
[*]	strcpy_s(buf,(sizeof(temp.buf)+1),temp.buf);
[*]	length = temp.getLength();
[*]	setName(buf);
[*]	return *this;
[*]}
[*]String& String::operator =(const char* ch04)
[*]{
[*]	delete []buf;
[*]	buf = new char[strlen(ch04)+1];
[*]	strcpy_s(buf,(sizeof(ch04)+1),ch04);
[*]	length = sizeof(ch04);
[*]	setName(buf);
[*]	return *this;
[*]}
[*]String String::operator +(const String& str01, const String& str02)
[*]{
[*]	String temp01(str01);
[*]	String temp02(str02);
[*]	
[*]	delete [] buf;
[*]	buf = new char [temp01.getLength() + temp02.getLength() +1];
[*]	for (int c = 0; c < temp01.getLength(); c++)
[*]		buf[c] = temp01.buf[c];

[*]	for (int c = 0; c < temp02.getLength(); c++)
[*]		buf[temp01.getLength() + c] = temp02.buf[c];

[*]	String temp03(buf);
[*]	temp03.setName(buf);
[*]	return temp03;
[*]}
[*]String String::operator +(const String& str01, const char* ch01)
[*]{
[*]	String temp01(str01);
[*]	String temp02(ch01);

[*]	delete [] buf;
[*]	buf = new char [temp01.getLength() + temp02.getLength() +1];
[*]	for (int c = 0; c < temp01.getLength(); c++)
[*]		buf[c] = temp01.buf[c];

[*]	for (int c = 0; c < temp02.getLength(); c++)
[*]		buf[temp01.getLength() + c] = temp02.buf[c];

[*]	String temp03(buf);
[*]	temp03.setName(buf);
[*]	return temp03;
[*]}
[*]String String::operator +(const char* ch01, const String& str01)
[*]{
[*]	String temp01(str01);
[*]	String temp02(ch01);
[*]	
[*]	delete [] buf;
[*]	buf = new char [temp01.getLength() + temp02.getLength() +1];
[*]	for (int c = 0; c < temp02.getLength(); c++)
[*]		buf[c] = temp02.buf[c];

[*]	for (int c = 0; c < temp01.getLength(); c++)
[*]		buf[temp02.getLength() + c] = temp01.buf[c];

[*]	String temp03(buf);
[*]	temp03.setName(buf);
[*]	return temp03;
[*]}
[*]String String::operator +(const String& str01, char ch01)
[*]{
[*]	String temp01(str01);
[*]	String temp02(ch01);
[*]	
[*]	delete [] buf;
[*]	buf = new char [temp01.getLength() + temp02.getLength() 1];
[*]	for (int c = 0; c < temp01.getLength(); c++)
[*]		buf[c] = temp01.buf[c];

[*]	buf[temp01.getLength() + temp02.getLength()] = temp02.buf;

[*]	String temp03(buf);
[*]	temp03.setName(buf);
[*]	return temp03;
[*]}
[*]String String::operator +(char ch01, const String& str01)
[*]{
[*]	String temp01(ch01);
[*]	String temp02(str01);
[*]	
[*]	delete [] buf;
[*]	buf = new char [temp01.getLength() + temp02.getLength()  1];
[*]	for (int c = 0; c < temp01.getLength(); c++)
[*]		buf[c] = temp01.buf[c];

[*]	for (int c = 0; c < temp02.getLength(); c++)
[*]		buf[temp01.getLength() + c] = temp02.buf[c];

[*]	String temp03(buf);
[*]	temp03.setName(buf);
[*]	return temp03;
[*]}
[*]String& String::operator +=(const String& str01)
[*]{
[*]	String temp(str01);
[*]	
[*]	delete [] buf;
[*]	buf = new char[length + temp.getLength() + 1];
[*]	for (int c = 0; c < length; c++)
[*]		buf[c] = name[c];

[*]	for (int c = 0; c < temp.getLength(); c++)
[*]		buf[length + c] = temp.buf[c];
[*]	
[*]	String temp01(buf);
[*]	String &temp02(temp01);
[*]	//temp01.setName(buf);
[*]	return temp02;
[*]}
[*]String String::operator +() const 
[*]{
[*]	return *this;
[*]}
[*]int String::operator ==(const String& str01, const String& str02);
[*]{
[*]	String temp01(str01);
[*]	String temp02(str02);
[*]	
[*]	if (temp01.getLength() == temp02.getLength())
[*]	{
[*]		for (int c = 0; c < temp01.getLength(); c++)
[*]		{
[*]			if (temp01.buf[c] != temp02.buf[c])
[*]			{
[*]				return 0;
[*]			}
[*]		}
[*]		return 1;
[*]	}
[*]	else
[*]	{
[*]		return 0;
[*]	}
[*]}
[*]int String::operator !=(const String& str01, const String& str02)
[*]{
[*]	String temp01(str01);
[*]	String temp02(str02);
[*]	
[*]	if (temp01.getLength() == temp02.getLength())
[*]	{
[*]		for (int c = 0; c < temp01.getLength(); c++)
[*]		{
[*]			if (temp01.buf[c] != temp02.buf[c])
[*]			{
[*]				return 1;
[*]			}
[*]		}
[*]		return 0;
[*]	}
[*]	else
[*]	{
[*]		return 1;
[*]	}
[*]}
[*]int String::operator <(const String& str01, const String& str02)
[*]{
[*]	String temp01(str01);
[*]	String temp02(str02);
[*]	
[*]	if (temp01.getLength() < temp02.getLength())
[*]	{
[*]		return 1;
[*]	}
[*]	else if (temp01.getLength() == temp02.getLength())
[*]	{
[*]		for (int c = 0; c < temp01.getLength(); c++)
[*]		{
[*]			if (temp01.buf[c] >= temp02.buf[c])
[*]			{
[*]				return 0;
[*]			}
[*]		}
[*]		return 1;
[*]	}
[*]	else
[*]	{
[*]		return 0;
[*]	}
[*]}
[*]int String::operator <=(const String& str01, const String& str02)
[*]{
[*]	String temp01(str01);
[*]	String temp02(str02);
[*]	
[*]	if (temp01.getLength() < temp02.getLength())
[*]	{
[*]		return 1;
[*]	}
[*]	else if (temp01.getLength() == temp02.getLength())
[*]	{
[*]		for (int c = 0; c < temp01.getLength(); c++)
[*]		{
[*]			if (temp01.buf[c] > temp02.buf[c])
[*]			{
[*]				return 0;
[*]			}
[*]		}
[*]		return 1;
[*]	}
[*]	else
[*]	{
[*]		return 0;
[*]	}
[*]}
[*]int String::operator >(const String& str01, const String& str02)
[*]{
[*]	String temp01(str01);
[*]	String temp02(str02);
[*]	
[*]	if (temp01.getLength() > temp02.getLength())
[*]	{
[*]		return 1;
[*]	}
[*]	else if (temp01.getLength() == temp02.getLength())
[*]	{
[*]		for (int c = 0; c < temp01.getLength(); c++)
[*]		{
[*]			if (temp01.buf[c] <= temp02.buf[c])
[*]			{
[*]				return 0;
[*]			}
[*]		}
[*]		return 1;
[*]	}
[*]	else
[*]	{
[*]		return 0;
[*]	}
[*]}
[*]int String::operator >=(const String& str01, const String& str02)
[*]{
[*]	String temp01(str01);
[*]	String temp02(str02);
[*]	
[*]	if (temp01.getLength() > temp02.getLength())
[*]	{
[*]		return 1;
[*]	}
[*]	else if (temp01.getLength() == temp02.getLength())
[*]	{
[*]		for (int c = 0; c < temp01.getLength(); c++)
[*]		{
[*]			if (temp01.buf[c] < temp02.buf[c])
[*]			{
[*]				return 0;
[*]			}
[*]		}
[*]		return 1;
[*]	}
[*]	else
[*]	{
[*]		return 0;
[*]	}
[*]}
[*]char& String::operator [](int n)
[*]{
[*]	return name[n];
[*]}
[*]char* String::operator +(const String& str01, int n)
[*]{
[*]	String temp(str01);
[*]	
[*]	delete [] buf;
[*]	buf = new char [temp.getLength() + 1];
[*]	strcpy_s(buf, temp.getLength(), temp.buf);
[*]	for (int c = 0; c < (temp.getLength() + 1); c++)
[*]	{
[*]		buf[c] = temp.buf + n;
[*]	}
[*]	setName(buf);
[*]	return buf;
[*]}
[*]char* String::operator+(int n, const String& str01)
[*]{ 
[*]	String temp(str01);
[*]	delete [] buf;
[*]	buf = new char [temp.getLength() + 1];
[*]	strcpy_s(buf, temp.getLength() + 1, temp.buf);
[*]	for (int c = 0; c < (temp.getLength() + 1); c++)
[*]	{
[*]		buf[c] = temp.buf[c] + n;
[*]	}
[*]	setName(buf);
[*]	return buf;
[*]}
[*]String& String::operator ++()
[*]{
[*]	delete [] buf;
[*]	buf = new char [sizeof(name) + 1];
[*]	strcpy_s(buf, sizeof(name), name);
[*]	for (int c = 0; c < (sizeof(name) + 1); c++)
[*]	{
[*]		buf[c] = name[c] + 1;
[*]	}
[*]	String& temp(*this);
[*]	//temp = this;
[*]	//&temp.setName(buf);
[*]	return temp;
[*]	//return& this
[*]} 
[*]String& String::operator --()
[*]{
[*]	delete [] buf;
[*]	buf = new char [sizeof(name) + 1];
[*]	strcpy_s(buf, sizeof(name), name);
[*]	for (int c = 0; c < (sizeof(name) + 1); c++)
[*]	{
[*]		buf[c] = name[c] - 1;
[*]	}
[*]	String temp(buf);
[*]	String& temp01(temp);
[*]	//temp.setName(buf);
[*]	return temp01;
[*]}
[*]String String::operator ++(int n)
[*]{
[*]	delete [] buf;
[*]	buf = new char [sizeof(name) + 1];
[*]	strcpy_s(buf, sizeof(name), name);
[*]	for (int c = 0; c < (sizeof(name) + 1); c++)
[*]	{
[*]		buf[c] = name[c] + n;
[*]	}
[*]	String temp(buf);
[*]	temp.setName(buf);
[*]	return temp;
[*]}
[*]String String::operator --(int n)
[*]{
[*]	delete [] buf;
[*]	buf = new char [sizeof(name) + 1];
[*]	strcpy_s(buf, sizeof(name), name);
[*]	for (int c = 0; c < (sizeof(name) + 1); c++)
[*]	{
[*]		buf[c] = name[c] - n;
[*]	}
[*]	String temp(buf);
[*]	temp.setName(buf);
[*]	return temp;
[*]}
[*]String String::substr(int n1, int n2)
[*]{
[*]	delete [] buf;
[*]	buf = new char [n2 - n1 +1];
[*]	for (int c = 0; c < (n2 - n1 +1); c++)
[*]		buf[c] = name[n1 + c];
[*]	
[*]	String temp(buf);
[*]	temp.setName(buf);
[*]	return temp;
[*]}
[*]ostream& String::operator<<(ostream& os, const String& str01)
[*]{
[*]	String temp(str01);
[*]	os << temp.name;
[*]    return os;
[*]}
[/LIST]
[LIST=1]
[*]#ifndef _REVERSE_H
[*]#define _REVERSE_H

[*]class ReverseString : public String 
[*]{
[*]	private:
[*]		char* reverse;
[*]	public:
[*]		ReverseString();
[*]		ReverseString(char* ch01);
[*]		ReverseString(const ReverseString& str01);
[*]		~ReverseString();
[*]		ReverseString operator~();
[*]};
[*]#endif
[/LIST]
[LIST=1]
[*]#include <iostream>
[*]#include <fstream>
[*]#include <stdlib.h>
[*]#include "string.h"
[*]#include "reverse.h"

[*]using namespace std;

[*]ReverseString::ReverseString()
[*]{
[*]	String::String();
[*]	reverse = new char[length + 1];
[*]}
[*]ReverseString::ReverseString(char* ch01)
[*]{
[*]	String::String(ch01);
[*]	reverse = new char[length + 1];
[*]}
[*]ReverseString::ReverseString(const ReverseString& str01)
[*]{
[*]	String::String(str01);
[*]	reverse = new char[length + 1];
[*]}
[*]ReverseString::~ReverseString()
[*]{	
[*]	delete [] reverse;
[*]}
[*]ReverseString ReverseString::operator ~()
[*]{
[*]	for (int c = 0; c <= length; c++)
[*]		reverse[c] = name[length - c];
[*]	
[*]	ReverseString temp(reverse);
[*]	return temp;
[*]}
[/LIST]
[LIST=1]
[*]#ifndef _CASE_H
[*]#define _CASE_H

[*]class CaseString : public String 
[*]{
[*]	private:
[*]		char *upper;
[*]		char *lower;
[*]	public:
[*]		CaseString();
[*]		CaseString(const CaseString &str01);
[*]		CaseString(char* ch);
[*]		~CaseString();
[*]		CaseString operator=(const CaseString &str01);
[*]		char *setUpper();
[*]		char *setLower();
[*]		void print();
[*]};
[*]#endif
[/LIST]
[LIST=1]
[*]#include <iostream>
[*]#include <fstream>
[*]#include <stdlib.h>
[*]#include "string.h"
[*]#include "case.h"

[*]using namespace std;
[*]extern ofstream csis;

[*]CaseString::CaseString()
[*]{
[*]	String::String();
[*]	upper = new char[length + 1];
[*]	lower = new char[length + 1];
[*]	upper = setUpper();
[*]	lower = setLower();
[*]}
[*]CaseString::CaseString(const CaseString &str01)
[*]{
[*]	String::String(str01);
[*]	upper = new char[length + 1];
[*]	lower = new char[length + 1];
[*]	upper = setUpper();
[*]	lower = setLower();
[*]}
[*]CaseString::CaseString(char *ch)
[*]{
[*]	String::String(ch);
[*]	upper = new char[length + 1];
[*]	lower = new char[length + 1];
[*]	upper = setUpper();
[*]	lower = setLower();
[*]}
[*]CaseString::~CaseString()
[*]{
[*]	delete [] upper;
[*]	delete [] lower;
[*]}
[*]char *CaseString::setLower()
[*]{
[*]	for (int c = 0; c <= length; c++)
[*]	{
[*]		if ((buf[c] >= 65) && (buf[c] <= 90))
[*]		{
[*]			lower[c] = buf[c] + 32;
[*]		}
[*]		else
[*]		{
[*]			lower[c] = buf[c];
[*]		}
[*]	}
[*]	return lower;
[*]}
[*]char *CaseString::setUpper()
[*]{
[*]	for (int c = 0; c <= length; c++)
[*]	{
[*]		if ((buf[c] >= 97) && (buf[c] <= 122))
[*]		{
[*]			upper[c] = buf[c] - 32;
[*]		}
[*]		else
[*]		{
[*]			upper[c] = buf[c];
[*]		}
[*]	}
[*]	return upper;
[*]}
[*]void CaseString::print()
[*]{
[*]	cout << upper << ", " << lower << endl;
[*]	csis << upper << ", " << lower << endl;
[*]}
[/LIST]

the strdrv.h and strdv.cpp have been provided by the teacher to test the program

[LIST=1]
[*]// strdrv.h
[*]#ifndef _STRDRV_H
[*]#define _STRDRV_H
[*]#include "string.h"
[*]#include "reverse.h"
[*]#include "case.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
[/LIST]
[LIST=1]
[*]// strdrv.cpp

[*]#include <iostream>
[*]#include <fstream>
[*]#include <stdlib.h>
[*]#include "strdrv.h"

[*]using namespace std;

[*]ofstream csis;

[*]int main() 
[*]{
[*]    csis.open("csis.dat");

[*]    test1();
[*]    test2();
[*]    test3();
[*]    test4();
[*]    test5();
[*]    test6();
[*]    test7();
[*]    test8();
[*]    test9();
[*]    test10();
[*]    test11();
[*]    test12();
[*]    test13();
[*]    test14();
[*]    test15();
[*]    test16();
[*]    test17();
[*]    test18();
[*]    test19();
[*]    test20();

[*]	csis.close();
[*]}
[*]void test1() 
[*]{
[*]    system("cls");

[*]    cout << "1. Testing: String default ctor." << endl << endl;
[*]    csis << "1. Testing: String default ctor." << endl << endl;

[*]    String s1;
[*]    s1.setName("s1");
[*]    s1.print();

[*]    wait();
[*]}
[*]void test2() 
[*]{
[*]    system("cls");

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

[*]    String s2("ABC");
[*]    s2.setName("s2");
[*]    s2.print();

[*]    wait();
[*]}
[*]void test3() 
[*]{
[*]    system("cls");

[*]    cout << "3. Testing: String one arg (char) ctor." << endl << endl;
[*]    csis << "3. Testing: String one arg (char) ctor." << endl << endl;

[*]    String s3('Z');
[*]    s3.setName("s3");
[*]    s3.print();

[*]    wait();
[*]}
[*]void test4() 
[*]{
[*]    system("cls");

[*]    cout << "4. Testing: String one arg (int) ctor." << endl << endl;
[*]    csis << "4. Testing: String one arg (int) ctor." << endl << endl;

[*]    String s4(10);
[*]    s4.setName("s4");
[*]    s4.print();

[*]    wait();
[*]}
[*]void test5() 
[*]{
[*]    system("cls");

[*]    cout << "5. Testing: String copy ctor." << endl << endl;
[*]    csis << "5. Testing: String copy ctor." << endl << endl;

[*]    String s5("Haley Laurel");
[*]    s5.setName("s5");
[*]    s5.print();
[*]    String t5(s5);
[*]    t5.setName("t5");
[*]    t5.print();

[*]    wait();
[*]}
[*]void test6() 
[*]{
[*]    system("cls");

[*]    cout << "6. Testing: String two arg (char, int) ctor." << endl << endl;
[*]	csis << "6. Testing: String two arg (char, int) ctor." << endl << endl;

[*]    String s6('*', 10);
[*]    s6.setName("s6");
[*]    s6.print();

[*]    wait();
[*]}
[*]void test7() 
[*]{
[*]    system("cls");

[*]    cout << "7. Testing: String assignment." << endl << endl;
[*]    csis << "7. Testing: String assignment." << endl << endl;

[*]    String s7("Samantha Morgan"), t7, u7;
[*]    s7.setName("s7");
[*]    t7.setName("t7");
[*]    u7.setName("u7");
[*]    t7 = u7 = s7;
[*]    s7.print();
[*]    t7.print();
[*]    u7.print();

[*]    wait();
[*]}
[*]void test8() 
[*]{
[*]    system("cls");

[*]    cout << "8. Testing: String assignment." << endl << endl;
[*]    csis << "8. Testing: String assignment." << endl << endl;

[*]    String s8("ABC");
[*]    s8.setName("s8");
[*]    s8 = s8;
[*]    s8.print();

[*]    wait();
[*]}
[*]void test9() 
[*]{
[*]    system("cls");

[*]    cout << "9. Testing: Implicit type conversion." << endl << endl;
[*]    csis << "9. Testing: Implicit type conversion." << endl << endl;

[*]    String s9;
[*]    s9 = "ABC";
[*]    s9.setName("s9");
[*]    s9.print();

[*]	wait();
[*]}
[*]void test10() 
[*]{
[*]    system("cls");

[*]    cout << "10. Testing: String concatenation." << endl << endl;
[*]    csis << "10. Testing: String concatenation." << endl << endl;

[*]    String s10("DEF");
[*]    String t10('H');
[*]    String u10("ABC" + s10 + "G" + t10 + 'I');
[*]    u10.setName("u10");
[*]    u10.print();
[*]    String v10('X' + u10);
[*]    v10.setName("v10");
[*]    v10.print();

[*]    wait();
[*]}
[*]void test11() 
[*]{
[*]    system("cls");

[*]    cout << "11. Testing: String concatenation." << endl << endl;
[*]    csis << "11. Testing: String concatenation." << endl << endl;

[*]    String s11('A');
[*]    String t11("BC");
[*]    s11.setName("s11");
[*]    t11.setName("t11");
[*]    s11 += s11 += t11 += 'D';
[*]    s11.print();
[*]    t11.print();

[*]    wait();
[*]}
[*]void test12() 
[*]{
[*]    system("cls");

[*]    cout << "12. Testing: String unary operator." << endl << endl;
[*]    csis << "12. Testing: String unary operator." << endl << endl;

[*]    String s12("Unary +");
[*]    String t12(+s12);
[*]    s12.setName("s12");
[*]    t12.setName("t12");
[*]    s12.print();
[*]    t12.print();
[*]    s12 = +s12;
[*]    s12.print();

[*]    wait();
[*]}
[*]void test13() 
[*]{
[*]    system("cls");

[*]    cout << "13. Testing: String comparison operators." << endl << endl;
[*]    csis << "13. Testing: String comparison operators." << endl << endl;

[*]    String s13("ABC"), t13("ABCD");
[*]    s13.setName("s13");
[*]    t13.setName("t13");
[*]    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() 
[*]{
[*]    system("cls");

[*]    cout << "14. Testing: Overloaded subscript operator." << endl << endl;
[*]    csis << "14. Testing: Overloaded subscript operator." << endl << endl;

[*]    String s14("C++ is fun.");
[*]    s14.setName("s14");

[*]    for (int i = -1; i <= s14.getLength(); i++) 
[*]	{
[*]        char& ch = s14[i];
[*]        if (ch != '\0')
[*]            ++ch;
[*]    }

[*]    s14.print();

[*]    wait();
[*]}
[*]void test15() 
[*]{
[*]    system("cls");

[*]    cout << "15. Testing: Pointer notation." << endl << endl;
[*]    csis << "15. Testing: Pointer notation." << endl << endl;

[*]    String s15("ABCDE");
[*]    s15.setName("s15");

[*]    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() 
[*]{
[*]    system("cls");

[*]    cout << "16. Testing: Increment and decrement operators." << endl << endl;
[*]    csis << "16. Testing: Increment and decrement operators." << endl << endl;

[*]    String s16("ABC");
[*]    String t16(++s16);
[*]    s16.setName("s16");
[*]    t16.setName("t16");
[*]    s16.print();
[*]    t16.print();
[*]    String u16("ABC");
[*]    String v16(u16++);
[*]    u16.setName("u16");
[*]    v16.setName("v16");
[*]    u16.print();
[*]    v16.print();
[*]    String w16("ABC");
[*]    String x16(--w16);
[*]    w16.setName("w16");
[*]    x16.setName("x16");
[*]    w16.print();
[*]    x16.print();
[*]    String y16("ABC");
[*]    String z16(y16--);
[*]    y16.setName("y16");
[*]    z16.setName("z16");
[*]    y16.print();
[*]    z16.print();

[*]    wait();
[*]}
[*]void test17() 
[*]{
[*]    system("cls");

[*]    cout << "17. Testing: Substr function." << endl << endl;
[*]    csis << "17. Testing: Substr function." << endl << endl;

[*]    String s17("Jai Guru Dev"), t17;
[*]    s17.setName("s17");
[*]    t17.setName("t17");
[*]    t17 = s17.substr(4, 8);
[*]    s17.print();
[*]    t17.print();

[*]    wait();
[*]}
[*]void test18() 
[*]{
[*]    system("cls");

[*]    cout << "18. Testing: Output function." << endl << endl;
[*]    csis << "18. Testing: Output function." << endl << endl;

[*]    String s18("Haley");
[*]    String t18("Laurel");
[*]    String u18("Stegman");

[*]    cout << s18 << t18 << u18;
[*]    cout << endl;
[*]    csis << endl;

[*]    wait();
[*]}
[*]void test19() 
[*]{
[*]    system("cls");

[*]    cout << "19. Testing: ReverseString class." << endl << endl;
[*]    csis << "19. Testing: ReverseString class." << endl << endl;

[*]    ReverseString s19("Purusha");
[*]    ReverseString t19;
[*]    s19.setName("s19");
[*]    t19.setName("t19");
[*]    t19 = ~s19;
[*]    s19.print();
[*]    t19.print();
[*]    ReverseString u19(~~s19);
[*]    u19.setName("u19");
[*]    u19.print();

[*]    wait();
[*]}
[*]void test20() 
[*]{
[*]    system("cls");

[*]    cout << "20. Testing: CaseString class." << endl << endl;
[*]    csis << "20. Testing: CaseString class." << endl << endl;

[*]    CaseString s20("BaLLooN");
[*]    CaseString t20;
[*]    s20.setName("s20");
[*]    t20.setName("t20");
[*]    t20 = s20;
[*]    s20.print();
[*]    t20.print();
[*]    CaseString u20(s20);
[*]    u20.setName("u20");
[*]    u20.print();

[*]	wait();
[*]}
[*]void wait() 
[*]{
[*]    char buf;

[*]	cout << endl << "Press any key to continue." << endl;
[*]    csis << endl << endl;
[*]    cin.get(buf);
[*]}
[/LIST]
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by losh177
0

I can't understand why you need additional comments to compiler messages in that case,
Consider line #94:

String String::operator +(const String& str01, const String& str02) ...

Where is this member function (incorrect) declaration in the class String definition? It's incorrect because of correct overloaded binary operator+ prototype is

String String::operator+(const String&);

And so on...

Another defects (it's not a complete list:():

1. Why you declare comparisons as friends? Why comparison operators return int? There is a wonderful (and natural) type in C++ - bool and the natural way to overload operator== and others is:

bool String::operator==(const String&) const;

2.Line #38:

buf[0] = NULL;

NULL is a macros defined as a pointer constant value. Why you are trying to assign a pointer to char?

3. Line #51 (and line #66, and other lines):

buf = new char[sizeof(str01.buf)+1];

A value of sizeof(str01.buf) is a pointer to char size (see line#8), it's not a length of C-string strlen(str91.buf) referred via buf pointer!

Try to correct the code step by step...

0

just to clarify, when overloading operators there is no need to specify the name of the data type

Also, what i'm trying by overloading the + operator is to get two strings and return them as a one.

Also for the boolean operator i have no idea why is that they are suppose to return and int instead of a bool. It makes no sense to me but i have not been able to get an answer from my teacher

On line #38

buf[0] = NULL;

I'm just trying to set the first member of the array as a null value, probably i'm using the wrong notacion

I will change sizeof() for strlen() , thanks

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.