Posted By

DrPepper on 09/27/11


Tagged


Versions (?)

[CISP430] Sequence4.h


 / Published in: C++
 

This is sequence4.h not node2.h you need to used sequence4.cpp sequence4.h node2.h node2.template and exam file to finish up this assignment

  1. // FILE: sequence4.h
  2. // TEMPLATE CLASS PROVIDED:
  3. // sequence<Item> (part of the namespace CISP430_A3)
  4. // This is a container class for a sequence of items,
  5. // where each List may have a designated item called the current item).
  6. // The template parameter <value_type> is the data type of the items
  7. // in the List. It may be any of the C++ built-in types (int, char, etc.),
  8. // or a class with a default constructor, an assignment operator,
  9. // and a copy constructor.
  10. //
  11. // TYPEDEFS and MEMBER CONSTANTS for the sequence class:
  12. // sequence<Item>::value_type
  13. // Thisis the data type of the items in the sequence. It
  14. // may be any of the C++ built-in types (int, char, etc.), or a class with a
  15. // default constructor, an assignment operator, and a copy constructor.
  16. //
  17. // sequence<Item>::size_type
  18. // This is the data type of any variable that keeps track of
  19. // how many items are in a sequence.
  20. //
  21. // CONSTRUCTOR for the sequence<Item> class:
  22. // sequence( )
  23. // Postcondition: The sequence has been initialized as an empty sequence.
  24. //
  25. // MODIFICATION MEMBER FUNCTIONS for the sequence<Item> class:
  26. // void start( )
  27. // Postcondition: The first item on the sequence becomes the current item
  28. // (but if the sequence is empty, then there is no current item).
  29. //
  30. // void advance( )
  31. // Precondition: is_item returns true.
  32. // Postcondition: If the current item was already the last item in the
  33. // sequence, then there is no longer any current item. Otherwise, the new
  34. // current item is the item immediately after the original current item.
  35. //
  36. // void insert(const value_type& entry)
  37. // Postcondition: A new copy of entry has been inserted in the sequence
  38. // before the current item. If there was no current item, then the new entry
  39. // has been inserted at the front of the sequence. In either case, the newly
  40. // inserted item is now the current item of the sequence.
  41. //
  42. // void attach(const value_type& entry)
  43. // Postcondition: A new copy of entry has been inserted in the sequence after
  44. // the current item. If there was no current item, then the new entry has
  45. // been attached to the end of the sequence. In either case, the newly
  46. // inserted item is now the current item of the sequence.
  47. //
  48. // void remove_current( )
  49. // Precondition: is_item returns true.
  50. // Postcondition: The current item has been removed from the sequence, and
  51. // the item after this (if there is one) is now the new current item.
  52. //
  53. // CONSTANT MEMBER FUNCTIONS for the sequence<Item> class:
  54. // size_type size( ) const
  55. // Postcondition: The return value is the number of items in the sequence.
  56. //
  57. // bool is_item( ) const
  58. // Postcondition: A true return value indicates that there is a valid
  59. // "current" item that may be retrieved by activating the current
  60. // member function (listed below). A false return value indicates that
  61. // there is no valid current item.
  62. //
  63. // value_type current( ) const
  64. // Precondition: is_item( ) returns true.
  65. // Postcondition: The item returned is the current item in the sequence.
  66. //
  67. // VALUE SEMANTICS for the sequence class:
  68. // Assignments and the copy constructor may be used with sequence objects.
  69.  
  70. #ifndef SEQUENCE4_H
  71. #define SEQUENCE4_H
  72. #include <cstdlib> // Provides size_t
  73. #include "node2.h" // Provides node class
  74.  
  75. namespace CISP430_A3
  76. {
  77. template <class Item>
  78. class sequence
  79. {
  80. public:
  81. // TYPEDEFS and MEMBER CONSTANTS
  82. typedef Item value_type;
  83. typedef size_t size_type;
  84.  
  85. // CONSTRUCTORS and DESTRUCTOR
  86. sequence( );
  87. sequence(const sequence& source);
  88. ~sequence( );
  89. // MODIFICATION MEMBER FUNCTIONS
  90. void start( );
  91. void advance( );
  92. void insert(const value_type& entry);
  93. void attach(const value_type& entry);
  94. void operator =(const sequence& source);
  95. void remove_current( );
  96. // CONSTANT MEMBER FUNCTIONS
  97. size_type size( ) const
  98. {
  99. cout << "\n ** size() ** "<<endl;
  100. return many_nodes;
  101. }
  102. bool is_item( ) const
  103. {
  104. cout << "\n ** is_item() ** "<<endl;
  105. return (cursor != NULL);
  106. } // HERE RETURN BOOL USING CURSOR SO IF THERE IS NOT ITEM RETURN 0
  107. value_type current( ) const;
  108. private:
  109. node<Item> *head_ptr;
  110. node<Item> *tail_ptr;
  111. node<Item> *cursor; // THE SAME AS CURRENT_INDEX
  112. node<Item> *precursor;
  113. size_type many_nodes; // THE SAME AS USED
  114. };
  115. }
  116.  
  117. // The implementation of a template class must be included in its header file:
  118. #include "sequence4.template"
  119. #endif

Report this snippet  

You need to login to post a comment.