Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**************header file********* sequence1.h******************* ****************************Implementation file *****************sequence1.cpp**************** #include #include #include using namespace std; namespace main_savitch_3 { // no argument constructor sequence::sequence() { used = 0; current_index

image text in transcribed

**************header file*********

sequence1.h*******************

image text in transcribed

image text in transcribed

image text in transcribed

****************************Implementation file

*****************sequence1.cpp****************

#include

#include

#include

using namespace std;

namespace main_savitch_3

{

// no argument constructor

sequence::sequence()

{

used = 0;

current_index = 0;

}

void sequence::start( )

{

current_index = 0;

}

void sequence::advance( )

{

//Implementation goes here

}

void sequence::insert(const value_type& entry)

{

assert(size()

if(!is_item())

{

current_index = 0;

}

if(size() > 0)

{

for(int i = size(); i > current_index; i--)

{

data[i] = data[i-1];

}

}

data[current_index] = entry;

used++;

}

void sequence::attach(const value_type& entry)

{

// implementation goes here

}

void sequence::remove_current( )

{

//implementation goes here

}

// CONSTANT MEMBER FUNCTIONS

sequence::size_type sequence::size( ) const

{

return used;

}

bool sequence::is_item( ) const

{

return used > current_index;

}

sequence::value_type sequence::current( ) const

{

return data[current_index];

}

}

please include the completed incrementation file with the new functions mentioned above. thank you

The purpose of this lab is to help reinforce container class concepts in C++ Specifically, the lab is to implement the sequence class from chapter 3. You should use the author's header file sequencel.h and the author's test program sequence_exam.cpp) You are provided with a partially implemented file sequencel.cpp. Please implement the following functions based on the pre and post conditions listed in the header file for this class. void advance0 void attach(const value _type& entry) void remove current0 > hi sequence 1.h) No Selection 1 // FILE: sequence1.h 2 II CLASS PROVIDED: sequence (part of the namespace main savitch_3) 3 // There is no implementation file provided for this class since it is 4 // an exercise from Section 3.2 of "Data Structures and Other Objects Using C++" 6 I/ TYPEDEFS and MEMBER CONSTANTS for the sequence class: 7 /1 typedef value_type sequence::value type is the data type of the items in the sequence. It 9 IImay be any of the C++ built-in types (int, char, etc.), or a class with a default constructor, an assignment operator, and a copy constructor 12 Itypedef 13/ size type sequence::size_type is the data type of any variable that keeps track of how many items are in a sequence. 16 IIstatic const size type CAPACITY sequence: :CAPACITY is the maximum number of items that a sequence can hold. 18/ 19 I/ CONSTRUCTOR for the sequence class: 20 I1sequence) 21 Postcondition: The sequence has been initialized as an empty sequence. 23 // MODIFICATION MEMBER FUNCTIONS for the sequence class: 24 Ivoid start() Postcondition: The first item on the sequence becomes the current item (but if the sequence is empty, then there is no current item). 27 11 28 void advance() Precondition: is item returns true Postcondition: If the current item was already the last item in the sequence, then there is no longer any current item. Otherwise, the new current item is the item immediately after the original current item. 32 / 33 / 34 IIvoid insert (const value_type& entry) Precondition: size( ) // Provides sizet 73 74 namespace main_savitch 3 75 76 - - - - - - - class sequence 78 public: // TYPEDEFS and MEMBER CONSTANTS tunedef douhe value tune 79 S h sequence1h No Selection 67 // VALUE SEMANTICS for the sequence class: 68 IIAssignments and the copy constructor may be used with sequence objects. 69 #imdef MAINSAVITCHSEQUENCEH #define MAINSAV ITCHSEQUENCEH #include // Provides size..t - - - - - - 73 74 namespace main_savitch 3 75 76 class sequence public: TYPEDEFS and MEMBER CONSTANTS typedef double value_type; typedef std::size t size type; static const size type CAPACITY30 79 81 CONSTRUCTOR sequence //MODIFICATION MEMBER FUNCTIONS void start( ); void advance; void insert (const value_type& entry); void attach (const value type& entry); void removecurrent // CONSTANT MEMBER FUNCTONS size type size( const; bool is item const value_type current const; 83 84 85 87 89 private: value_type data [CAPACITY] size type used; size type current index; 97 100 101 102 #endif 103 104

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

Discuss the five steps that can be used to conduct a task analysis

Answered: 1 week ago

Question

Discuss the purpose and advantages of conducting a needs assessment

Answered: 1 week ago