Sams Teach Yourself C++ in 21 Days
LISTING13.13 Using strncpy() 0: //Listing 13.13 Using strncpy() 1: 2: #include <iostream> 3: #include <string.h> 4: ...
Managing Arrays and Strings 437 13 Before using this class, you will create a custom Stringclass as an exercise in under- standi ...
28: String (unsigned short); // private constructor 29: char * itsString; 30: unsigned short itsLen; 31: }; 32: 33: // default c ...
Managing Arrays and Strings 439 13 78: 79: // operator equals, frees existing memory 80: // then copies string and size 81: Stri ...
128: } 129: 130: // changes current string, returns nothing 131: void String::operator+=(const String& rhs) 132: { 133: unsi ...
Managing Arrays and Strings 441 13 S1: initial test S1: Hello World tempTwo: ; nice to be here! S1: Hello World; nice to be here ...
the existing string is established by a call to the standard Stringlibrary function strlen(). On line 28, another constructor,St ...
Managing Arrays and Strings 443 13 On line 127, operator plus returns the string,temp, by value, which is assigned to the string ...
In looking through Listing 13.14, you see that the Stringclass that you’ve built is begin- ning to become pretty robust. You’ll ...
Managing Arrays and Strings 445 13 Bag—An unordered collection that is added to and retrieved in indeterminate order. By overlo ...
Q Can I combine arrays? A Yes. With simple arrays, you can use pointers to combine them into a new, larger array. With strings, ...
Managing Arrays and Strings 447 13 Exercises ................................................................................... ...
...
DAY 14 WEEK 2 Polymorphism On Day 12, “Implementing Inheritance,” you learned how to write virtual func- tions in derived classe ...
Suddenly, you realize you need a Pegasusobject: a cross between a Horseand a Bird. A Pegasuscan Fly(), it can Whinny(), and it c ...
Polymorphism 451 14 9: void Gallop(){ cout << “Galloping...\n”; } 10: virtual void Fly() { cout << “Horses can’t fly ...
This program certainly works, although at the expense of the Horseclass having a Fly()method. On line 10, the method Fly()is pro ...
Polymorphism 453 14 Casting Down ............................................................................................... ...
454 Day 14 3: #include <iostream> 4: using namespace std; 5: 6: enum TYPE { HORSE, PEGASUS }; 7: 8: class Horse 9: { 10: p ...
Polymorphism 455 14 (1)Horse (2)Pegasus: 1 (1)Horse (2)Pegasus: 2 (1)Horse (2)Pegasus: 1 (1)Horse (2)Pegasus: 2 (1)Horse (2)Pega ...
«
19
20
21
22
23
24
25
26
27
28
»
Free download pdf