Sequence class
102710 ワード
Question1:
Implement the sequence class from Section 3.2. You may wish to provide some additional useful member functions, such as: (1) a function to add a new item at the front of the sequence; (2) a function to remove the item from the front of the sequence; (3) a function to add a new item at the end of the sequence; (4) a function that makes the last item of the sequence become the current item; (5) operators for - and +=. For the + operator, x + y contains all the items of x, followed by all the items of y. The statement x += y appends all of the items of y to the end of what’s already in x.
My answer:
まず本の要求を完成します.作成者が提供するヘッダファイルsequence 1.h:
作成者が提供するテストファイルsequence_test.cpp:
1、2、3のsequence 1を実現する.cppファイル:
実行結果:
問題に必要な5つの関数を追加します.
インタラクティブテストプログラムを変更するには、次の手順に従います.
テスト結果:
Data Structures and Other Objects Using C++ ( Fourth Edition ) Michael Main, Walter Savitch. p179 ↩︎
Implement the sequence class from Section 3.2. You may wish to provide some additional useful member functions, such as: (1) a function to add a new item at the front of the sequence; (2) a function to remove the item from the front of the sequence; (3) a function to add a new item at the end of the sequence; (4) a function that makes the last item of the sequence become the current item; (5) operators for - and +=. For the + operator, x + y contains all the items of x, followed by all the items of y. The statement x += y appends all of the items of y to the end of what’s already in x.
My answer:
まず本の要求を完成します.作成者が提供するヘッダファイルsequence 1.h:
// FILE: sequence1.h
// CLASS PROVIDED: sequence (part of the namespace main_savitch_3)
// There is no implementation file provided for this class since it is
// an exercise from Section 3.2 of "Data Structures and Other Objects Using C++"
//
// TYPEDEFS and MEMBER CONSTANTS for the sequence class:
// typedef ____ value_type
// sequence::value_type is the data type of the items in the sequence. It
// may 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.
//
// typedef ____ size_type
// sequence::size_type is the data type of any variable that keeps track of
// how many items are in a sequence.
//
// static const size_type CAPACITY = _____
// sequence::CAPACITY is the maximum number of items that a sequence can hold.
//
// CONSTRUCTOR for the sequence class:
// sequence( )
// Postcondition: The sequence has been initialized as an empty sequence.
//
// MODIFICATION MEMBER FUNCTIONS for the sequence class:
// void start( )
// Postcondition: The first item on the sequence becomes the current item
// (but if the sequence is empty, then there is no current item).
//
// 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.
//
// void insert(const value_type& entry)
// Precondition: size( ) < CAPACITY.
// Postcondition: A new copy of entry has been inserted in the sequence
// before the current item. If there was no current item, then the new entry
// has been inserted at the front of the sequence. In either case, the newly
// inserted item is now the current item of the sequence.
//
// void attach(const value_type& entry)
// Precondition: size( ) < CAPACITY.
// Postcondition: A new copy of entry has been inserted in the sequence after
// the current item. If there was no current item, then the new entry has
// been attached to the end of the sequence. In either case, the newly
// inserted item is now the current item of the sequence.
//
// void remove_current( )
// Precondition: is_item returns true.
// Postcondition: The current item has been removed from the sequence, and the
// item after this (if there is one) is now the new current item.
//
// CONSTANT MEMBER FUNCTIONS for the sequence class:
// size_type size( ) const
// Postcondition: The return value is the number of items in the sequence.
//
// bool is_item( ) const
// Postcondition: A true return value indicates that there is a valid
// "current" item that may be retrieved by activating the current
// member function (listed below). A false return value indicates that
// there is no valid current item.
//
// value_type current( ) const
// Precondition: is_item( ) returns true.
// Postcondition: The item returned is the current item in the sequence.
//
// VALUE SEMANTICS for the sequence class:
// Assignments and the copy constructor may be used with sequence objects.
#ifndef MAIN_SAVITCH_SEQUENCE_H
#define MAIN_SAVITCH_SEQUENCE_H
#include // Provides size_t
namespace main_savitch_3
{
class sequence
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef std::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
作成者が提供するテストファイルsequence_test.cpp:
// FILE: sequence_test.cxx
// An interactive test program for the new sequence class
#include // Provides toupper
#include // Provides cout and cin
#include // Provides EXIT_SUCCESS
#include "sequence1.h" // With value_type defined as double
using namespace std;
using namespace main_savitch_3;
// PROTOTYPES for functions used by this test program:
void print_menu( );
// Postcondition: A menu of choices for this program has been written to cout.
char get_user_command( );
// Postcondition: The user has been prompted to enter a one character command.
// The next character has been read (skipping blanks and newline characters),
// and this character has been returned.
void show_sequence(sequence display);
// Postcondition: The items on display have been printed to cout (one per line).
double get_number( );
// Postcondition: The user has been prompted to enter a real number. The
// number has been read, echoed to the screen, and returned by the function.
int main( )
{
sequence test; // A sequence that we’ll perform tests on
char choice; // A command character entered by the user
cout << "I have initialized an empty sequence of real numbers." << endl;
do
{
print_menu( );
choice = toupper(get_user_command( ));
switch (choice)
{
case '!': test.start( );
break;
case '+': test.advance( );
break;
case '?': if (test.is_item( ))
cout << "There is an item." << endl;
else
cout << "There is no current item." << endl;
break;
case 'C': if (test.is_item( ))
cout << "Current item is: " << test.current( ) << endl;
else
cout << "There is no current item." << endl;
break;
case 'P': show_sequence(test);
break;
case 'S': cout << "Size is " << test.size( ) << '.' << endl;
break;
case 'I': test.insert(get_number( ));
break;
case 'A': test.attach(get_number( ));
break;
case 'R': test.remove_current( );
cout << "The current item has been removed." << endl;
break;
case 'Q': cout << "Ridicule is the best test of truth." << endl;
break;
default: cout << choice << " is invalid." << endl;
}
}
while ((choice != 'Q'));
return EXIT_SUCCESS;
}
void print_menu( )
// Library facilities used: iostream.h
{
cout << endl; // Print blank line before the menu
cout << "The following choices are available: " << endl;
cout << " ! Activate the start( ) function" << endl;
cout << " + Activate the advance( ) function" << endl;
cout << " ? Print the result from the is_item( ) function" << endl;
cout << " C Print the result from the current( ) function" << endl;
cout << " P Print a copy of the entire sequence" << endl;
cout << " S Print the result from the size( ) function" << endl;
cout << " I Insert a new number with the insert(...) function" << endl;
cout << " A Attach a new number with the attach(...) function" << endl;
cout << " R Activate the remove_current( ) function" << endl;
cout << " Q Quit this test program" << endl;
}
char get_user_command( )
// Library facilities used: iostream
{
char command;
cout << "Enter choice: ";
cin >> command; // Input of characters skips blanks and newline character
return command;
}
void show_sequence(sequence display)
// Library facilities used: iostream
{
for (display.start( ); display.is_item( ); display.advance( ))
cout << display.current( ) << endl;
}
double get_number( )
// Library facilities used: iostream
{
double result;
cout << "Please enter a real number for the sequence: ";
cin >> result;
cout << result << " has been read." << endl;
return result;
}
1、2、3のsequence 1を実現する.cppファイル:
#include "sequence1.h"
#include
#include
using namespace std;
using namespace main_savitch_3;
sequence::sequence(){
// If there is a current item, then it lies in data[current_index];
// if there is no current item, then current_index equals used.
current_index = used = 0;
}
void sequence::start(){
current_index = 0;
}
void sequence::advance(){
current_index = (current_index + 1) % CAPACITY;
// the max of current_index is CAPACITY-1
}
void sequence::insert(const value_type& entry){
assert(size() < CAPACITY);
size_type i;
if(current_index == used){//no current item
for(i = current_index; i != 0; i--){
data[i] = data[i-1];
}
data[i] = entry;
used++;
current_index = i;
return;
}
for(i = current_index; i < size(); i++);
for(; i != current_index; i--){
data[i] = data[i-1];
}
data[i] = entry;// now i equals current_index
used++;
}
void sequence::attach(const value_type& entry){
assert(size() < CAPACITY);
size_type i;
if(current_index == used){//no current item
data[current_index] = entry;
used++;
return;
}
for(i = current_index; i < size(); i++);
for(; i != current_index; i--){
data[i] = data[i-1];
}
data[i+1] = entry;// put entry in data[current_index+1]
used++;
}
void sequence::remove_current(){
assert(is_item());
if(current_index == size()-1){
// the last one
used--;
} else {
for(size_type i = current_index; i < size(); i++){
data[i] = data[i+1];
}
used--;
}
}
sequence::size_type sequence::size() const{
return used;
}
bool sequence::is_item() const{
if(current_index >= used){
return false;
} else {
return true;
}
}
sequence::value_type sequence::current() const{
assert(is_item());
return data[current_index];
}
実行結果:
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: A
Please enter a real number for the sequence: 4.13
4.13 has been read.
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: S
Size is 1.
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: I
Please enter a real number for the sequence: 9
9 has been read.
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: S
Size is 2.
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: A
Please enter a real number for the sequence: 4
4 has been read.
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: S
Size is 3.
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: C
Current item is: 9
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: C
Current item is: 4
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: C
Current item is: 4.13
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: P
9
4
4.13
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: R
The current item has been removed.
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: D
D is invalid.
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: S
Size is 2.
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: Q
Ridicule is the best test of truth.
[1] + Done /usr/bin/gdb --interpreter=mi --tty=${DbgTerm} 0/tmp/Microsoft-MIEngine-Out-cgrqdfyo.aov
...
問題に必要な5つの関数を追加します.
void sequence::insert_head(const value_type& entry){
assert(size() < CAPACITY);
size_t i = size();
for(; i > 0; i--){
data[i] = data[i-1];//
}
// i = 0
data[i] = entry;
used++;
}
void sequence::remove_head(){
assert(size() > 0);
size_t i = 0;
for(; i < size(); i++){
data[i] = data[i+1];
}
used--;
}
void sequence::insert_tail(const value_type& entry){
assert(size() < CAPACITY);
data[size()] = entry;
used++;
}
void sequence::end(){
current_index = size() - 1;
}
sequence sequence::operator -(sequence& entry){
sequence res;
for(this->start(); this->is_item(); this->advance()){
res.insert(this->current());
}
for(entry.start(); entry.is_item(); entry.advance()){
for(res.start(); res.is_item(); res.advance()){
if(res.current() == entry.current()){
res.remove_current();
}
}
}
return res;
}
void sequence::operator -=(sequence& entry){
for(entry.start(); entry.is_item(); entry.advance()){
for(start(); is_item(); advance()){
if(entry.current() == current()){
remove_current();
}
}
}
}
インタラクティブテストプログラムを変更するには、次の手順に従います.
// FILE: sequence_test.cxx
// An interactive test program for the new sequence class
#include // Provides toupper
#include // Provides cout and cin
#include // Provides EXIT_SUCCESS
#include "sequence1.h" // With value_type defined as double
using namespace std;
using namespace main_savitch_3;
// PROTOTYPES for functions used by this test program:
void print_menu( );
// Postcondition: A menu of choices for this program has been written to cout.
char get_user_command( );
// Postcondition: The user has been prompted to enter a one character command.
// The next character has been read (skipping blanks and newline characters),
// and this character has been returned.
void show_sequence(sequence display);
// Postcondition: The items on display have been printed to cout (one per line).
double get_number( );
// Postcondition: The user has been prompted to enter a real number. The
// number has been read, echoed to the screen, and returned by the function.
int main( )
{
sequence test, test1, test2; // A sequence that we’ll perform tests on
char choice; // A command character entered by the user
cout << "I have initialized an empty sequence of real numbers." << endl;
do
{
print_menu( );
choice = toupper(get_user_command( ));
switch (choice)
{
case '!': test.start( );
break;
case '@': test.end();
break;
case '+': test.advance( );
break;
case '?': if (test.is_item( ))
cout << "There is an item." << endl;
else
cout << "There is no current item." << endl;
break;
case 'C': if (test.is_item( ))
cout << "Current item is: " << test.current( ) << endl;
else
cout << "There is no current item." << endl;
break;
case 'P': show_sequence(test);
break;
case 'S': cout << "Size is " << test.size( ) << '.' << endl;
break;
case 'I': test.insert(get_number( ));
break;
case 'A': test.attach(get_number( ));
break;
case 'R': test.remove_current( );
cout << "The current item has been removed." << endl;
break;
case 'H': test.insert_head(get_number());
break;
case 'L': test.remove_head();
cout << "The item in the head has been removed." << endl;
break;
case 'Z': test.insert_tail(get_number());
cout << "A new item has been inserted into the tail." << endl;
break;
case 'T': test1.insert(1);
test1.insert(2);
test1.insert(3);
cout << "test:" << endl;
show_sequence(test);
cout << "test1:" << endl;
show_sequence(test1);
test2 = test - test1;
cout << "test2 = test - test1, its result is" << endl;
show_sequence(test2);
test -= test1;
cout << "test -= test1, its result is" << endl;
show_sequence(test);
break;
case 'Q': cout << "Ridicule is the best test of truth." << endl;
break;
default: cout << choice << " is invalid." << endl;
}
}
while ((choice != 'Q'));
return EXIT_SUCCESS;
}
void print_menu( )
// Library facilities used: iostream.h
{
cout << endl; // Print blank line before the menu
cout << "The following choices are available: " << endl;
cout << " ! Activate the start( ) function" << endl;
cout << " @ Activate the end() function" << endl;
cout << " + Activate the advance( ) function" << endl;
cout << " ? Print the result from the is_item( ) function" << endl;
cout << " C Print the result from the current( ) function" << endl;
cout << " P Print a copy of the entire sequence" << endl;
cout << " S Print the result from the size( ) function" << endl;
cout << " I Insert a new number with the insert(...) function" << endl;
cout << " A Attach a new number with the attach(...) function" << endl;
cout << " R Activate the remove_current( ) function" << endl;
cout << " H Insert a new item with insert_head() function" << endl;
cout << " L Remove an item with remove_head() function" << endl;
cout << " Z Insert a new item with insert_tail() function" << endl;
cout << " T Test the operator - and -=" << endl;
cout << " Q Quit this test program" << endl;
}
char get_user_command( )
// Library facilities used: iostream
{
char command;
cout << "Enter choice: ";
cin >> command; // Input of characters skips blanks and newline character
return command;
}
void show_sequence(sequence display)
// Library facilities used: iostream
{
for (display.start( ); display.is_item( ); display.advance( ))
cout << display.current( ) << endl;
}
double get_number( )
// Library facilities used: iostream
{
double result;
cout << "Please enter a real number for the sequence: ";
cin >> result;
cout << result << " has been read." << endl;
return result;
}
テスト結果:
I have initialized an empty sequence of real numbers.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: 1
1 is invalid.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: I
Please enter a real number for the sequence: 2
2 has been read.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: I
Please enter a real number for the sequence: 3
3 has been read.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: I4
Please enter a real number for the sequence: 4 has been read.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: I7
Please enter a real number for the sequence: 7 has been read.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: I
Please enter a real number for the sequence: 5
5 has been read.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: P
5
7
4
3
2
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: H
Please enter a real number for the sequence: 2
2 has been read.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: H
Please enter a real number for the sequence: 0
0 has been read.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: P
0
2
5
7
4
3
2
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: L
The item in the head has been removed.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: P
2
5
7
4
3
2
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: Z
Please enter a real number for the sequence: 9.9
9.9 has been read.
A new item has been inserted into the tail.
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: P
2
5
7
4
3
2
9.9
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Enter choice: T
test:
2
5
7
4
3
2
9.9
test1:
3
2
1
test2 = test - test1, its result is
9.9
4
7
5
test -= test1, its result is
5
7
4
9.9
The following choices are available:
! Activate the start( ) function
@ Activate the end() 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
H Insert a new item with insert_head() function
L Remove an item with remove_head() function
Z Insert a new item with insert_tail() function
T Test the operator - and -=
Q Quit this test program
Q
Enter choice: Ridicule is the best test of truth.
Data Structures and Other Objects Using C++ ( Fourth Edition ) Michael Main, Walter Savitch. p179 ↩︎