D
Defcon2030
<b> Hey, can someone help me with this? I've been working on it for a
few days now, and my head's starting to spin... </b>
// FILE:ex1_imp.cxx
//
//
//
// CLASS IMPLEMENTED: sequence (see ex1.h for documentation)
// INVARIANT for the sequence class:
// 1. The number of items in the sequence is in the member variable
used;
// 2. For an empty sequence, we do not care what is stored in any of
data; for a
// non-empty sequence the items in the bag are stored in data[0]
through
// data[used - 1], and we don't care what's in the rest of data.
#include <iostream>
#include <cassert> // Provides assert function
#include "ex1.h" // With value_type defined as double
using namespace std;
namespace main_savitch_3
{
// MODIFICATION MEMBER FUNCTIONS
sequence::sequence ()
{
current_index = 0;
used = 0;
}
void sequence::start( )
{
current_index = 0;
}
void sequence::advance( )
{
assert (is_item());
current_index++;
}
void sequence::insert(const value_type& entry)
{
int i;
for (i = used; i > current_index; i--)
{
data= data[i-1];
data[current_index] = entry;
used++;
}
}
File Edit Options Buffers Tools C++ Help
void sequence::attach(const value_type& entry)
{
int i;
assert(size()<CAPACITY);
for (i = used; i > current_index; i--)
{
data = data[i+1];
data[current_index] = entry;
used++;
}
}
void sequence::remove_current( )
{
int i;
assert (is_item());
for (i= current_index +1; i < used -1; i++)
{
data = data[i+1];
used--;
}
}
// CONSTANT MEMBER FUNCTIONS
sequence::size_type sequence::size( ) const
{
return used;
}
bool sequence::is_item( ) const
{
return current_index < used;
}
sequence::value_type sequence::current( ) const
{
return data[current_index];
}
}
-------------------------------
<b> When i compile and run the program i get the following output: </
b>
------------------
$ ex1.out
I have initialized an empty sequence of real numbers.
The following choices are available:
! Activate the start( ) function
+ Activate the advance( ) function
? Print the result from the is_item( ) function
C Print the result from the current( ) function
P Print a copy of the entire sequence
S Print the result from the size( ) function
I Insert a new number with the insert(...) function
A Attach a new number with the attach(...) function
R Activate the remove_current( ) function
Q Quit this test program
Enter choice: !
The following choices are available:
! Activate the start( ) function
+ Activate the advance( ) function
? Print the result from the is_item( ) function
C Print the result from the current( ) function
P Print a copy of the entire sequence
S Print the result from the size( ) function
I Insert a new number with the insert(...) function
A Attach a new number with the attach(...) function
R Activate the remove_current( ) function
Q Quit this test program
Enter choice: +
ex1_imp.cxx:42: failed assertion `is_item()'
Abort - core dumped
$
few days now, and my head's starting to spin... </b>
// FILE:ex1_imp.cxx
//
//
//
// CLASS IMPLEMENTED: sequence (see ex1.h for documentation)
// INVARIANT for the sequence class:
// 1. The number of items in the sequence is in the member variable
used;
// 2. For an empty sequence, we do not care what is stored in any of
data; for a
// non-empty sequence the items in the bag are stored in data[0]
through
// data[used - 1], and we don't care what's in the rest of data.
#include <iostream>
#include <cassert> // Provides assert function
#include "ex1.h" // With value_type defined as double
using namespace std;
namespace main_savitch_3
{
// MODIFICATION MEMBER FUNCTIONS
sequence::sequence ()
{
current_index = 0;
used = 0;
}
void sequence::start( )
{
current_index = 0;
}
void sequence::advance( )
{
assert (is_item());
current_index++;
}
void sequence::insert(const value_type& entry)
{
int i;
for (i = used; i > current_index; i--)
{
data= data[i-1];
data[current_index] = entry;
used++;
}
}
File Edit Options Buffers Tools C++ Help
void sequence::attach(const value_type& entry)
{
int i;
assert(size()<CAPACITY);
for (i = used; i > current_index; i--)
{
data = data[i+1];
data[current_index] = entry;
used++;
}
}
void sequence::remove_current( )
{
int i;
assert (is_item());
for (i= current_index +1; i < used -1; i++)
{
data = data[i+1];
used--;
}
}
// CONSTANT MEMBER FUNCTIONS
sequence::size_type sequence::size( ) const
{
return used;
}
bool sequence::is_item( ) const
{
return current_index < used;
}
sequence::value_type sequence::current( ) const
{
return data[current_index];
}
}
-------------------------------
<b> When i compile and run the program i get the following output: </
b>
------------------
$ ex1.out
I have initialized an empty sequence of real numbers.
The following choices are available:
! Activate the start( ) function
+ Activate the advance( ) function
? Print the result from the is_item( ) function
C Print the result from the current( ) function
P Print a copy of the entire sequence
S Print the result from the size( ) function
I Insert a new number with the insert(...) function
A Attach a new number with the attach(...) function
R Activate the remove_current( ) function
Q Quit this test program
Enter choice: !
The following choices are available:
! Activate the start( ) function
+ Activate the advance( ) function
? Print the result from the is_item( ) function
C Print the result from the current( ) function
P Print a copy of the entire sequence
S Print the result from the size( ) function
I Insert a new number with the insert(...) function
A Attach a new number with the attach(...) function
R Activate the remove_current( ) function
Q Quit this test program
Enter choice: +
ex1_imp.cxx:42: failed assertion `is_item()'
Abort - core dumped
$