CPS 6, Ramm - Summer Semester I - 6/7/00 #14

7. Class Interfaces, Design, & Implementation

Chap 8. Arrays, Data, & Random Access

  • Vector Definition Syntax
    tvector<type> name;
    tvector<type> name(expression);
    tvector<type> name(expression, value);
    type is any with default (parameterless) constructor

  • Vector Initialization

    • Use Constructor
      • tvector<int> nums(4, -1);
      • tvector<string> words(12, "Hi");

    • Use Client Program
      for(k = 0; k < 4; k++)
          nums[k] = -1;
      
      for(k = 0; k < 12; k++)
          words[k] = "Hi";
      

  • Character Frequencies in Classical Cryptography
    • Crypoquotes in paper



  • Vector Parameters
    letters.cpp
    • char type
    • functions tolower(char), isalpha(char)
    • get(char) member function
    • fail() member function

  • A Draft Word in Context Program
    context.cpp

  • Redesigning a Word in Context Program
    Redesign in Classroom
    context2.cpp

  • What if File is Too Large?
    • Advantage of Vector Class: Resize
    • .resize(int size) member function
    • Copying/Cost: Memory and Time
    • Double It!
    • .capacity() member function
    • context3.cpp

  • How to Solve Problem Without Vectors?
    • Trailing Variables
    • Limited Search
    • or Reread File