Professional Documents
Culture Documents
Solved - Chapter 5 Problem 19PP Solution - Data Structures and Other Objects Using C++ 4th Edition
Solved - Chapter 5 Problem 19PP Solution - Data Structures and Other Objects Using C++ 4th Edition
Solved - Chapter 5 Problem 19PP Solution - Data Structures and Other Objects Using C++ 4th Edition
My courses
My books My folder Career Life Study Pack
Your subscription will expire on Dec 25, 2021. Turn on auto-renew to keep accessing solutions.
Turn on auto-renew
home / study / engineering / computer science / computer architecture / computer architecture solutions manuals / data structures and other objects using c++ / 4th edition / chapter 5 / problem 19p
(4th Edition)
Enter question
Chapter 5, Problem 19PP Bookmark Show all steps: ON
Step-by-step solution
Continue to post
20 questions remaining
Step 1 of 16
Refer to the specifications and design of node class given in FIGURE 5.10 for the complete code
from the textbook. My Textbook Solutions
Refer to the implementation of Linked List toolkit given from page 232 to 253 from the textbook.
Refer to the specifications, design and implementation of bag class using linked list given in the
FIGURE 5.11 and FIGURE 5.14 for the complete code from the textbook. Add a
textboo
Data Auditing &
Comment Structures... Assurance...
4th Edition 6th Edition
Step 2 of 16
Programming Plan:
• Include the utility header in node class which contain the definition for the pair class.
• In the bag class modify the following functions to include functionality for the pair class:
• count(): modify the function to test for the second member of the pair class to check for a
match.
Great Clips® Near You
• erase(): modify this to match for the second member of the pair class and then if a match is
found then erase this node. Great Clips
Frisco 10AM–5PM
• erase_one(): modify this to match for the second member of the pair class and then if a match
is found then erase this node.
• grab(): modify the function to return the second member of the pair class object.
• insert(): modify this function to insert a pair object as the data of the node.
• operator+=: modify to add the second member of the addend to this bag.
• print(): define this method to print both the first as well as second member of the data.
Comment
Home Study tools
My courses
My books My folder Career Life Study Pack
Step 3 of 16
Program:
node1.h file:
// FILE: node1.h
// .
// .
// .
#ifndef MAIN_SAVITCH_NODE1_H
#define MAIN_SAVITCH_NODE1_H
#include
namespace main_savitch_5
class node
public:
// TYPEDEF
value_type;
// .
// .
// .
};
// .
// .
// .
#endif
Comment
Step 4 of 16
node1.cxx file:
// FILE: node1.cxx
#include "node1.h"
#include
namespace main_savitch_5
// .
// .
// . Home Study tools
My courses
My books My folder Career Life Study Pack
Comment
Step 5 of 16
bag3.h file:
// FILE: bag3.h
// .
// .
// .
#ifndef MAIN_SAVITCH_BAG3_H
#define MAIN_SAVITCH_BAG3_H
namespace main_savitch_5
class bag
public:
// TYPEDEFS
// .
// .
// .
};
// .
// .
// .
#endif
Comment
Step 6 of 16
bag3.cxx file:
// FILE: bag3.cxx
// .
// .
// .
#include "bag3.h"
namespace main_savitch_5
// .
// .
// .
target) const
// define a counter
size_type value_count = 0;
node *cursor;
cursor = cursor->link( ))
value_count = cursor->data().first;
break;
return value_count;
target)
size_type value_count = 0;
if(size() == 0)
return value_count;
node *cursor;
Comment
Step 7 of 16
for (cursor = head_ptr; cursor != NULL;
cursor Home Study tools
My courses
My books My folder Career Life Study Pack
= cursor->link( ))
value_count = cursor->data().first;
break;
previous_node = cursor;
if(previous_node == NULL)
if(cursor->link() == NULL)
head_ptr = NULL;
else
head_ptr = head_ptr->link();
else
previous_node->set_link(cursor->link());
many_nodes -= value_count;
return value_count;
Comment
Step 8 of 16
size_type value_count = 0;
if(size() == 0)
return value_count;
node *cursor;
cursor = cursor->link( ))
value_count = cursor->data().first;
is_found = true;
break;Home Study tools
My courses
My books My folder Career Life Study Pack
previous_node = cursor;
.first > 1)
head_ptr->set_data(make_pair(
head_ptr->data().first - 1,
head_ptr->data().second));
.first == 1)
if(cursor->link() == NULL)
head_ptr = NULL;
else
head_ptr = head_ptr->link();
data().first > 1)
cursor->set_data(make_pair(cursor->data()
.first - 1, cursor->data().second));
previous_node->set_link(cursor->link());
else
return false;
--many_nodes;
return true;
Comment
Step 9 of 16
size_type idx;
// declare a node to traverse
node *cursor;
Home Study tools
My courses
My books My folder Career Life Study Pack
if(head_ptr == NULL)
list_head_insert(head_ptr, make_pair(1,
entry));
++many_nodes;
return;
< entry)
previous = cursor;
cursor = cursor->link();
entry)
cursor->set_data(make_pair(cursor->data()
.first + 1, cursor->data().second));
list_head_insert(head_ptr, make_pair(1,
entry));
else
}
// increment number of elements
++many_nodes;
Home Study tools
My courses
My books My folder Career Life Study Pack
while(current != NULL)
.first; idx++)
insert(current->data().second);
current = current->link();
// .
// .
// .
Comment
Step 10 of 16
// .
// .
// .
void bag::print()
node *cursor;
cursor = cursor->link())
Comment
Step 11 of 16
bagtester.cpp file:
#include
#include
#include "bag3.cxx"
int main()
bag bag1;
bag1.insert(10.125);
bag1.insert(10.125);
bag1.insert(10.125);
bag1.insert(10.123);
bag1.insert(10.123);
bag1.insert(1.5);
bag1.insert(100.5);
bag1.insert(10.124);
bag1.insert(10.123);
<< endl;
<< endl;
<< endl;
<< endl;
bag1.erase(10.125);
bag1.print();
<< endl;
bag1.erase(10.123);
bag1.print();
<< endl;
<< endl;
Comment
Step 12 of 16
<< endl;
bag1.insert(10.125);
bag1.insert(10.125);
bag1.insert(10.125);
bag1.insert(10.125);
bag1.insert(10.125);
bag1.insert(10.125);
bag1.print();
bag1.erase_one(10.125);
bag1.print();
<< endl;
"Number of 100.5 is -> " << bag1.count(100.5)
My books My folder Career Life Study Pack
<< endl;
bag1.erase_one(10.123);
bag1.print();
<< endl;
<< endl;
<< endl;
bag1.erase_one(10.124);
bag1.print();
<< endl;
<< endl;
<< endl;
bag1.erase_one(100.5);
bag1.print();
<< endl;
<< endl;
bag bag2;
bag2.insert(25.1);
bag2.insert(25.1);
bag2.insert(25.1);
bag2.insert(25.1);
bag2.insert(250.1);
bag2.insert(125.1);
bag2.insert(1.5);
bag2.insert(1000.1);
bag1.print();
Comment
Step 13 of 16
bag2.print();
bag1 += bag2;
bag1.print();
bag3.print();
bag4.print();
bag4 = bag2;
bag4.print();
Comment
Step 14 of 16
Sample output:
10.123
10.124
100.5
1.5 Home Study tools
My courses
My books My folder Career Life Study Pack
100.5
100.5
10.125
10.125
10.124
100.5
1.5
1.5
10.123
10.124
10.123
10.123
1.5
10.124
10.124
10.123
10.123
100.5
10.124
10.125
10.124
10.124
10.123
10.123
10.125
1.5
10.124
10.123
10.123
10.125
100.5
10.124
10.124
100.5
1.5
100.5
10.125
10.123
10.124
10.125
10.125
100.5
10.123
10.123
10.125
10.125
of 1.5 is -> 1
My courses
My books My folder Career Life Study Pack
(1, 1.5)
(3, 10.123)
(1, 10.124)
(3, 10.125)
(1, 100.5)
(1, 1.5)
(3, 10.123)
(1, 10.124)
(1, 100.5)
Comment
Step 15 of 16
(1, 1.5)
(1, 10.124)
(1, 100.5)
(1, 1.5)
(1, 10.124)
(6, 10.125)
(1, 100.5)
(1, 1.5)
(1, 10.124)
(5, 10.125)
(1, 100.5)
(1, 1.5)
(1, 10.124)
(5, 10.125)
Home Study tools
My courses
My books My folder Career Life Study Pack
(1, 100.5)
(1, 1.5)
(5, 10.125)
(1, 100.5)
(1, 1.5)
(5, 10.125)
(1, 1.5)
(5, 10.125)
(1, 1.5)
(4, 25.1)
(1, 125.1)
(1, 250.1)
(1, 1000.1)
(2, 1.5)
(5, 10.125)
(4, 25.1)
(1, 125.1)
(1, 250.1)
(1, 1000.1)
(3, 1.5)
(5, 10.125)
(8, 25.1)
(2, 125.1)
(2, 250.1)
Home Study tools
My courses
My books My folder Career Life Study Pack
(2, 1000.1)
Comment
Step 16 of 16
(3, 1.5)
(5, 10.125)
(8, 25.1)
(2, 125.1)
(2, 250.1)
(2, 1000.1)
(1, 1.5)
(4, 25.1)
(1, 125.1)
(1, 250.1)
(1, 1000.1)
Comment
Refer to the specification and design of card class Refer to the specification and design of sequence
from Chapter 2 Project 4. Refer to the specification class provided under section 5.4 from the textbook.
and design of deck...
See solution
See solution
COMPANY