Tuesday, November 9, 2010

[DSA] string class

I hope you have enjoyed and learned some "know how" of writing a program from scratch, with our lil' palindrome example.

To make our lives easier, C++ have lots of library for us to choose from
#include < string > is one of them. Take note string and cstring. both are different!

If you check out the book pg260. There is a piece of code that is very similar of what we have done today. It is using CString instead of String.


Drill Question


Write a name generator (star wars name anybody? hehe) software.
1. The software takes in a name for input and
2. think of the "magic" algorithm to generate a "NINJA" name. Or any name modifiers you can think of. Similar to those name generators you have played on facebook. I guess pretty much of everybody have generated at least once.  Code it FREE STYLE ~maybe you want to start by storing 10 sample first name and 10 sample last name. Which gives a 10 to 10 mapping. Easily 100 names~

Append part of your original name to the sample name "randomly".
3. Check out the string member functions attached~

below are the member functions of String. http://www.cplusplus.com/reference/string/string/

Member functions

(constructor) Construct string object (constructor member)
operator= String assignment (public member function)


Iterators:
begin Return iterator to beginning (public member function)
end Return iterator to end (public member function)
rbegin Return reverse iterator to reverse beginning (public member function)
rend Return reverse iterator to reverse end (public member function)


Capacity:
size Return length of string (public member function)
length Return length of string (public member function)
max_size Return maximum size of string (public member function)
resize Resize string (public member function)
capacity Return size of allocated storage (public member function)
reserve Request a change in capacity (public member function)
clear Clear string (public member function)
empty Test if string is empty (public member function)


Element access:
operator[] Get character in string (public member function)
at Get character in string (public member function)


Modifiers:
operator+= Append to string (public member function)
append Append to string (public member function)
push_back Append character to string (public member function)
assign Assign content to string (public member function)
insert Insert into string (public member function)
erase Erase characters from string (public member function)
replace Replace part of string (public member function)
copy Copy sequence of characters from string (public member function)
swap Swap contents with another string (public member function)


String operations:
c_str Get C string equivalent (public member function)
data Get string data (public member function)
get_allocator Get allocator (public member function)
find Find content in string (public member function)
rfind Find last occurrence of content in string (public member function)
find_first_of Find character in string (public member function)
find_last_of Find character in string from the end (public member function)
find_first_not_of Find absence of character in string
find_last_not_of Find absence of character in string from the end (public member function)
substr Generate substring (public member function)
compare Compare strings (public member function)

20 comments:

  1. http://snipt.net/Qwertronic/string-7?key=9a4ae851b5362e31694228b6b54faa98

    ReplyDelete
  2. http://snipt.net/Qwertronic/malayalam?key=eb6d172757e1145c6967cdc6c735c857

    ReplyDelete
  3. alvinthen dcpe/ft/2b/03November 11, 2010 at 8:50 AM

    http://snipt.net/alvinthen/11-nov-2010?key=7afada7425bd619c5f3b49f90b4bf1a0

    ReplyDelete
  4. http://snipt.net/UJuzGtJacked/stringclasscompare?key=25925c11e845d1d50d38c121e53ecbee

    ReplyDelete
  5. http://snipt.net/asdsieg/string-10

    ReplyDelete
  6. http://snipt.net/sa198/qi-haodcpe2b03-5/?key=1b54d4bd6e71e101f6d06f9eb9633501

    ReplyDelete
  7. http://snipt.net/hengnee/another-string-class

    ReplyDelete
  8. http://snipt.net/kuanknightz/string-creation-and-replacement/?key=05fffbbbdc6a1f6f9182b7a945e9a4b0

    ReplyDelete
  9. Li Xiaofei DCPE 2B03November 11, 2010 at 8:59 AM

    http://snipt.net/xiaofei/replace-string-1/?key=a8be2d0546001d3764609f7c96534adc

    ReplyDelete
  10. http://snipt.net/bigshow/week44

    http://snipt.net/bigshow/week43

    ReplyDelete
  11. http://snipt.net/Stish/strings-1

    ReplyDelete
  12. http://snipt.net/jellybanana/week-4-replacing-strings

    ReplyDelete
  13. http://snipt.net/Stish/strings-reverse

    ReplyDelete
  14. alvinthen dcpe/ft/2b/03November 11, 2010 at 9:36 AM

    http://snipt.net/alvinthen/malayalam-reverse-compare?key=0f4ec39cc1c10d653e30d33a8dfac297

    ReplyDelete
  15. http://snipt.net/UJuzGtJacked/palindrome-8/?key=0b2bbf0aea4b773fb5e2152dd59a5a7a

    ReplyDelete
  16. http://snipt.net/sa198/qi-haodcpe2b03-6?key=21ab9ff28562fece1414aa5fab2fea73

    ReplyDelete
  17. @guys, nice work. keep the codes coming in~!~ RAWWRRRR

    ReplyDelete