Hello sir,
I'm supposed to Implement and Test the sequence Class Using a Fixed-Sized Array (Chapter 3), from Data Structures & Other objects using c++. The header file is provided, and so is a test program to check the correctness of the sequence class. I cannot figure out what the problem is and keep looking back and forth at the textbook and its not helping, can someone please please help me , i cannot figure out the errors in the implementation file.
[code=cpp]
// This is the Header File sequence.h
#define MAIN_SAVITCH_SE QUENCE_H
#include <iostream>
#include <cstdlib> // Provides size_t
namespace main_savitch_3
{
class sequence
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef size_t size_type;
static const size_type CAPACITY = 30;
// CONSTRUCTOR
sequence( );
// MODIFICATION MEMBER FUNCTIONS
void start( );
void advance( );
void insert(const value_type& entry);
void attach(const value_type& entry);
void remove_current( );
// CONSTANT MEMBER FUNCTIONS
size_type size( ) const;
bool is_item( ) const;
value_type current( ) const;
private:
value_type data[CAPACITY];
size_type used;
size_type current_index;
};
}
#endif
// This is the implementation file which i have having problems with
//i cant figure out what is wrong help please please
#include <iostream>
#include <cassert> // Provides assert function
#include "sequence.h " // With value_type defined as double
using namespace std;
namespace main_savitch_3
{
// MODIFICATION MEMBER FUNCTIONS
sequence::seque nce ()
{
current_index = 0;
used = 0;
}
void sequence::start ( )
{
current_index = 0;
}
void sequence::advan ce( )
{
assert (is_item());
current_index++ ;
}
void sequence::inser t(const value_type& entry)
{
int i;
assert (is_item());
const int old_used = used;
for (i = used; i current_index; i--)
{
data[i]= data[i-1];
data[current_index] = entry;
used++;
}
assert( used == old_used - 1 );
}
File Edit Options Buffers Tools C++ Help
void sequence::attac h(const value_type& entry)
{
int i;
assert(size()<C APACITY);
const int old_used = used;
for (i = used; i current_index; i--)
{
data[i] = data[i+1];
data[current_index] = entry;
used++;
}
assert( used == old_used - 1 );
}
void sequence::remov e_current( )
{
int i;
assert (is_item());
const int old_used = used; // added line here
for (i= current_index +1; i < used -1; i++)
{
data[i] = data[i+1];
used--;
}
assert( used == old_used - 1 ); // added line here
}
// CONSTANT MEMBER FUNCTIONS
sequence::size_ type sequence::size( ) const
{
return used;
}
bool sequence::is_it em( ) const
{
return current_index < used;
}
sequence::value _type sequence::curre nt( ) const
{
return data[current_index];
}
}
[/code]
Im getting all sorts of warnings or c++ does not support default int, but i followed examples from the book please help meee =(
I'm supposed to Implement and Test the sequence Class Using a Fixed-Sized Array (Chapter 3), from Data Structures & Other objects using c++. The header file is provided, and so is a test program to check the correctness of the sequence class. I cannot figure out what the problem is and keep looking back and forth at the textbook and its not helping, can someone please please help me , i cannot figure out the errors in the implementation file.
[code=cpp]
// This is the Header File sequence.h
#define MAIN_SAVITCH_SE QUENCE_H
#include <iostream>
#include <cstdlib> // Provides size_t
namespace main_savitch_3
{
class sequence
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef size_t size_type;
static const size_type CAPACITY = 30;
// CONSTRUCTOR
sequence( );
// MODIFICATION MEMBER FUNCTIONS
void start( );
void advance( );
void insert(const value_type& entry);
void attach(const value_type& entry);
void remove_current( );
// CONSTANT MEMBER FUNCTIONS
size_type size( ) const;
bool is_item( ) const;
value_type current( ) const;
private:
value_type data[CAPACITY];
size_type used;
size_type current_index;
};
}
#endif
// This is the implementation file which i have having problems with
//i cant figure out what is wrong help please please
#include <iostream>
#include <cassert> // Provides assert function
#include "sequence.h " // With value_type defined as double
using namespace std;
namespace main_savitch_3
{
// MODIFICATION MEMBER FUNCTIONS
sequence::seque nce ()
{
current_index = 0;
used = 0;
}
void sequence::start ( )
{
current_index = 0;
}
void sequence::advan ce( )
{
assert (is_item());
current_index++ ;
}
void sequence::inser t(const value_type& entry)
{
int i;
assert (is_item());
const int old_used = used;
for (i = used; i current_index; i--)
{
data[i]= data[i-1];
data[current_index] = entry;
used++;
}
assert( used == old_used - 1 );
}
File Edit Options Buffers Tools C++ Help
void sequence::attac h(const value_type& entry)
{
int i;
assert(size()<C APACITY);
const int old_used = used;
for (i = used; i current_index; i--)
{
data[i] = data[i+1];
data[current_index] = entry;
used++;
}
assert( used == old_used - 1 );
}
void sequence::remov e_current( )
{
int i;
assert (is_item());
const int old_used = used; // added line here
for (i= current_index +1; i < used -1; i++)
{
data[i] = data[i+1];
used--;
}
assert( used == old_used - 1 ); // added line here
}
// CONSTANT MEMBER FUNCTIONS
sequence::size_ type sequence::size( ) const
{
return used;
}
bool sequence::is_it em( ) const
{
return current_index < used;
}
sequence::value _type sequence::curre nt( ) const
{
return data[current_index];
}
}
[/code]
Im getting all sorts of warnings or c++ does not support default int, but i followed examples from the book please help meee =(
Comment