MyString_demo

MyString_demo - C = B + C; output <<...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/**** An Example Using The String Class ****/ /**** An example program illustrating the functionality ****/ #include <fstream> #include "MyString.h" using namespace std; ofstream output; void main () { output.open("demo_String.out"); String A; // String object A is created and A contains // the null string String B("Hello"); // String object B is created and // B contains the string "Hello" String C = " CS XXX class"; // String object C is created and // C contains the string " CS XXX class" String D(B); // String object D is created and D contains // the string "Hello" String E = C; // String object E is created and E contains //the string " CS XXX class" A = B; // resets the value of A to that of B output << A << " " << B << endl; // output to file: Hello Hello A[0] = ’M’; output << A << " " << B << endl; // output to file: Mello Hello output << "operator= and [] are working" << endl; D[0] = ’M’; output << D << " " << B << endl; // output to file: Mello Hello output << "copy constructor is working" << endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C = B + C; output &lt;&lt; C &lt;&lt; endl; // output to file: Hello CS XXX class C = &quot;String Class &quot; + B + E; output &lt;&lt; C &lt;&lt; endl; // output to file: String Class Hello CS XXX class if ( A &lt; B ) output &lt;&lt; &quot;My code has a bug in operator&lt; function&quot; &lt;&lt; endl; else if ( A &lt;= B ) output &lt;&lt; &quot;My code has a bug in operator&lt;= function&quot; &lt;&lt; endl; else if ( A == B ) output &lt;&lt; &quot;My code has a bug in operator== function&quot; &lt;&lt; endl; else output &lt;&lt; &quot;My comparison operators are working so far&quot; &lt;&lt; endl; if ( A != B &amp;&amp; A &gt; B &amp;&amp; A &gt;= B ) output &lt;&lt; &quot;All my comparison operators are working&quot; &lt;&lt; endl; output.close(); } THE ABOVE PROGRAM PRODUCES THE FOLLOWING OUTPUT IN THE OUTPUT FILE NAMED demo_String.out Hello Hello Mello Hello operator= and are working Mello Hello copy constructor is working Hello CS XXX class String Class Hello CS XXX class My comparison operators are working so far All my comparison operators are working...
View Full Document

Page1 / 2

MyString_demo - C = B + C; output &amp;amp;lt;&amp;amp;lt;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online