SlideShare a Scribd company logo
Files that you must write and turn in (Please do not turn in other files!!):
sequence2.h: The header file for the new sequence class. Actually, you don't have to write much
of this file. If some of your member functions are implemented as inline functions, then you may
put those implementations in this file too. By the way, you might want to compare this header file
with your first sequence header file sequence1.h, the new version no longer has a CAPACITY
constant because the items are stored in a dynamic array that grows as needed. But there is a
DEFAULT_CAPACITY constant, which provides the initial size of the array for a sequence created
by the default constructor.
sequence2.cpp: The implementation file for the new sequence class. You will write all of this file,
which will have the implementations of all the sequence's member functions
sequence2.h
#ifndef MAIN_SAVITCH_SEQUENCE_H
#define MAIN_SAVITCH_SEQUENCE_H
#include <cstdlib> // Provides size_t
namespace main_savitch_4
{
class sequence
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef std::size_t size_type;
static const size_type DEFAULT_CAPACITY = 30;
// CONSTRUCTORS and DESTRUCTOR
sequence(size_type initial_capacity = DEFAULT_CAPACITY);
sequence(const sequence& source);
~sequence( );
// MODIFICATION MEMBER FUNCTIONS
void resize(size_type new_capacity);
void start( );
void advance( );
void insert(const value_type& entry);
void attach(const value_type& entry);
void remove_current( );
void operator =(const sequence& source);
// CONSTANT MEMBER FUNCTIONS
size_type size( ) const;
bool is_item( ) const;
value_type current( ) const;
void operator +=(const sequence& source);
void operator +(const sequence& source);
value_type operator[](size_type index) const;
private:
value_type* data;
size_type used;
size_type current_index;
size_type capacity;
};
}
#endif
sequence2.cpp
#include "sequence2.h"
#include <algorithm>
#include <cassert>
namespace main_savitch_4 {
// CONSTRUCTORS AND DESTRUCTOR
sequence::sequence(size_type initial_capacity) {
data = new value_type[initial_capacity];
capacity = initial_capacity;
used = 0;
current_index = 0;
}
sequence::sequence(const sequence& source) {
data = new value_type[source.capacity];
capacity = source.capacity;
used = source.used;
current_index = source.current_index;
std::copy(source.data, source.data + used, data);
}
sequence::~sequence() {
delete[] data;
}
// MODIFICATION MEMBER FUNCTIONS
void sequence::resize(size_type new_capacity) {
if (new_capacity == capacity)
return;
if (new_capacity < used)
new_capacity = used;
value_type* new_data = new value_type[new_capacity];
std::copy(data, data + used, new_data);
delete[] data;
data = new_data;
capacity = new_capacity;
}
void sequence::start() {
if (used > 0)
current_index = 0;
}
void sequence::advance() {
if (is_item())
++current_index;
}
void sequence::insert(const value_type& entry) {
if (size() == capacity)
resize(capacity * 2);
if (!is_item()) // No current item, so insert at start
current_index = 0;
for (size_type i = used; i > current_index; --i)
data[i] = data[i - 1];
data[current_index] = entry;
++used;
}
void sequence::attach(const value_type& entry) {
if (size() == capacity)
resize(capacity * 2);
if (!is_item()) // No current item, so attach at end
current_index = used - 1;
++current_index;
for (size_type i = used; i > current_index; --i)
data[i] = data[i - 1];
data[current_index] = entry;
++used;
}
void sequence::remove_current() {
assert(is_item());
for (size_type i = current_index; i < used - 1; ++i)
data[i] = data[i + 1];
--used;
}
void sequence::operator=(const sequence& source) {
if (this == &source)
return;
value_type* new_data = new value_type[source.capacity];
std::copy(source.data, source.data + source.used, new_data);
delete[] data;
data = new_data;
capacity = source.capacity;
used = source.used;
current_index = source.current_index;
}
void sequence::operator+=(const sequence& source) {
if (size() + source.size() > capacity)
resize(size() + source.size());
std::copy(source.data, source.data + source.used, data + used);
used += source.used;
}
sequence sequence::operator+(const sequence& source) const {
sequence result(size() + source.size());
std::copy(data, data + used, result.data);
std::copy(source.data, source.data + source.used, result.data + used);
result.used = used + source.used;
return result;
}
sequence::value_type sequence::operator[](size_type index) const {
assert(index < used);
}
}
Error:
./sequence2.cpp:111:24: error: out-of-line definition of 'operator+' does not match any declaration
in 'main_savitch_4::sequence'
sequence sequence::operator+(const sequence& source) const {
^~~~~~~~
./sequence2.h:128:8: note: member declaration does not match because it is not const qualified
void operator +(const sequence& source);
^ ~
1 error generated.
make: *** [Makefile:10: main] Error 1

More Related Content

PDF
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
PDF
Given below is the code for the question. Since the test files (ment.pdf
PDF
Given below is the code for the question. Since the test files (ment.pdf
PDF
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
PDF
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
PDF
In java , I want you to implement a Data Structure known as a Doubly.pdf
PDF
Lab 13 Practicing STLVector Container1a. Write a template func.pdf
ODP
Session 2- day 3
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
Lab 13 Practicing STLVector Container1a. Write a template func.pdf
Session 2- day 3

Similar to Files that you must write and turn in Please do not turn in.pdf (20)

DOCX
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
PPTX
CPP Assignment Help
PDF
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
PPT
Data Processing Using Quantum
PPT
Queue Data Structure
PPT
Queue Data Structure
PDF
IO redirection in C shellPlease implement input output redirect.pdf
PDF
File name a2.cppTaskFor this assignment, you are required to ei.pdf
PDF
in c languageTo determine the maximum string length, we need to .pdf
PPTX
Programming Assignment Help
PDF
need help with my computer science lab assignemnt. this assignment i.pdf
PDF
#include iostream #include cstring #include vector #i.pdf
DOCX
all i need is these two filesCreate VectorContainer.hppCreat.docx
PDF
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
PPT
Memory Management In C++
PDF
For problems 3 and 4, consider the following functions that implemen.pdf
PPT
Spring data ii
PDF
Angular Schematics
PDF
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
PDF
BackgroundIn many applications, the composition of a collection o.pdf
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
CPP Assignment Help
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Data Processing Using Quantum
Queue Data Structure
Queue Data Structure
IO redirection in C shellPlease implement input output redirect.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdf
in c languageTo determine the maximum string length, we need to .pdf
Programming Assignment Help
need help with my computer science lab assignemnt. this assignment i.pdf
#include iostream #include cstring #include vector #i.pdf
all i need is these two filesCreate VectorContainer.hppCreat.docx
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
Memory Management In C++
For problems 3 and 4, consider the following functions that implemen.pdf
Spring data ii
Angular Schematics
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
BackgroundIn many applications, the composition of a collection o.pdf

More from actocomputer (20)

PDF
Figure 3 below shows that the survival rate of Blue Wildeb.pdf
PDF
FIGURE 241 Refer to Figure 241 Suppose the economy is cur.pdf
PDF
Fibroblast cells from patients Jack Karen Agatha and Tony.pdf
PDF
Fetal pig What is the purpose of the pericardial sac that su.pdf
PDF
Find the probability PEc if PE019 The probability PE.pdf
PDF
Feral pigs are an invasive species around the world They ca.pdf
PDF
Find the maximum likelihood estimator of +2 Suppose that .pdf
PDF
Find the indicated IQ score The graph to the right depicts .pdf
PDF
Female labour force participation rate and economic growth i.pdf
PDF
FedEx construy su negocio sobre la base de la entrega rpid.pdf
PDF
fecower Kayimood Dwicyo Soens sherwood Compact dise playe.pdf
PDF
Find the area of the shaded region The graph to the right de.pdf
PDF
Find code that you wrote and apply 2 of the 3 design princip.pdf
PDF
Find a current news article or video within the past 12 mon.pdf
PDF
Female pig Emmy Lou straight tail whitehaired with the h.pdf
PDF
Financing Assumptions Please assume a traditional bank cons.pdf
PDF
FigURE 01 Needle intersecting the border of the ruled tabl.pdf
PDF
Financial InformationFinancial InformationFinancial In.pdf
PDF
Fewer open fNa+ and Ca++ channels during the pacemaker poten.pdf
PDF
FIN 3100 Principios de Finanzas Caso de estudio Barry y S.pdf
Figure 3 below shows that the survival rate of Blue Wildeb.pdf
FIGURE 241 Refer to Figure 241 Suppose the economy is cur.pdf
Fibroblast cells from patients Jack Karen Agatha and Tony.pdf
Fetal pig What is the purpose of the pericardial sac that su.pdf
Find the probability PEc if PE019 The probability PE.pdf
Feral pigs are an invasive species around the world They ca.pdf
Find the maximum likelihood estimator of +2 Suppose that .pdf
Find the indicated IQ score The graph to the right depicts .pdf
Female labour force participation rate and economic growth i.pdf
FedEx construy su negocio sobre la base de la entrega rpid.pdf
fecower Kayimood Dwicyo Soens sherwood Compact dise playe.pdf
Find the area of the shaded region The graph to the right de.pdf
Find code that you wrote and apply 2 of the 3 design princip.pdf
Find a current news article or video within the past 12 mon.pdf
Female pig Emmy Lou straight tail whitehaired with the h.pdf
Financing Assumptions Please assume a traditional bank cons.pdf
FigURE 01 Needle intersecting the border of the ruled tabl.pdf
Financial InformationFinancial InformationFinancial In.pdf
Fewer open fNa+ and Ca++ channels during the pacemaker poten.pdf
FIN 3100 Principios de Finanzas Caso de estudio Barry y S.pdf

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Cell Types and Its function , kingdom of life
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Lesson notes of climatology university.
PDF
Complications of Minimal Access Surgery at WLH
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Pharma ospi slides which help in ospi learning
PDF
RMMM.pdf make it easy to upload and study
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
102 student loan defaulters named and shamed – Is someone you know on the list?
Cell Types and Its function , kingdom of life
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Final Presentation General Medicine 03-08-2024.pptx
Lesson notes of climatology university.
Complications of Minimal Access Surgery at WLH
VCE English Exam - Section C Student Revision Booklet
Module 4: Burden of Disease Tutorial Slides S2 2025
Computing-Curriculum for Schools in Ghana
Pharmacology of Heart Failure /Pharmacotherapy of CHF
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Final Presentation General Medicine 03-08-2024.pptx
GDM (1) (1).pptx small presentation for students
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Institutional Correction lecture only . . .
Pharma ospi slides which help in ospi learning
RMMM.pdf make it easy to upload and study
Abdominal Access Techniques with Prof. Dr. R K Mishra

Files that you must write and turn in Please do not turn in.pdf

  • 1. Files that you must write and turn in (Please do not turn in other files!!): sequence2.h: The header file for the new sequence class. Actually, you don't have to write much of this file. If some of your member functions are implemented as inline functions, then you may put those implementations in this file too. By the way, you might want to compare this header file with your first sequence header file sequence1.h, the new version no longer has a CAPACITY constant because the items are stored in a dynamic array that grows as needed. But there is a DEFAULT_CAPACITY constant, which provides the initial size of the array for a sequence created by the default constructor. sequence2.cpp: The implementation file for the new sequence class. You will write all of this file, which will have the implementations of all the sequence's member functions sequence2.h #ifndef MAIN_SAVITCH_SEQUENCE_H #define MAIN_SAVITCH_SEQUENCE_H #include <cstdlib> // Provides size_t namespace main_savitch_4 { class sequence { public: // TYPEDEFS and MEMBER CONSTANTS typedef double value_type; typedef std::size_t size_type; static const size_type DEFAULT_CAPACITY = 30; // CONSTRUCTORS and DESTRUCTOR sequence(size_type initial_capacity = DEFAULT_CAPACITY); sequence(const sequence& source); ~sequence( ); // MODIFICATION MEMBER FUNCTIONS void resize(size_type new_capacity); void start( ); void advance( ); void insert(const value_type& entry); void attach(const value_type& entry); void remove_current( ); void operator =(const sequence& source); // CONSTANT MEMBER FUNCTIONS size_type size( ) const; bool is_item( ) const; value_type current( ) const; void operator +=(const sequence& source); void operator +(const sequence& source); value_type operator[](size_type index) const;
  • 2. private: value_type* data; size_type used; size_type current_index; size_type capacity; }; } #endif sequence2.cpp #include "sequence2.h" #include <algorithm> #include <cassert> namespace main_savitch_4 { // CONSTRUCTORS AND DESTRUCTOR sequence::sequence(size_type initial_capacity) { data = new value_type[initial_capacity]; capacity = initial_capacity; used = 0; current_index = 0; } sequence::sequence(const sequence& source) { data = new value_type[source.capacity]; capacity = source.capacity; used = source.used; current_index = source.current_index; std::copy(source.data, source.data + used, data); } sequence::~sequence() { delete[] data; } // MODIFICATION MEMBER FUNCTIONS void sequence::resize(size_type new_capacity) { if (new_capacity == capacity) return; if (new_capacity < used) new_capacity = used; value_type* new_data = new value_type[new_capacity]; std::copy(data, data + used, new_data); delete[] data; data = new_data; capacity = new_capacity; }
  • 3. void sequence::start() { if (used > 0) current_index = 0; } void sequence::advance() { if (is_item()) ++current_index; } void sequence::insert(const value_type& entry) { if (size() == capacity) resize(capacity * 2); if (!is_item()) // No current item, so insert at start current_index = 0; for (size_type i = used; i > current_index; --i) data[i] = data[i - 1]; data[current_index] = entry; ++used; } void sequence::attach(const value_type& entry) { if (size() == capacity) resize(capacity * 2); if (!is_item()) // No current item, so attach at end current_index = used - 1; ++current_index; for (size_type i = used; i > current_index; --i) data[i] = data[i - 1]; data[current_index] = entry; ++used; } void sequence::remove_current() { assert(is_item()); for (size_type i = current_index; i < used - 1; ++i) data[i] = data[i + 1]; --used; } void sequence::operator=(const sequence& source) { if (this == &source) return; value_type* new_data = new value_type[source.capacity]; std::copy(source.data, source.data + source.used, new_data); delete[] data; data = new_data;
  • 4. capacity = source.capacity; used = source.used; current_index = source.current_index; } void sequence::operator+=(const sequence& source) { if (size() + source.size() > capacity) resize(size() + source.size()); std::copy(source.data, source.data + source.used, data + used); used += source.used; } sequence sequence::operator+(const sequence& source) const { sequence result(size() + source.size()); std::copy(data, data + used, result.data); std::copy(source.data, source.data + source.used, result.data + used); result.used = used + source.used; return result; } sequence::value_type sequence::operator[](size_type index) const { assert(index < used); } } Error: ./sequence2.cpp:111:24: error: out-of-line definition of 'operator+' does not match any declaration in 'main_savitch_4::sequence' sequence sequence::operator+(const sequence& source) const { ^~~~~~~~ ./sequence2.h:128:8: note: member declaration does not match because it is not const qualified void operator +(const sequence& source); ^ ~ 1 error generated. make: *** [Makefile:10: main] Error 1