| @@ -0,0 +1,201 @@ | ||
|
|
||
| #include <iostream> | ||
| #include <string.h> | ||
|
|
||
| #include "ANT_String.h" | ||
|
|
||
| using namespace std; | ||
|
|
||
| void main() | ||
| { | ||
| //Testing empty constructor. Pretty much nothing should happen here | ||
| //but there should be no error. | ||
| ANT_String Str1; | ||
| cout << "There was no error executing the empty copy constructor" << endl; | ||
| //test successful | ||
|
|
||
| //Testing constructor that takes a c type string. It should make a | ||
| //copy of the string we pass to it. | ||
| char myTestString[] = "This is a test string."; | ||
| ANT_String Str2(myTestString); | ||
| Str2.Display(); | ||
| cout << endl; | ||
| //now lets change myTestString and make sure it doesn't change | ||
| //the string value in our newly created object. | ||
| strcpy(myTestString, "Th1s 1s @ t3$t $tr1ng."); | ||
| Str2.Display(); | ||
| cout << endl; | ||
| //test successful | ||
|
|
||
| //Testing Compare function that takes char*. It should return an int indicating | ||
| //which string was larger. | ||
|
|
||
| char testString2[] = "I am pretty big."; | ||
| char testString3[] = "That string is wimpy."; | ||
| //making the string object the char* will be compared to. | ||
| ANT_String Str3(testString2); | ||
| //Comparing an output | ||
| int result = Str3.Compare(testString3); | ||
| if(result > 0) | ||
| cout << "testString2 was bigger than testString3" << endl; | ||
| if(result < 0) | ||
| cout << "testString3 was bigger than testString2" << endl; | ||
| if(result == 0) | ||
| cout << "The two strings were equal." << endl; | ||
| //testString3 should be bigger than testString2 | ||
| //test successful. | ||
|
|
||
| //Converting testString3 to object for testing Compare which takes object parameter | ||
| ANT_String Str4(testString3); | ||
| result = Str3.Compare(Str4); | ||
|
|
||
| if(result > 0) | ||
| cout << "Str3 was bigger than Str4" << endl; | ||
| if(result < 0) | ||
| cout << "Str4 was bigger than Str3" << endl; | ||
| if(result == 0) | ||
| cout << "The two string objects were equal." << endl; | ||
| //Str4 should be bigger than Str3 | ||
| //test successful | ||
|
|
||
| //Beging testing Concat (char* version) | ||
|
|
||
| char testString4[] = "Let's be "; | ||
| char testString5[] = "together!!!"; | ||
| char testString6[] = " Forever!!!"; | ||
|
|
||
| ANT_String Str5(testString4); | ||
| Str5.Concat(testString5); | ||
|
|
||
| Str5.Display(); | ||
| cout << endl; | ||
| //Should display "Let's be together!!!" on one line. | ||
| //Testing for object version | ||
| //test successful | ||
|
|
||
| ANT_String Str6(testString6); | ||
| Str5.Concat(Str6); | ||
| Str5.Display(); | ||
| cout << endl; | ||
| ////Should display "Let's be together!!! Forever!!!" on one line. | ||
|
|
||
|
|
||
|
|
||
| //Begin testing copy functions | ||
| char testString7[] = "I am a good string."; | ||
| char testString8[] = "I am a very evil string."; | ||
| char testString9[] = "Nay, I am the most evil string."; | ||
|
|
||
| ANT_String Str7(testString7); | ||
|
|
||
| Str7.Copy(testString8); | ||
| Str7.Display(); | ||
| cout << endl; | ||
|
|
||
| //Should display "I am a very evil string." | ||
| //test successful | ||
|
|
||
| ANT_String Str8(testString9); | ||
| Str7.Copy(Str8); | ||
| Str7.Display(); | ||
| cout << endl; | ||
|
|
||
| //Should display "Nay, I am the most evil string." | ||
| //test successful | ||
|
|
||
| //Begin testing length functions | ||
| char testString10[] = "abcd"; | ||
|
|
||
| ANT_String Str9(testString10); | ||
| result = Str9.Length(); | ||
|
|
||
| cout << "Length of 'abcd' is : " << result << endl; | ||
|
|
||
| //test successful. | ||
|
|
||
| //Beginning Operator testing | ||
|
|
||
| //testing = operator | ||
|
|
||
| char testString11[] = "woot woot!"; | ||
| char testString12[] = "blah"; | ||
|
|
||
| ANT_String Str10(testString11); | ||
| ANT_String Str11(testString12); | ||
|
|
||
| Str10 = Str11; | ||
|
|
||
| Str10.Display(); | ||
| cout << endl; | ||
|
|
||
| //"blah" should be displayed. | ||
| //test successful | ||
|
|
||
| //testing == operator | ||
|
|
||
| bool boolResult = (Str10 == Str11); | ||
| cout << boolResult << endl; | ||
|
|
||
| //test successful | ||
|
|
||
| //testing != operator | ||
|
|
||
| boolResult = (Str10 != Str11); | ||
| cout << boolResult << endl; | ||
|
|
||
| //test successful | ||
|
|
||
| //testing & operator | ||
|
|
||
| ANT_String Str12(Str10&Str11); | ||
| Str12.Display(); | ||
| cout << endl; | ||
|
|
||
| //test succesful | ||
|
|
||
| //testing &= operator | ||
|
|
||
| char testString13[] = "connect "; | ||
| char testString14[] = "four!"; | ||
|
|
||
| ANT_String Str13(testString13); | ||
| ANT_String Str14(testString14); | ||
|
|
||
| ANT_String Str15(Str13&=Str14); | ||
|
|
||
| Str13.Display(); | ||
| cout << endl; | ||
|
|
||
| //test successful | ||
|
|
||
| //testing << operator | ||
|
|
||
| ANT_String Str16; | ||
| cin >> Str16; | ||
| ANT_String Str17 = "testing 1 2 3"; | ||
| cout << Str17 << endl; | ||
| cout << Str16; | ||
|
|
||
| } | ||
|
|
||
| //OUTPUT | ||
|
|
||
| //There was no error executing the empty copy constructor | ||
| //This is a test string. | ||
| //This is a test string. | ||
| //testString3 was bigger than testString2 | ||
| //Str4 was bigger than Str3 | ||
| //Let's be together!!! | ||
| //Let's be together!!! Forever!!! | ||
| //I am a very evil string. | ||
| //Nay, I am the most evil string. | ||
| //Length of 'abcd' is : 4 | ||
| //blah | ||
| //0 | ||
| //1 | ||
| //blahblah | ||
| //connect four! | ||
| //hello derr | ||
| //☺☺☺☺☺☺☺☺☺☺ | ||
| //Press any key to continue . . . | ||
|
|
| @@ -0,0 +1,46 @@ | ||
| #ifndef ARRAY_H | ||
| #define ARRAY_H | ||
|
|
||
| template <class T> | ||
| class Array | ||
| { | ||
| public: | ||
| Array (); | ||
| Array (const Array <T> &); | ||
| Array (long); | ||
| Array (int); | ||
| ~Array (); | ||
| T & operator = (const Array <T> &); | ||
| void Test (); | ||
| private: | ||
| T * pArray; | ||
| long NumElements; | ||
| }; | ||
|
|
||
| template <class T> | ||
| Array <T>::Array () | ||
| { | ||
| pArray = new T [10]; | ||
| } | ||
|
|
||
| template <class T> | ||
| Array <T>::~Array () | ||
| { | ||
| delete [] pArray; | ||
| } | ||
|
|
||
| template <class T> | ||
| Array <T>::Array (const Array <T> & A) | ||
| { | ||
| pArray = new T [10]; | ||
| for (int i = 0; i < 10; i++) | ||
| pArray [i] = A.pArray [i]; | ||
| } | ||
|
|
||
| template <class T> | ||
| void Array <T>::Test () | ||
| { | ||
| dfv fmf f // template methods are not compiled unless they are called | ||
| } | ||
|
|
||
| #endif |
| @@ -0,0 +1,81 @@ | ||
| #ifndef FIXED_ARRAY_H | ||
| #define FIXED_ARRAY_H | ||
|
|
||
| template <class T = int, long Lower = 0, long Upper = 10> // Lower and Upper are constants | ||
| class FixedArray | ||
| { | ||
| public: | ||
| FixedArray (); | ||
| FixedArray (const FixedArray <T, Lower, Upper> &); | ||
| FixedArray <T, Lower, Upper> & operator = (const FixedArray <T, Lower, Upper> &); | ||
| FixedArray <T, Lower, Upper> & GetAt (const FixedArray <T, Lower, Upper> &); | ||
| FixedArray <T, Lower, Upper> & operator = (FixedArray <T, Lower, Upper> &); | ||
| FixedArray <T, Lower, Upper> & SetAt (FixedArray <T, Lower, Upper> &); | ||
| T & operator [] (long); | ||
| const T & operator [] (long) const; | ||
| private: | ||
| T A [Upper - Lower + 1]; | ||
| }; | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| FixedArray <T, Lower, Upper>::FixedArray () | ||
| { | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| FixedArray <T, Lower, Upper>::FixedArray (const FixedArray <T, Lower, Upper> & Arr) | ||
| { | ||
| for (long i = 0; i < (Upper - Lower + 1); i++) | ||
| A [i] = Arr.A [i]; | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| FixedArray <T, Lower, Upper> & FixedArray <T, Lower, Upper>::operator = (const FixedArray <T, Lower, Upper> & Arr) | ||
| { | ||
| for (long i = 0; i < (Upper - Lower + 1); i++) | ||
| A [i] = Arr.A [i]; | ||
| return *this; | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| FixedArray<T, Lower, Upper> & FixedArray <T, Lower, Upper>::GetAt(const FixedArray <T, Lower, Upper>& Arr) | ||
| { | ||
| for (long i = 0; i < (Upper - Lower + 1); i++) | ||
| A [i] = Arr.A [i]; | ||
| return *this; | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| FixedArray <T, Lower, Upper> & FixedArray <T, Lower, Upper>::operator = (FixedArray <T, Lower, Upper> & Arr) | ||
| { | ||
| for (long i = 0; i < (Upper - Lower + 1); i++) | ||
| A [i] = Arr.A [i]; | ||
| return *this; | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| FixedArray<T, Lower, Upper> & FixedArray <T, Lower, Upper>::SetAt(FixedArray <T, Lower, Upper>& Arr) | ||
| { | ||
| for (long i = 0; i < (Upper - Lower + 1); i++) | ||
| A [i] = Arr.A [i]; | ||
| return *this; | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| T & FixedArray <T, Lower, Upper>::operator [] (long i) | ||
| { | ||
| return A [i - Lower]; | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| const T & FixedArray <T, Lower, Upper>::operator [] (long i) const | ||
| { | ||
| return A [i - Lower]; | ||
| } | ||
|
|
||
| template <class T, long Lower, long Upper> | ||
| void Func2 (FixedArray <T, Lower, Upper> & Arr) | ||
| { | ||
| } | ||
|
|
||
| #endif |
| @@ -0,0 +1,43 @@ | ||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| #include "FixedArray.h" | ||
| #include "Array.h" | ||
|
|
||
| #define XXX FixedArray<int, -2, 2> | ||
|
|
||
| void Func (const FixedArray <int, -5, 5> &); | ||
|
|
||
| void main () | ||
| { | ||
| FixedArray <int, -5, 5> A1; | ||
| FixedArray <int, -5, 5> A2; | ||
| FixedArray <int, 0, 10> A3; | ||
| FixedArray <> A4; | ||
| FixedArray <int> A5; | ||
|
|
||
| // FixedArray <FixedArray <int ,-2, 2>, 5, 8> Array2D; | ||
| FixedArray <XXX, 5, 8> Array2D; | ||
|
|
||
| A1 = A2; | ||
| // A1 = A3; | ||
| A3 = A4; | ||
|
|
||
| Func (A2); | ||
| // Func (A3); | ||
|
|
||
| Func2 (A1); | ||
| Func2 (A3); | ||
| A1 [0] = 5; | ||
| Func (A1); | ||
|
|
||
| Func2 (Array2D [6]); | ||
|
|
||
| cout << Array2D [5] [0] << endl; | ||
| } | ||
|
|
||
| void Func (const FixedArray <int, -5, 5> & Arr) | ||
| { | ||
| cout << Arr [0] << endl; | ||
| } |
| @@ -0,0 +1,20 @@ | ||
|
|
||
| Microsoft Visual Studio Solution File, Format Version 11.00 | ||
| # Visual Studio 2010 | ||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "atharp_Program4", "atharp_Program4.vcxproj", "{8FA3C8FE-6D2A-41F6-B4AD-B87F722B80DF}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Win32 = Debug|Win32 | ||
| Release|Win32 = Release|Win32 | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {8FA3C8FE-6D2A-41F6-B4AD-B87F722B80DF}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
| {8FA3C8FE-6D2A-41F6-B4AD-B87F722B80DF}.Debug|Win32.Build.0 = Debug|Win32 | ||
| {8FA3C8FE-6D2A-41F6-B4AD-B87F722B80DF}.Release|Win32.ActiveCfg = Release|Win32 | ||
| {8FA3C8FE-6D2A-41F6-B4AD-B87F722B80DF}.Release|Win32.Build.0 = Release|Win32 | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| EndGlobal |
| @@ -0,0 +1,87 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup Label="ProjectConfigurations"> | ||
| <ProjectConfiguration Include="Debug|Win32"> | ||
| <Configuration>Debug</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| <ProjectConfiguration Include="Release|Win32"> | ||
| <Configuration>Release</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| </ItemGroup> | ||
| <PropertyGroup Label="Globals"> | ||
| <ProjectGuid>{8FA3C8FE-6D2A-41F6-B4AD-B87F722B80DF}</ProjectGuid> | ||
| <Keyword>Win32Proj</Keyword> | ||
| <RootNamespace>atharp_Program4</RootNamespace> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
| <ConfigurationType>Application</ConfigurationType> | ||
| <UseDebugLibraries>true</UseDebugLibraries> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
| <ConfigurationType>Application</ConfigurationType> | ||
| <UseDebugLibraries>false</UseDebugLibraries> | ||
| <WholeProgramOptimization>true</WholeProgramOptimization> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
| <ImportGroup Label="ExtensionSettings"> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <PropertyGroup Label="UserMacros" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <LinkIncremental>true</LinkIncremental> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <LinkIncremental>false</LinkIncremental> | ||
| </PropertyGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <ClCompile> | ||
| <PrecompiledHeader> | ||
| </PrecompiledHeader> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <Optimization>Disabled</Optimization> | ||
| <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| </ClCompile> | ||
| <Link> | ||
| <SubSystem>Console</SubSystem> | ||
| <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <ClCompile> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <PrecompiledHeader> | ||
| </PrecompiledHeader> | ||
| <Optimization>MaxSpeed</Optimization> | ||
| <FunctionLevelLinking>true</FunctionLevelLinking> | ||
| <IntrinsicFunctions>true</IntrinsicFunctions> | ||
| <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| </ClCompile> | ||
| <Link> | ||
| <SubSystem>Console</SubSystem> | ||
| <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
| <OptimizeReferences>true</OptimizeReferences> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemGroup> | ||
| <ClInclude Include="Array.h" /> | ||
| <ClInclude Include="FixedArray.h" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="Array.cpp" /> | ||
| <ClCompile Include="Main.cpp" /> | ||
| </ItemGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
| <ImportGroup Label="ExtensionTargets"> | ||
| </ImportGroup> | ||
| </Project> |
| @@ -0,0 +1,210 @@ | ||
| #include "ANT_String.h" | ||
| #include <string.h> | ||
| #include <cassert> | ||
|
|
||
| //Implementation Section | ||
|
|
||
| //constructors | ||
| ANT_String::ANT_String(): numChars(0) | ||
| { | ||
| myStrPtr = new char [numChars + 1]; | ||
| myStrPtr[0] = '\0'; | ||
|
|
||
| } | ||
|
|
||
| ANT_String::ANT_String(char* Str) | ||
| { | ||
| //this constructor will accept a string and make an object | ||
| //containing a copy of the string passed to it. | ||
| numChars = strlen(Str); | ||
| myStrPtr = new char[numChars +1 ]; | ||
| strcpy((*this).myStrPtr, Str); | ||
| } | ||
|
|
||
| ANT_String::ANT_String(const char* Str) | ||
| { | ||
| //this constructor will accept a string and make an object | ||
| //containing a copy of the string passed to it. | ||
| numChars = strlen(Str); | ||
| myStrPtr = new char[numChars +1 ]; | ||
| strcpy((*this).myStrPtr, Str); | ||
| } | ||
|
|
||
| ANT_String::ANT_String(ANT_String& StrObj) | ||
| { | ||
| //This constructor will accept an object and make an object | ||
| //containing a copy of the string passed to it. | ||
| numChars = StrObj.numChars; | ||
| myStrPtr = new char[numChars +1]; | ||
| strcpy((*this).myStrPtr, StrObj.myStrPtr); | ||
| } | ||
|
|
||
| ANT_String::~ANT_String() | ||
| { | ||
| delete[] myStrPtr; | ||
| } | ||
|
|
||
| //funtions | ||
| ANT_String& ANT_String::Concat(const char* Str) | ||
| { | ||
| char* tmpPtr = new char[numChars + 1]; | ||
| strcpy(tmpPtr, myStrPtr); | ||
| myStrPtr[numChars] = '\0';// | ||
|
|
||
| delete[] myStrPtr; | ||
| myStrPtr = new char [numChars + strlen(Str) + 1]; | ||
|
|
||
| strcpy(myStrPtr, tmpPtr); | ||
| strcpy(myStrPtr + numChars, Str); | ||
| numChars+=strlen(Str); | ||
|
|
||
| return *this; | ||
| } | ||
|
|
||
| ANT_String& ANT_String::Concat(const ANT_String& Str) | ||
| { | ||
| char* tmpPtr = new char [strlen(myStrPtr) + 1]; | ||
| strcpy(tmpPtr, myStrPtr); | ||
|
|
||
| delete [] myStrPtr; | ||
| myStrPtr = new char [numChars + Str.numChars + 1]; | ||
|
|
||
| strcpy(myStrPtr, tmpPtr); | ||
| strcpy(myStrPtr + numChars, Str.myStrPtr); | ||
| numChars += Str.numChars; | ||
|
|
||
| return *this; | ||
| } | ||
|
|
||
| char* ANT_String::ConcatVirgin(const char* Str) | ||
| { | ||
| char* tmpPtr = new char[numChars + 1]; | ||
| strcpy(tmpPtr, myStrPtr); | ||
| strcpy(myStrPtr + numChars, Str); | ||
|
|
||
| return tmpPtr; | ||
| } | ||
|
|
||
| char* ANT_String::ConcatVirgin(const ANT_String& Str) | ||
| { | ||
| char* tmpPtr = new char[strlen(myStrPtr) + 1]; | ||
| strcpy(tmpPtr, myStrPtr); | ||
| strcpy(myStrPtr+numChars, Str.myStrPtr); | ||
| return tmpPtr; | ||
| } | ||
|
|
||
| ANT_String& ANT_String::Copy(const char* str) | ||
| { | ||
| if(strlen(str)> numChars) | ||
| { | ||
| delete[] myStrPtr; | ||
| myStrPtr = new char [strlen(str) +1]; | ||
| strcpy(myStrPtr, str); | ||
| } | ||
| else; | ||
| numChars = strlen(str); | ||
| strcpy(myStrPtr, str); | ||
| return *this; | ||
| } | ||
|
|
||
| ANT_String& ANT_String::Copy(const ANT_String& str) | ||
| { | ||
| if(str.numChars> numChars) | ||
| { | ||
| delete[] myStrPtr; | ||
| myStrPtr = new char [str.numChars +1]; | ||
| strcpy(myStrPtr,str.myStrPtr); | ||
| } | ||
| else; | ||
| numChars = str.numChars; | ||
| strcpy(myStrPtr, str.myStrPtr); | ||
| return *this; | ||
| } | ||
|
|
||
| char* ANT_String::getString() | ||
| { | ||
| return myStrPtr; | ||
| } | ||
|
|
||
| //operators | ||
|
|
||
| ANT_String& ANT_String::operator=(ANT_String& myStringObj) | ||
| { | ||
| return (*this).Copy(myStringObj); | ||
| } | ||
|
|
||
| ANT_String& ANT_String::operator=(char* myCharPtr) | ||
| { | ||
| Copy(myCharPtr); | ||
| return (*this); | ||
| } | ||
|
|
||
| bool ANT_String::operator==(ANT_String& myStringObj) | ||
| { | ||
| return ((*this).Compare(myStringObj) == 0); | ||
| } | ||
|
|
||
| bool ANT_String::operator==(const ANT_String& myStringObj)const | ||
| { | ||
| return (Compare(myStringObj) == 0); | ||
| } | ||
|
|
||
| bool ANT_String::operator!=(ANT_String& myStringObj) | ||
| { | ||
| return !((*this).Compare(myStringObj)); | ||
| } | ||
|
|
||
| ANT_String& ANT_String::operator&(const ANT_String& myStringObj) | ||
| { | ||
|
|
||
| (*this).ConcatVirgin(myStringObj.myStrPtr); | ||
| return *this; | ||
| } | ||
|
|
||
| void ANT_String::operator&=(const ANT_String& myStringObj) | ||
| { | ||
| (*this).Concat(myStringObj.myStrPtr); | ||
| } | ||
|
|
||
| bool ANT_String::operator>(const ANT_String& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)<0); | ||
| } | ||
|
|
||
| bool ANT_String::operator>=(const ANT_String& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)<=0); | ||
| } | ||
|
|
||
| bool ANT_String::operator<(const ANT_String& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)>0); | ||
| } | ||
|
|
||
| bool ANT_String::operator<=(const ANT_String& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)>=0); | ||
| } | ||
|
|
||
| inline ostream & operator<<(ostream & out, const ANT_String & S) | ||
| { | ||
| return S.Display(out); | ||
|
|
||
| } | ||
|
|
||
| inline istream & operator>>(istream& in, ANT_String& S) | ||
| { | ||
| S.myStrPtr = ReadString(); | ||
| return in; | ||
| } | ||
|
|
||
|
|
||
| char ANT_String::operator [] (long i) | ||
| { | ||
| return myStrPtr[i]; | ||
| } | ||
|
|
||
| char ANT_String::operator [] (long i) const | ||
| { | ||
| return myStrPtr[i]; | ||
| } |
| @@ -0,0 +1,88 @@ | ||
| #ifndef ANT_STRING_H | ||
| #define ANT_STRING_H | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| typedef unsigned int uint; | ||
|
|
||
| class ANT_String | ||
| { | ||
| public: //member function prototypes go here. | ||
|
|
||
| ANT_String(); | ||
| ANT_String(char*); | ||
| ANT_String(const char*); | ||
| ANT_String(ANT_String&); | ||
| ~ANT_String(); | ||
|
|
||
| ostream& Display(ostream & = cout) const; | ||
| int Compare (const char*)const; | ||
| int Compare (const ANT_String&)const; | ||
| ANT_String& Concat(const char*); | ||
| ANT_String& Concat(const ANT_String&); | ||
| char* ConcatVirgin(const char*); | ||
| char* ConcatVirgin(const ANT_String&); | ||
| virtual ANT_String& Copy(const char*); | ||
| virtual ANT_String& Copy(const ANT_String&); | ||
| int Length(); | ||
| int Length()const; | ||
| char* getString(); | ||
|
|
||
| //operators | ||
| ANT_String& operator = ( ANT_String &); | ||
| ANT_String& operator = (char* myCharPtr); | ||
| bool operator == ( ANT_String&) ; | ||
| bool operator == ( const ANT_String&)const ; | ||
| bool operator == ( char []) ; | ||
| bool operator != ( ANT_String &); | ||
| ANT_String & operator & (const ANT_String &); | ||
| void operator &= (const ANT_String &); | ||
| bool operator>(const ANT_String&); | ||
| bool operator>=(const ANT_String&); | ||
| bool operator<(const ANT_String&); | ||
| bool operator<=(const ANT_String&); | ||
| char operator [] (long i) const; | ||
| char operator [] (long i); | ||
|
|
||
| //friends | ||
| friend extern ostream& operator<<(ostream&, const ANT_String&); | ||
| friend extern istream& operator>>(istream&, ANT_String&); | ||
| friend char * ReadString (); | ||
|
|
||
|
|
||
| protected: | ||
| uint numChars; | ||
| char* myStrPtr; | ||
| }; | ||
|
|
||
| inline ostream& ANT_String::Display (ostream& out)const | ||
| { | ||
| return out << myStrPtr; | ||
| } | ||
|
|
||
| inline int ANT_String::Compare (const char* Str)const | ||
| { | ||
| return strcmp(myStrPtr, Str); | ||
| } | ||
|
|
||
| inline int ANT_String::Compare(const ANT_String& StrObj)const | ||
| { | ||
| return(strcmp(myStrPtr, StrObj.myStrPtr)); | ||
| } | ||
|
|
||
|
|
||
| inline int ANT_String::Length() | ||
| { | ||
| return numChars; | ||
| } | ||
|
|
||
| inline int ANT_String::Length() const | ||
| { | ||
| return numChars; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| #endif |
| @@ -0,0 +1,179 @@ | ||
| #include <iostream> | ||
| #include <cassert> | ||
| #include <cctype> | ||
|
|
||
| #include "ANT_String.h" | ||
| #include "ReadString.h" | ||
| #include "DigitString.h" | ||
|
|
||
| DigitString::DigitString() | ||
| { | ||
| numChars = 0; | ||
| myStrPtr = new char [numChars + 1]; | ||
| myStrPtr[0] = '\0'; | ||
| } | ||
|
|
||
| DigitString::DigitString(char* str) | ||
| { | ||
| Copy((const char *) str); | ||
| assert(CheckDigits()); | ||
| } | ||
|
|
||
| DigitString::DigitString(const char* str) | ||
| { | ||
| Copy((const char *) str); | ||
| assert(CheckDigits()); | ||
| } | ||
|
|
||
| DigitString::DigitString(ANT_String& ANTStr) | ||
| { | ||
| //Copy(ANTStr); | ||
| numChars = ANTStr.Length(); | ||
| myStrPtr = new char[numChars +1]; | ||
| strcpy((*this).myStrPtr, ANTStr.getString() ); | ||
| assert(CheckDigits()); | ||
| } | ||
|
|
||
| DigitString::DigitString(DigitString& dStr) | ||
| { | ||
| Copy(dStr); | ||
| assert(CheckDigits()); | ||
| } | ||
|
|
||
| DigitString& DigitString::Copy(const char* str ) | ||
| { | ||
| ANT_String::Copy(str); | ||
| //CheckDigits(); | ||
| return * this; | ||
| } | ||
|
|
||
| DigitString& DigitString::Copy(const DigitString& str) | ||
| { | ||
| ANT_String::Copy(str); | ||
| //CheckDigits(); | ||
| return * this; | ||
| } | ||
|
|
||
| bool DigitString::CheckDigits() throw(char) | ||
| { | ||
| char NON_DIGIT_EXCEPTION; | ||
| static bool isDigits; | ||
| isDigits = true; | ||
|
|
||
| try | ||
| { | ||
| for (int i = 0; i < Length(); i++) | ||
| { | ||
| if( isalpha(myStrPtr[i]) || ispunct(myStrPtr[i])) | ||
| { | ||
| NON_DIGIT_EXCEPTION = myStrPtr[i]; | ||
| throw NON_DIGIT_EXCEPTION; | ||
| } | ||
| } | ||
| } | ||
| catch (char c) | ||
| { | ||
| cout << "Character: " << c << " is not a number. Please enter a completely numeric string." << endl; | ||
| isDigits = false; | ||
| } | ||
|
|
||
| return isDigits; | ||
| } | ||
|
|
||
| DigitString& DigitString::operator=(const char* str) | ||
| { | ||
| return Copy(str); | ||
| } | ||
|
|
||
| DigitString& DigitString::operator=(const DigitString& str) | ||
| { | ||
| return Copy(str); | ||
| } | ||
|
|
||
| DigitString & DigitString::operator &(const DigitString & myStringObj) | ||
| { | ||
| Concat (myStringObj); | ||
| return * this; | ||
| } | ||
|
|
||
| ostream& operator<<(ostream& out, const DigitString& S) | ||
| { | ||
| return S.Display(out); | ||
| } | ||
|
|
||
| istream& operator>>(istream& in, DigitString& S) | ||
| { | ||
|
|
||
| do | ||
| { | ||
| S.Copy(ReadString()); | ||
|
|
||
| } | ||
| while( !(S.CheckDigits()) ); | ||
| return in; | ||
| } | ||
|
|
||
| /*bool DigitString::operator==(DigitString& myStringObj) | ||
| { | ||
| return ((*this).Compare(myStringObj) == 0); | ||
| } | ||
| bool DigitString::operator==(const DigitString& myStringObj)const | ||
| { | ||
| return (Compare(myStringObj) == 0); | ||
| } | ||
| bool DigitString::operator!=(DigitString& myStringObj) | ||
| { | ||
| return !((*this).Compare(myStringObj)); | ||
| } | ||
| void DigitString::operator&=(const DigitString& myStringObj) | ||
| { | ||
| (*this).Concat(myStringObj.myStrPtr); | ||
| } | ||
| bool DigitString::operator>(const DigitString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)<0); | ||
| } | ||
| bool DigitString::operator>=(const DigitString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)<=0); | ||
| } | ||
| bool DigitString::operator<(const DigitString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)>0); | ||
| } | ||
| bool DigitString::operator<=(const DigitString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)>=0); | ||
| } | ||
| inline ostream & operator<<(ostream & out, const DigitString & S) | ||
| { | ||
| return S.Display(out); | ||
| } | ||
| inline istream & operator>>(istream& in, DigitString& S) | ||
| { | ||
| S.myStrPtr = ReadString(); | ||
| return in; | ||
| } | ||
| char DigitString::operator [] (long i) | ||
| { | ||
| return myStrPtr[i]; | ||
| } | ||
| char DigitString::operator [] (long i) const | ||
| { | ||
| return myStrPtr[i]; | ||
| }*/ |
| @@ -0,0 +1,36 @@ | ||
| #ifndef DIGIT_STRING_H | ||
| #define DIGIT_STRING_H | ||
|
|
||
| #include "ANT_String.h" | ||
| #include "ReadString.h" | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| class DigitString : public ANT_String | ||
| { | ||
| public: | ||
| DigitString(); | ||
| explicit DigitString(char*); | ||
| explicit DigitString(const char*); | ||
| explicit DigitString(ANT_String&); | ||
| explicit DigitString(DigitString&); | ||
|
|
||
| istream& READ(istream& In); | ||
| DigitString& Copy(const char*); | ||
| DigitString& Copy(const DigitString&); | ||
| bool CheckDigits() throw(char); | ||
| DigitString& operator=(const char*); | ||
| DigitString& operator=(const DigitString &); | ||
| DigitString& operator &(const DigitString &); | ||
|
|
||
| friend extern ostream& operator<<(ostream&, const DigitString&); | ||
| friend extern istream& operator>>(istream&, DigitString&); | ||
| friend char * ReadString (); | ||
|
|
||
|
|
||
| }; | ||
|
|
||
|
|
||
| #endif |
| @@ -0,0 +1,39 @@ | ||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| #include <memory.h> | ||
| #include <conio.h> | ||
|
|
||
| #include "ReadString.h" | ||
|
|
||
|
|
||
| char * ReadString () | ||
| { | ||
| const int StartSize (50); | ||
| int CurrentNumChars (0); | ||
| int CurrentSize (StartSize); | ||
| char * pStr; | ||
| char c; | ||
|
|
||
| pStr = new char [StartSize + 1]; | ||
| //SkipSpaces (); | ||
| while ((c = cin.get ()) != '\n') | ||
| { | ||
| pStr [CurrentNumChars] = c; | ||
| CurrentNumChars++; | ||
| if (CurrentNumChars >= CurrentSize) | ||
| { | ||
| char * pTemp; | ||
|
|
||
| CurrentSize += StartSize; | ||
| pTemp = new char [CurrentSize + 1]; | ||
| memcpy (pTemp, pStr, CurrentNumChars); | ||
| delete [] pStr; | ||
| pStr = pTemp; | ||
| } | ||
| else; | ||
| } | ||
| pStr [CurrentNumChars] = '\0'; | ||
| return pStr; | ||
| } |
| @@ -0,0 +1,6 @@ | ||
| #ifndef READ_STRING_H | ||
| #define READ_STRING_H | ||
|
|
||
| char * ReadString (); | ||
|
|
||
| #endif |
| @@ -0,0 +1,164 @@ | ||
| #include "UppercaseString.h" | ||
| #include "ANT_String.h" | ||
| #include <cassert> | ||
| #include <string.h> | ||
| #include <cctype> | ||
|
|
||
| UpperCaseString::UpperCaseString() | ||
| { | ||
| numChars = 0; | ||
| myStrPtr = new char [numChars + 1]; | ||
| myStrPtr[0] = '\0'; | ||
| } | ||
|
|
||
| UpperCaseString::UpperCaseString(char* str) | ||
| { | ||
| Copy((const char *) str); | ||
| ToUpperCase(); | ||
| } | ||
|
|
||
| UpperCaseString::UpperCaseString(const char* str) | ||
| { | ||
| Copy((const char *) str); | ||
| ToUpperCase(); | ||
| } | ||
|
|
||
| UpperCaseString::UpperCaseString(ANT_String& ANTStr) | ||
| { | ||
| Copy(ANTStr); | ||
| ToUpperCase(); | ||
| } | ||
|
|
||
| UpperCaseString::UpperCaseString(UpperCaseString& uStr) | ||
| { | ||
| Copy(uStr); | ||
| ToUpperCase(); | ||
| } | ||
|
|
||
|
|
||
| //FUNCTIONS | ||
| void UpperCaseString::ToUpperCase() | ||
| { | ||
| for (int i = 0; i < Length(); i++) | ||
| { | ||
| myStrPtr[i] = toupper(myStrPtr[i]); | ||
| } | ||
| } | ||
|
|
||
| UpperCaseString& UpperCaseString::Copy(const char* str) | ||
| { | ||
| ANT_String::Copy(str); | ||
| ToUpperCase(); | ||
| return * this; | ||
| } | ||
|
|
||
| UpperCaseString& UpperCaseString::Copy(const UpperCaseString & str) | ||
| { | ||
| ANT_String::Copy(str); | ||
| ToUpperCase(); | ||
| return * this; | ||
| } | ||
|
|
||
| UpperCaseString& UpperCaseString::Copy(const ANT_String & str) | ||
| { | ||
| ANT_String::Copy(str); | ||
| ToUpperCase(); | ||
| return * this; | ||
| } | ||
|
|
||
| UpperCaseString& UpperCaseString::operator=(const char* str) | ||
| { | ||
| return Copy(str); | ||
| } | ||
|
|
||
| UpperCaseString& UpperCaseString::operator=(const UpperCaseString & str) | ||
| { | ||
| return Copy(str); | ||
| } | ||
|
|
||
| UpperCaseString & UpperCaseString::operator &(const UpperCaseString & myStringObj) | ||
| { | ||
| Concat (myStringObj); | ||
| return * this; | ||
| } | ||
|
|
||
| ostream & operator<<(ostream & out, const UpperCaseString & S) | ||
| { | ||
| return S.Display(out); | ||
|
|
||
| } | ||
|
|
||
| istream & operator>>(istream& in, UpperCaseString& S) | ||
| { | ||
| S.Copy(ReadString()); | ||
| return in; | ||
| } | ||
|
|
||
| /*bool UpperCaseString::operator==(UpperCaseString& myStringObj) | ||
| { | ||
| return ((*this).Compare(myStringObj) == 0); | ||
| } | ||
| bool UpperCaseString::operator==(const UpperCaseString& myStringObj)const | ||
| { | ||
| return (Compare(myStringObj) == 0); | ||
| } | ||
| bool UpperCaseString::operator!=(UpperCaseString& myStringObj) | ||
| { | ||
| return !((*this).Compare(myStringObj)); | ||
| } | ||
| void UpperCaseString::operator&=(const UpperCaseString& myStringObj) | ||
| { | ||
| (*this).Concat(myStringObj.myStrPtr); | ||
| } | ||
| bool UpperCaseString::operator>(const UpperCaseString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)<0); | ||
| } | ||
| bool UpperCaseString::operator>=(const UpperCaseString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)<=0); | ||
| } | ||
| bool UpperCaseString::operator<(const UpperCaseString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)>0); | ||
| } | ||
| bool UpperCaseString::operator<=(const UpperCaseString& myStringObj) | ||
| { | ||
| return((*this).Compare(myStringObj)>=0); | ||
| } | ||
| inline ostream & operator<<(ostream & out, const UpperCaseString & S) | ||
| { | ||
| return S.Display(out); | ||
| } | ||
| inline istream & operator>>(istream& in, UpperCaseString& S) | ||
| { | ||
| S.myStrPtr = ReadString(); | ||
| return in; | ||
| } | ||
| char UpperCaseString::operator [] (long i) | ||
| { | ||
| return myStrPtr[i]; | ||
| } | ||
| char UpperCaseString::operator [] (long i) const | ||
| { | ||
| return myStrPtr[i]; | ||
| }*/ | ||
|
|
||
|
|
||
|
|
||
|
|
| @@ -0,0 +1,39 @@ | ||
| #ifndef UPPER_CASE_STRING_H | ||
| #define UPPER_CASE_STRING_H | ||
|
|
||
| #include <cctype> | ||
| #include <iostream> | ||
|
|
||
| #include "ANT_String.h" | ||
|
|
||
| using namespace std; | ||
|
|
||
| class UpperCaseString : public ANT_String | ||
| { | ||
| public: | ||
|
|
||
| //constructors | ||
| UpperCaseString(); | ||
| explicit UpperCaseString(char*); | ||
| explicit UpperCaseString(const char*); | ||
| explicit UpperCaseString(ANT_String&); | ||
| explicit UpperCaseString(UpperCaseString&); | ||
|
|
||
| //functions | ||
| UpperCaseString& Copy(const char*); | ||
| UpperCaseString& Copy(const UpperCaseString &); | ||
| UpperCaseString& Copy(const ANT_String &); | ||
|
|
||
| void ToUpperCase(); | ||
|
|
||
| //operators | ||
| UpperCaseString& operator=(const char*); | ||
| UpperCaseString& operator=(const UpperCaseString &); | ||
| UpperCaseString& operator &(const UpperCaseString &); | ||
| friend ostream & operator<<(ostream & out, const UpperCaseString & S); | ||
| friend istream & operator>>(istream& in, UpperCaseString& S); | ||
|
|
||
|
|
||
| }; | ||
|
|
||
| #endif |
| @@ -0,0 +1,185 @@ | ||
| #include <iostream> | ||
| #include "ANT_String.h" | ||
| #include "ReadString.h" | ||
| #include "UppercaseString.h" | ||
| #include "DigitString.h" | ||
|
|
||
| using namespace std; | ||
|
|
||
| void main() | ||
| { | ||
| cout << "Testing for the UPPERCASE CLASS: " << endl << endl << endl; | ||
| UpperCaseString UStr1("hello hello hello"); | ||
| UpperCaseString UStr2("Hello there!"); | ||
| UpperCaseString UStr3("Alright already!"); | ||
|
|
||
| cout << "Ustr1 = " << UStr1 << endl; | ||
| cout << "Ustr2 = " << UStr2 << endl; | ||
| cout << "Ustr3 = " << UStr3 << endl; | ||
|
|
||
| UStr1 = UStr2; | ||
|
|
||
| cout << "After assignment UStr1 is now: " << UStr1 << endl; | ||
|
|
||
|
|
||
| cout << "Testing == operator: " << endl; | ||
| if(UStr1 == UStr2) | ||
| cout << "UStr1 and UStr2 are equal." << endl; | ||
| else | ||
| cout << "UStr1 and UStr2 are NOT equal." << endl; | ||
|
|
||
| if(UStr1 == UStr3) | ||
| cout << "UStr1 and UStr3 are equal." << endl; | ||
| else | ||
| cout << "UStr1 and UStr3 are NOT equal." << endl; | ||
|
|
||
|
|
||
| cout << "Testing < > <= >= Operators:" << endl; | ||
| cout << "Ustr1 = " << UStr1 << endl; | ||
| cout << "Ustr2 = " << UStr2 << endl; | ||
| cout << "Ustr3 = " << UStr3 << endl; | ||
|
|
||
| if(UStr1 > UStr3) | ||
| cout << "UStr1 > UStr3" << endl; | ||
| else | ||
| cout << "UStr1 <= UStr3" << endl; | ||
|
|
||
| if(UStr1 >= UStr3) | ||
| cout << "UStr1 >= UStr3" << endl; | ||
| else | ||
| cout << "UStr1 < UStr3" << endl; | ||
|
|
||
| if(UStr1 < UStr2) | ||
| cout << "UStr1 < UStr2" << endl; | ||
| else | ||
| cout << "UStr1 >= UStr2" << endl; | ||
|
|
||
| if(UStr1 <= UStr2) | ||
| cout << "UStr1 <= UStr2" << endl; | ||
| else | ||
| cout << "UStr1 > UStr2" << endl; | ||
|
|
||
| //testing & and &= operators | ||
| cout << "testing & and &= operators" << endl; | ||
| UpperCaseString UStr5("Hello "); | ||
| UpperCaseString UStr6("World!"); | ||
| cout << "Ustr5 = " << UStr5 << endl; | ||
| cout << "Ustr6 = " << UStr6 << endl; | ||
| UStr5 = (UStr5 & UStr6); | ||
| cout << "Ustr5 now = " << UStr5 << endl << endl; | ||
| UpperCaseString UStr7(" Goodbye World!"); | ||
| cout << "Ustr7 = " << UStr7 << endl; | ||
| UStr5 &= UStr7; | ||
| cout << "UStr5 &= UStr7" << endl; | ||
| cout << "Ustr5 is now: " << UStr5 << endl; | ||
|
|
||
|
|
||
|
|
||
| //testing >> operator ; already tested << operator | ||
| cout << "Testing >> (input) operator: please enter a string" << endl; | ||
| UpperCaseString UStr4; | ||
| cin >> UStr4; | ||
| cout << UStr4 << endl; | ||
|
|
||
| //testing for [] operator | ||
| cout << "testing for [] operator" << endl; | ||
| UpperCaseString UStr8 ("abcdefg"); | ||
| cout << UStr8[0] << endl; | ||
|
|
||
|
|
||
| //************************************************************************************************ | ||
| //testing for the DigitString class | ||
| //************************************************************************************************ | ||
|
|
||
| cout << "Testing for the DIGITSTRING CLASS: " << endl << endl << endl; | ||
| DigitString DStr1("1234"); | ||
| DigitString DStr2("5678"); | ||
|
|
||
| ////Testing Assertions ************************************************************************* | ||
| ////uncomment and one line at a time and execute to see assertions. ** | ||
| ////recomment afterword, and uncomment the next line and execute, to test the next assertion. ** | ||
| ////******************************************************************************************** | ||
| char a = 'a'; | ||
| char* myCharPntr = &a; | ||
| ANT_String myNonDigitString("not a digit"); | ||
| //DigitString DStr3("not a number"); | ||
| //DigitString DStr3(myCharPntr); | ||
| //DigitString DStr3(myNonDigitString); | ||
|
|
||
|
|
||
| DigitString DStr3("99999"); | ||
| cout << "Dstr1 = " << DStr1 << endl; | ||
| cout << "Dstr2 = " << DStr2 << endl; | ||
|
|
||
|
|
||
| DStr1 = DStr2; | ||
|
|
||
| cout << "After assignment DStr1 is now: " << DStr1 << endl; | ||
|
|
||
|
|
||
| cout << "Testing == operator: " << endl; | ||
| if(DStr1 == DStr2) | ||
| cout << "DStr1 and DStr2 are equal." << endl; | ||
| else | ||
| cout << "DStr1 and DStr2 are NOT equal." << endl; | ||
|
|
||
| if(DStr1 == DStr3) | ||
| cout << "DStr1 and DStr3 are equal." << endl; | ||
| else | ||
| cout << "DStr1 and DStr3 are NOT equal." << endl; | ||
|
|
||
|
|
||
| cout << "Testing < > <= >= Operators:" << endl; | ||
| cout << "Dstr1 = " << DStr1 << endl; | ||
| cout << "Dstr2 = " << DStr2 << endl; | ||
| cout << "Dstr3 = " << DStr3 << endl; | ||
|
|
||
| if(DStr1 > DStr3) | ||
| cout << "DStr1 > DStr3" << endl; | ||
| else | ||
| cout << "DStr1 <= DStr3" << endl; | ||
|
|
||
| if(DStr1 >= DStr3) | ||
| cout << "DStr1 >= DStr3" << endl; | ||
| else | ||
| cout << "DStr1 < DStr3" << endl; | ||
|
|
||
| if(DStr1 < DStr2) | ||
| cout << "DStr1 < DStr2" << endl; | ||
| else | ||
| cout << "DStr1 >= DStr2" << endl; | ||
|
|
||
| if(DStr1 <= DStr2) | ||
| cout << "DStr1 <= DStr2" << endl; | ||
| else | ||
| cout << "DStr1 > DStr2" << endl; | ||
|
|
||
| //testing & and &= operators | ||
| cout << "testing & and &= operators" << endl; | ||
| DigitString DStr5("867564"); | ||
| DigitString DStr6("534231"); | ||
| cout << "Dstr5 = " << DStr5 << endl; | ||
| cout << "Dstr6 = " << DStr6 << endl; | ||
| DStr5 = (DStr5 & DStr6); | ||
| cout << "Dstr5 now = " << DStr5 << endl << endl; | ||
| DigitString DStr7("111222333"); | ||
| cout << "Dstr7 = " << DStr7 << endl; | ||
| DStr5 &= DStr7; | ||
| cout << "DStr5 &= DStr7" << endl; | ||
| cout << "Dstr5 is now: " << DStr5 << endl; | ||
|
|
||
|
|
||
| //testing >> operator ; already tested << operator | ||
| cout << "Testing >> (input) operator: Please enter a numeric string:" << endl; | ||
| DigitString DStr4; | ||
| cin >> DStr4; | ||
| cout << DStr4 << endl; | ||
|
|
||
| //testing for [] operator | ||
| cout << "testing for [] operator" << endl; | ||
| DigitString DStr8("12345"); | ||
| cout << DStr8[0] << endl; | ||
|
|
||
|
|
||
|
|
||
| } |
| @@ -0,0 +1,20 @@ | ||
|
|
||
| Microsoft Visual Studio Solution File, Format Version 11.00 | ||
| # Visual Studio 2010 | ||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "version 1", "version 1.vcxproj", "{71873C74-E875-4171-A177-E4E3A00EED89}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Win32 = Debug|Win32 | ||
| Release|Win32 = Release|Win32 | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {71873C74-E875-4171-A177-E4E3A00EED89}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
| {71873C74-E875-4171-A177-E4E3A00EED89}.Debug|Win32.Build.0 = Debug|Win32 | ||
| {71873C74-E875-4171-A177-E4E3A00EED89}.Release|Win32.ActiveCfg = Release|Win32 | ||
| {71873C74-E875-4171-A177-E4E3A00EED89}.Release|Win32.Build.0 = Release|Win32 | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| EndGlobal |
| @@ -0,0 +1,92 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup Label="ProjectConfigurations"> | ||
| <ProjectConfiguration Include="Debug|Win32"> | ||
| <Configuration>Debug</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| <ProjectConfiguration Include="Release|Win32"> | ||
| <Configuration>Release</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| </ItemGroup> | ||
| <PropertyGroup Label="Globals"> | ||
| <ProjectGuid>{71873C74-E875-4171-A177-E4E3A00EED89}</ProjectGuid> | ||
| <Keyword>Win32Proj</Keyword> | ||
| <RootNamespace>version1</RootNamespace> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
| <ConfigurationType>Application</ConfigurationType> | ||
| <UseDebugLibraries>true</UseDebugLibraries> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
| <ConfigurationType>Application</ConfigurationType> | ||
| <UseDebugLibraries>false</UseDebugLibraries> | ||
| <WholeProgramOptimization>true</WholeProgramOptimization> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
| <ImportGroup Label="ExtensionSettings"> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <PropertyGroup Label="UserMacros" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <LinkIncremental>true</LinkIncremental> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <LinkIncremental>false</LinkIncremental> | ||
| </PropertyGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <ClCompile> | ||
| <PrecompiledHeader> | ||
| </PrecompiledHeader> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <Optimization>Disabled</Optimization> | ||
| <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| </ClCompile> | ||
| <Link> | ||
| <SubSystem>Console</SubSystem> | ||
| <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <ClCompile> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <PrecompiledHeader> | ||
| </PrecompiledHeader> | ||
| <Optimization>MaxSpeed</Optimization> | ||
| <FunctionLevelLinking>true</FunctionLevelLinking> | ||
| <IntrinsicFunctions>true</IntrinsicFunctions> | ||
| <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| </ClCompile> | ||
| <Link> | ||
| <SubSystem>Console</SubSystem> | ||
| <GenerateDebugInformation>true</GenerateDebugInformation> | ||
| <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
| <OptimizeReferences>true</OptimizeReferences> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="ANT_String\ANT_String.cpp" /> | ||
| <ClCompile Include="ANT_String\ReadString.cpp" /> | ||
| <ClCompile Include="DigitString.cpp" /> | ||
| <ClCompile Include="main.cpp" /> | ||
| <ClCompile Include="UpperCaseString.cpp" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClInclude Include="ANT_String\ANT_String.h" /> | ||
| <ClInclude Include="ANT_String\ReadString.h" /> | ||
| <ClInclude Include="DigitString.h" /> | ||
| <ClInclude Include="UppercaseString.h" /> | ||
| </ItemGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
| <ImportGroup Label="ExtensionTargets"> | ||
| </ImportGroup> | ||
| </Project> |