STL and Example Review <vector> Declaration: - - PowerPoint PPT Presentation

stl and example review vector
SMART_READER_LITE
LIVE PREVIEW

STL and Example Review <vector> Declaration: - - PowerPoint PPT Presentation

STL and Example Review <vector> Declaration: std::vector<T>vec = {initializer list} Access and modify: vec[index] = value Assignment of whole array: new_vec = vec Find size: vec.size() Extend: vec.push_back(val) How


slide-1
SLIDE 1

STL and Example

slide-2
SLIDE 2

Review <vector>

  • Declaration: std::vector<T>vec = {initializer list}
  • Access and modify: vec[index] = value
  • Assignment of whole array: new_vec = vec
  • Find size: vec.size()
  • Extend: vec.push_back(val)
slide-3
SLIDE 3

How hard was week 6 code review assignment?

  • A. Easy
  • B. Moderate
  • C. Challenging
  • D. Unreasonable
slide-4
SLIDE 4

How long did week 6 assignment take?

  • A. Less than 3 hours
  • B. 3 to 6 hours
  • C. 6 to 9 hours
  • D. 9 to 12 hours
  • E. More than 12 hours
slide-5
SLIDE 5

Which assignment did you do?

  • A. Simulation (Open)
  • B. Simulation2 (Chef Specific)
slide-6
SLIDE 6

C++ Libraries – Dictionary or Associative Array

  • Take two types first key and second is value. <key,value>
  • Use as an array indexed by key values.
  • <map>
  • Whole container can be accessed in key order
  • O(log n) for most operations
  • <unordered_map>
  • Accessing the whole container is possible but the order is not defined
  • O(1) expected for most operations
slide-7
SLIDE 7

<map>

  • Declaration: std::map<T1,T2>my_map
  • Access and modify: my_map[index] = value
  • Assignment of whole array: new_map = my_map
  • Find size: my_map.size()
  • Find: my_map.find(key)
  • Returns an iterator to a pair <key,value>
slide-8
SLIDE 8

STL iterators and pair

  • Iterators
  • Acts like a pointer access the value with * or -> as with a pointer
  • Used to interact with STL containers
  • STL pair
  • Two types <T1,T2>
  • Access through public member variables first and second
slide-9
SLIDE 9

Filestreams

  • ofstream – Write to a file
  • ifstream – Read from a file
  • fstream – Read and write from a file
  • Open the file fstream.open(filename)
  • Close the file fstream.close()
slide-10
SLIDE 10

Gradebook