Please implement the functions in C++ (in the .tpp file) Only 6 functions to implement!! Where it says: //To be implemen

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Please implement the functions in C++ (in the .tpp file) Only 6 functions to implement!! Where it says: //To be implemen

Post by answerhappygod »

Please implement the functions in C++ (in the .tpp file) Only 6
functions to implement!! Where it says: //To be implemented by
students
// FILE: table2.tpp.h
// TEMPLATE CLASS IMPLEMENTED: Table (see table2.h for
documentation)
#include // Provides assert
#include // Provides nullptr, size_t
#include "link2.h" // Provides the linked list toolkit
template <class RecordType>
Table::Table( )
// Library facilities used: stdlib.h
{
size_t i;
total_records = 0;
for (i = 0; i < TABLE_SIZE; i++)
data = nullptr;
}
template <class RecordType>
Table::Table(const Table& source)
// Library facilities used: link2.h, stdlib.h
{
size_t i;
Node* tail_ptr; // Needed for list_copy
for (i = 0; i < TABLE_SIZE; i++)
list_copy(source.data, data, tail_ptr);
total_records = source.total_records;
}
template <class RecordType>
Table::~Table( )
// Library facilities used: link2.h
{
size_t i;
total_records = 0;
for (i = 0; i < TABLE_SIZE; i++)
list_clear(data);
}
template <class RecordType>
void Table::insert(const RecordType&
entry)
// Library facilities used: assert.h, link2.h
{
Node* cursor; // set to point to existing Node with given
key
assert(entry.key >= 0);
// Set cursor to point to existing Node with given key (if there
is one)
// To be implemented by students
}
template <class RecordType>
void Table::remove(int key)
// Library facilities used: assert.h, link2.h
{
Node *cursor; // Points to existing Node with given key
Node *precursor; // Points to node before the cursor
assert(key >= 0);
// Set cursor to point to existing Node with given key (if there
is one)
// To be implemented by students
}
template <class RecordType>
void Table::operator =(const Table&
source)
// Library facilities used: link2.h, stdlib.h
{
size_t i;
Node* tail_ptr; // Needed for list_copy
// To be implemented by students
}
template <class RecordType>
bool Table::is_present(int key) const
// Library facilities used: assert.h, stdlib.h
{
assert(key >= 0);
// To be implemented by students
}
template <class RecordType>
void Table::find(int key, bool&
found, RecordType& result) const
// Library facilities used: stdlib.h
{
Node *cursor;
// To be implemented by students
}
template <class RecordType>
size_t
Table::hash(int key) const
// Library facilities used: stdlib.h
{
return (key % TABLE_SIZE);
}
template <class RecordType>
Node*
Table::find_node(int key) const
// Postcondition: The return value is a pointer to the record
with the
// specified key (if there is one). If there is no such node,
the return value
// is the nullptr pointer.
// Library facilities used: link2.h, stdlib.h
{
Node* cursor;
// To be implemented by students
}
.
.
.
// FILE: table2.h
// TEMPLATE CLASS PROVIDED: Table
// This class is a container template class for a Table of
records.
// The template parameter, RecordType, is the data type of the
records in the
// Table. It may any type with a default constructor, a copy
constructor,
// an assignment operator, and an integer member variable called
key.
//
// CONSTRUCTOR for the Table template class:
// Table( )
// Postcondition: The Table has been initialized as an empty
Table.
//
// MODIFICATION MEMBER FUNCTIONS for the Table class:
// void insert(const RecordType& entry)
// Precondition: entry.key >= 0. Also if entry.key is not
already a key in
// the table, then the Table has space for another record
// (i.e., size( ) < CAPACITY).
// Postcondition: If the table already had a record with a key
equal to
// entry.key, then that record is replaced by entry. Otherwise,
entry has
// been added as a new record of the Table.
//
// void remove(int key)
// Postcondition: If a record was in the Table with the specified
key, then
// that record has been removed; otherwise the table is
unchanged.
//
// CONSTANT MEMBER FUNCTIONS for the Table class:
// bool is_present(const Item& target) const
// Postcondition: The return value is true if there is a record in
the
// Table with the specified key. Otherwise, the return value is
false.
//
// void find(int key, bool& found, RecordType& result)
const
// Postcondition: If a record is in the Table with the specified
key, then
// found is true and result is set to a copy of the record with
that key.
// Otherwise found is false and the result contains garbage.
//
// size_t size( ) const
// Postcondition: Return value is the total number of records in
the
// Table.
//
// VALUE SEMANTICS for the Table template class:
// Assignments and the copy constructor may be used with Table
objects.
//
// DYNAMIC MEMORY USAGE by the Table template class:
// If there is insufficient dynamic memory, then the following
functions
// can call new_handler: the copy constructor, insert, the
assignment
// operator.
#ifndef TABLE1_H
#define TABLE1_H
#include "link2.h"
#include // Provides size_t
template
class Table
{
public:
// MEMBER CONSTANT
enum { TABLE_SIZE = 811 }; // Or: static const size_t TABLE_SIZE =
811;
// CONSTRUCTORS and DESTRUCTOR
Table( );
Table(const Table& source);
~Table( );
// MODIFICATION MEMBER FUNCTIONS
void insert(const RecordType& entry);
void remove(int key);
void operator =(const Table& source);
// CONSTANT MEMBER FUNCTIONS
void find(int key, bool& found, RecordType& result)
const;
bool is_present(int key) const;
size_t size( ) const { return total_records; }
private:
Node *data[TABLE_SIZE];
size_t total_records;
// HELPER FUNCTION
size_t hash(int key) const;
Node* find_node(int key) const;
};
#include "table2.tpp.h" // Include the implementation
#endif
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply