Points |
Task |
Task # |
.2 |
Has a contructor with no arguments |
1 |
.2 |
Has a constructor that builds a string using a char*
as input |
2 |
.3 |
Can cout << the String |
3 |
.2 |
Has an operator= that copy's a string into another
string |
4 |
.2 |
Has an operator= that copies a char* into a string |
5 |
.4 |
Can concatenate the strings using '+'. String a("Hello"), b("Mommy"), c; c = a + b; // Yields "HelloMommy" |
6 |
.4 |
Can subtract an int from a string to delete charactors String a("Hello"); String b = a-3; // Yields "He" |
7 |
.4 |
Can access a particular element from the string using
[] String a("hello"); cout << a[1]; // Prints a 'e' |
8 |
1 |
Can work with strings of ANY positive length. You
must have a destructor! |
9 |
.4 |
Can tell if string a char contains a substring using
"%". String a("hello"); if (a % 'e') // This is true |
10 |
.6 |
Can tell if a string contains a substring using '%'. String a("Hello"), b("He"); if (a % b) // This is true |
11 |
1 |
Turned in before Thursday October 31st. |
|
-1 |
Turned in after Thursday Nov 7th |
|
40,003 |
Includes the 'Buffy the Vampire Slayer' DVD collection |
int main()
{
String scott; // Task #1
String mom("mom"); // Task #2
String brother; // Task #1 again
cout << "Mom is " << mom << endl; // Task 3
brother = mom; // Task 4
brother = "Scott"; // Task 5
String ans; // Task 1 again
ans = mom + scott; // Tasks 4 and 6
cout << ans << endl; // Task 3 again
cout << "That should say momScott\n";
for(int i = 0; i < 5; i++)
cout << "Letter #" << i << " is " << brother[i] << endl; // Task 8
ans = ans - 3; // Task 7
cout << "That should say momSco\n";
if (ans % 'o') // Task 10
cout << "% seems to work\n";
else
cout << "% was wrong!\n";
if (ans % 'x') // Task 10 again
cout << "% was wrong!\n";
else
cout << "% was right again\n";
if (ans % mom) // Task 11
cout << "% on 2 strings was right\n";
else
cout << "% on 2 strings was wrong!\n";
if (ans % scott) // Task 11 again
cout << "% on 2 strings was wrong\n";
else
cout << "% on 2 strings was right!\n";
}