Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone one fix this to work in visual studios in c++? Errors I am getting are at the bottom. //node2.h #ifndef MAIN_SAVITCH_NODE2_H #define MAIN_SAVITCH_NODE2_H

Can someone one fix this to work in visual studios in c++? Errors I am getting are at the bottom.

//node2.h

#ifndef MAIN_SAVITCH_NODE2_H #define MAIN_SAVITCH_NODE2_H #include // Provides NULL and size_t #include // Provides iterator and forward_iterator_tag

namespace main_savitch_6B { template class node { public: typedef Item value_type; node(const Item& init_data = Item(), node* init_link = NULL) { data_field = init_data; link_field = init_link; } Item& data() { return data_field; } node* link() { return link_field; } void set_data(const Item& new_data) { data_field = new_data; } void set_link(node* new_link) { link_field = new_link; } const Item& data() const { return data_field; } const node* link() const { return link_field; } private: Item data_field; node *link_field; };

template void list_clear(node*& head_ptr);

template void list_copy (const node* source_ptr, node*& head_ptr, node*& tail_ptr);

template void list_head_insert(node*& head_ptr, const Item& entry);

template void list_head_remove(node*& head_ptr);

template void list_insert(node* previous_ptr, const Item& entry);

template std::size_t list_length(const node* head_ptr);

template NodePtr list_locate(NodePtr head_ptr, SizeType position);

template void list_remove(node* previous_ptr);

template NodePtr list_search(NodePtr head_ptr, const Item& target);

template class node_iterator : public std::iterator { public: node_iterator(node* initial = NULL) { current = initial; } Item& operator *() const { return current->data(); } node_iterator& operator ++() // Prefix ++ { current = current->link(); return *this; } node_iterator operator ++(int) // Postfix ++ { node_iterator original(current); current = current->link(); return original; } bool operator ==(const node_iterator other) const { return current == other.current; } bool operator !=(const node_iterator other) const { return current != other.current; } private: node* current; };

template class const_node_iterator : public std::iterator { public: const_node_iterator(const node* initial = NULL) { current = initial; } const Item& operator *() const { return current->data(); } const_node_iterator& operator ++() // Prefix ++ { current = current->link(); return *this; } const_node_iterator operator ++(int) // Postfix ++ { const_node_iterator original(current); current = current->link(); return original; } bool operator ==(const const_node_iterator other) const { return current == other.current; } bool operator !=(const const_node_iterator other) const { return current != other.current; } private: const node* current; }; }

#include "node2.template" #endif

//node2.template

#include "stdafx.h" #include // Provides assert #include // Provides NULL and size_t

namespace main_savitch_6B { template void list_clear(node*& head_ptr) // Library facilities used: cstdlib { while (head_ptr != NULL) list_head_remove(head_ptr); }

template void list_copy( const node* source_ptr, node*& head_ptr, node*& tail_ptr ) // Library facilities used: cstdlib { head_ptr = NULL; tail_ptr = NULL;

// Handle the case of the empty list if (source_ptr == NULL) return;

// Make the head node for the newly created list, and put data in it list_head_insert(head_ptr, source_ptr->data( )); tail_ptr = head_ptr; // Copy rest of the nodes one at a time, adding at the tail of new list source_ptr = source_ptr->link( ); while (source_ptr != NULL) { list_insert(tail_ptr, source_ptr->data( )); tail_ptr = tail_ptr->link( ); source_ptr = source_ptr->link( ); } } template void list_head_insert(node*& head_ptr, const Item& entry) { head_ptr = new node(entry, head_ptr); }

template void list_head_remove(node*& head_ptr) { node *remove_ptr;

remove_ptr = head_ptr; head_ptr = head_ptr->link( ); delete remove_ptr; }

template void list_insert(node* previous_ptr, const Item& entry) { node *insert_ptr; insert_ptr = new node(entry, previous_ptr->link( )); previous_ptr->set_link(insert_ptr); }

template std::size_t list_length(const node* head_ptr) // Library facilities used: cstdlib { const node *cursor; std::size_t answer; answer = 0; for (cursor = head_ptr; cursor != NULL; cursor = cursor->link( )) ++answer; return answer; }

template NodePtr list_locate(NodePtr head_ptr, SizeType position) // Library facilities used: cassert, cstdlib { NodePtr cursor; SizeType i; assert(0 < position); cursor = head_ptr; for (i = 1; (i < position) && (cursor != NULL); ++i) cursor = cursor->link( ); return cursor; }

template void list_remove(node* previous_ptr) { node *remove_ptr;

remove_ptr = previous_ptr->link( ); previous_ptr->set_link(remove_ptr->link( )); delete remove_ptr; }

template NodePtr list_search(NodePtr head_ptr, const Item& target) // Library facilities used: cstdlib { NodePtr cursor; for (cursor = head_ptr; cursor != NULL; cursor = cursor->link( )) if (target == cursor->data( )) return cursor; return NULL; } }

//table2.h

#ifndef TABLE2_H #define TABLE2_H #include #include "node2.h"

namespace main_savitch_12B { template class table { public: static const std::size_t TABLE_SIZE = 811; table(); table(const table& source); ~table(); void insert(const RecordType& entry); void remove(int key); void operator =(const table& source); void find(int key, bool& found, RecordType& result) const; bool is_present(int key) const; std::size_t size() const { return total_records; }

private: main_savitch_6B::node *data[TABLE_SIZE]; std::size_t total_records; std::size_t hash(int key) const; }; } #include "table2.template" #endif

//table2.template

using namespace main_savitch_12B; template table::table() { total_records = 0; }

template table::table(const table& source) { copy(source.data, source.data + total_records, data); total_records = source.total_records; }

template table::~table() { }

template void table::insert(const RecordType &entry) { assert(entry.key >= 0); size_t index = hash(entry.key); if (!is_present(entry.key)) { data[index].push_back(entry); ++total_records; } else { for (typename list::iterator i = data[index].begin(); i != data[index].end(); ++i) { if (i->key == entry.key) { *i = entry; break; } } } }

template void table::remove(int key) { if (is_present(key)) { int index = hash(key); for (typename list::iterator i = data[index].begin(); i != data[index].end(); ++i) { if (i->key == key) { data[index].erase(i); --total_records; return; } } } }

template void table::operator =(const table &source) { if (this != &source) { copy(source.data, source.data + total_records, data); total_records = source.total_records; } }

template void table::find(int key, bool &found, RecordType &result) const { size_t index = hash(key); for (typename list::const_iterator i = data[index].begin(); i != data[index].end() ; i++) { if (key == i->key) { found = true; result = *i; return; } } found = false; }

template bool table::is_present(int key) const { size_t index = hash(key); for (typename list::const_iterator i = data[index].begin(); i != data[index].end() ; i++) { if (key == i->key) { return true; } } return false; }

template size_t table::hash(int key) const { return (key % TABLE_SIZE); }

//testlab2.cpp

using namespace main_savitch_12B; template table::table() { total_records = 0; }

template table::table(const table& source) { copy(source.data, source.data + total_records, data); total_records = source.total_records; }

template table::~table() { }

template void table::insert(const RecordType &entry) { assert(entry.key >= 0); size_t index = hash(entry.key); if (!is_present(entry.key)) { data[index].push_back(entry); ++total_records; } else { for (typename list::iterator i = data[index].begin(); i != data[index].end(); ++i) { if (i->key == entry.key) { *i = entry; break; } } } }

template void table::remove(int key) { if (is_present(key)) { int index = hash(key); for (typename list::iterator i = data[index].begin(); i != data[index].end(); ++i) { if (i->key == key) { data[index].erase(i); --total_records; return; } } } }

template void table::operator =(const table &source) { if (this != &source) { copy(source.data, source.data + total_records, data); total_records = source.total_records; } }

template void table::find(int key, bool &found, RecordType &result) const { size_t index = hash(key); for (typename list::const_iterator i = data[index].begin(); i != data[index].end() ; i++) { if (key == i->key) { found = true; result = *i; return; } } found = false; }

template bool table::is_present(int key) const { size_t index = hash(key); for (typename list::const_iterator i = data[index].begin(); i != data[index].end() ; i++) { if (key == i->key) { return true; } } return false; }

template size_t table::hash(int key) const { return (key % TABLE_SIZE); }

Severity Code Description Project File Line Suppression State Error C2228 left of '.push_back' must have class/struct/union TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 25 Error C2065 'list': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2275 'RecordType': illegal use of this type as an expression TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2955 'std::iterator': use of class template requires template argument list TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2146 syntax error: missing ';' before identifier 'i' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2143 syntax error: missing ';' before '=' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2143 syntax error: missing ')' before '=' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2059 syntax error: '=' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2065 'i': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2228 left of '.end' must have class/struct/union TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2059 syntax error: ')' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 29 Error C2059 syntax error: 'if' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 30 Error C2143 syntax error: missing ';' before '{' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 30 Error C2065 'i': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 31 Error C2043 illegal break TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 32 Error C2059 syntax error: '}' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 36 Error C2143 syntax error: missing ';' before '}' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 36 Error C2065 'RecordType': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 39 Error C2923 'main_savitch_12B::table': 'RecordType' is not a valid template type argument for parameter 'RecordType' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 39 Error C2955 'main_savitch_12B::table': use of class template requires template argument list TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 39 Error C2143 syntax error: missing ';' before '{' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 39 Error C2447 '{': missing function header (old-style formal list?) TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 39 Error C2065 'list': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2275 'RecordType': illegal use of this type as an expression TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2039 'const_iterator': is not a member of '`global namespace'' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2065 'const_iterator': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2146 syntax error: missing ';' before identifier 'i' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2143 syntax error: missing ';' before '=' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2143 syntax error: missing ')' before '=' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2059 syntax error: '=' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2065 'i': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2228 left of '.end' must have class/struct/union TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2059 syntax error: ')' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 64 Error C2059 syntax error: 'if' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 65 Error C2143 syntax error: missing ';' before '{' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 65 Error C2065 'i': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 67 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 71 Error C2059 syntax error: '}' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 72 Error C2143 syntax error: missing ';' before '}' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 72 Error C2065 'RecordType': undeclared identifier TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 75 Error C2923 'main_savitch_12B::table': 'RecordType' is not a valid template type argument for parameter 'RecordType' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 75 Error C2955 'main_savitch_12B::table': use of class template requires template argument list TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 75 Error C2143 syntax error: missing ';' before '{' TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 75 Error C2447 '{': missing function header (old-style formal list?) TomHensonHW12 c:\users\tehen\source epos\tomhensonhw12\tomhensonhw12\table2.template 75

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn Mysql The Easy Way A Beginner Friendly Guide

Authors: Kiet Huynh

1st Edition

B0CNY7143T, 979-8869761545

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago