Question

there show an error in sample.cpp file that more than one instance of overloaded function find...

there show an error in sample.cpp file that more than one instance of overloaded function find matches the argument list. can you please fix it. and rewrite the program and debug. thanks. I also wrote error below on which line in sample.cpp. it shows on find.

#include #include #include "node1.cpp"

using namespace main_savitch_5;

// node1.h

#ifndef MAIN_SAVITCH_NODE1_H

#define MAIN_SAVITCH_NODE1_H

#include <string>

namespace main_savitch_5

{

   template<class item>

   class node

   {

   public:

       typedef item value_type;

       node(const value_type& init_data = value_type(), node* init_link = NULL)

       {

           data_field = init_data;

           link_field = init_link;

       }

       void set_data(const value_type& new_data)

       {

           data_field = new_data;

       }

       void set_link(node<item>* new_link)

       {

           link_field = new_link;

       }

       value_type data()const

       {

           return data_field;

       }

       const node<item>* link()const

       {

           return link_field;

       }

       node<item>* link()

       {

           return link_field;

       }

   private:

       value_type data_field;

       node<item>* link_field;

   };

   template<class item>

   std::size_t list_length(const node<item>* head_ptr);

   template<class item>

   void list_head_insert(node<item>*& head_ptr, const node<int>::value_type& entry);

   template<class item>

   void list_insert(node<item>* previous_ptr, const node<int>::value_type& entry);

   template<class item>

   node<item>* list_search(node<item>* head_ptr, const node<int>::value_type& target);

   template<class item>

   const node<item>* list_search(const node<item>* head_ptr, const node<int>::value_type& target);

   template<class item>

   node<item>* list_locate(node<item>* head_ptr, std::size_t position);

   template<class item>

   const node<item>* list_locate(const node<item>* head_ptr, std::size_t position);

   template<class item>

   void list_head_remove(node<item>*& head_ptr);

   template<class item>

   void list_remove(node<item>* previous_ptr);

   template<class item>

   void list_copy(const node<item>* source_ptr, node<item>*& tail_ptr);

}

#endif

//node1.cpp

#include "node1.h"

#include <cassert> // for assert

using namespace std;

namespace main_savitch_5

{

   template<class item>

   size_t list_length(const node<item>* head_ptr)

   {

       const node<item>* cursor;

       size_t answer;

       answer = 0;

       for (cursor = head_ptr; cursor != NULL; cursor = cursor->link())

           ++answer;

       return answer;

   }

   template<class item>

   void list_head_insert(node<item>*& head_ptr, const node<int>::value_type& entry)

   {

       head_ptr = new node<item>(entry, head_ptr);

   }

   template<class item>

   void list_insert(node<item>* previous_ptr, const node<int>::value_type& entry)

   {

       node<item>* insert_ptr;

       insert_ptr = new node<item>(entry, previous_ptr());

       previous_ptr->set_link(insert_ptr);

   }

   template<class item>

   node<item>* list_search(node<item>* head_ptr, const node<int>::value_type& target)

   {

       node<item>* cursor;

       for (cursor = head_ptr; cursor != NULL; cursor = cursor->link())

           return cursor;

       return NULL;

   }

   template<class item>

   const node<item>* list_search(const node<item>* head_ptr, const node<int>::value_type& target)

   {

       const node<item>* cursor;

       for (cursor = head_ptr; cursor != NULL; cursor = cursor->linl())

           if (target == cursor->data())

               return cursor;

       return NULL;

   }

   template<class item>

   node<int>* list_locate(node<int>* head_ptr, size_t position)

   {

       size_t i;

       node<int>* cursor; (0 < position);

       cursor = head_ptr;

       for (i = 1; (i < position && cursor != NULL);

           i++)

           cursor = cursor->link();

       return cursor;

   }

   template<class item>

   const node<int>* list_locate(const node<int>* head_ptr, size_t position)

   {

       const node<int>* cursor;

       size_t i;

       assert(0 < position);

       cursor = head_ptr;

       for (i = 1; (i < position) && (cursor != NULL); i++)

           cursor = cursor->link();

       return cursor;

   }

   template<class item>

   void list_head_remove(node<int>* head_ptr)

   {

       node<int>* remove_ptr;

       remove_ptr = head_ptr;

       head_ptr = head_ptr->link();

       delete remove_ptr;

   }

   template<class item>

   void list_remove(node<int>* previous_ptr)

   {

       node<int>* remove_ptr;

       remove_ptr = previous_ptr->link();

       delete remove_ptr;

   }

   template<class item>

   void list_clear(node<int>*& head_ptr)

   {

       while (head_ptr != NULL)

           list_head_remove(head_ptr);

   }

   template<class item>

   void list_copy(const node<int>* source_ptr, node<int>*& head_ptr, node<int>*& tail_ptr) // change the node<int> **tail_ptr to node<int>*& tail_ptr

   {

       head_ptr = NULL;

       tail_ptr = NULL;

       if (source_ptr == NULL)

           return;

       list_head_insert(head_ptr, source_ptr->data());

       tail_ptr = head_ptr;

       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();

// sample.cpp

#include <iostream>
#include <string>
#include "node1.cpp"

using namespace main_savitch_5;

template<class iterator, class T>
iterator find(iterator start, iterator end, const T& target);
template<class iterator, class T>
void traverseList(iterator start, iterator end);
template<class iterator, class T>
T get_data(iterator current_ptr);

// include the declaration of get_next
template<class iterator, class T>
iterator get_next(iterator current_ptr);

int main()

{

   node<int>* head = NULL;

   list_head_insert(head, 5);

   list_head_insert(head, 3);

   list_head_insert(head, 4);

   list_head_insert(head, 12);

   list_head_insert(head, 13);

   list_head_insert(head, 2);

   list_head_insert(head, 45);

   list_head_insert(head, 51);

   cout << "The list is..." << endl;

   traverseList<node<int>*, int >(head, NULL);

   int x;

   cout << "Enter the element to be searched for\n";

   cin >> x;


   node<int>* ptr = find<node<int>*, int>(head, NULL, x); Error on the word find

   if (ptr)

       cout << x << " is present in the list\n";

   else

       cout << x << " is not present in the list\n";

   return 0;
}


template<class iterator, class T>

iterator find(iterator start, iterator end, const T& target) // method name should be find and not f

{

   iterator temp = start;

   while (temp != end)

   {

       if (get_data<iterator, T>(temp) == target)

           return temp;

       temp = get_next<iterator, T>(temp);

   }

   return end;

}

template<class iterator, class T>

void traverseList(iterator start, iterator end)

{

   iterator temp = start;

   while (temp != end)

   {

       cout << get_data<iterator, T>(temp) << " ";

       temp = get_next<iterator, T>(temp);

   }

   cout << endl;

}

template<class iterator, class T>

T get_data(iterator current_ptr)

{

   return current_ptr->data();

}

template<class iterator, class T>

iterator get_next(iterator current_ptr)

{

   return current_ptr->link();

}

//end of sample.cpp

       }

   }

}

//end of node1.cpp

0 0
Add a comment Improve this question Transcribed image text
Answer #1

sample.cpp


// sample.cpp

#include <iostream>

#include <string>

#include "node1.cpp"

using namespace main_savitch_5;

template<class iterator, class T>

iterator find(iterator start, iterator end, const T& target);

template<class iterator, class T>

void traverseList(iterator start, iterator end);

template<class iterator, class T>

T get_data(iterator current_ptr);

// include the declaration of get_next

template<class iterator, class T>

iterator get_next(iterator current_ptr);

int main()

{

node<int>* head = NULL;

list_head_insert(head, 5);

list_head_insert(head, 3);

list_head_insert(head, 4);

list_head_insert(head, 12);

list_head_insert(head, 13);

list_head_insert(head, 2);

list_head_insert(head, 45);

list_head_insert(head, 51);

cout << "The list is..." << endl;

traverseList<node<int>*, int >(head, NULL);

int x;

cout << "Enter the element to be searched for\n";

cin >> x;


node<int>* ptr = find<node<int>*, int>(head, NULL, x);

//Error on the word find

if (ptr)

cout << x << " is present in the list\n";

else

cout << x << " is not present in the list\n";

return 0;

}


template<class iterator, class T>

iterator find(iterator start, iterator end, const T& target) // method name should be find and not f

{

iterator temp = start;

while (temp != end)

{

if (get_data<iterator, T>(temp) == target)

return temp;

temp = get_next<iterator, T>(temp);

}

return end;

}

template<class iterator, class T>

void traverseList(iterator start, iterator end)

{

iterator temp = start;

while (temp != end)

{

cout << get_data<iterator, T>(temp) << " ";

temp = get_next<iterator, T>(temp);

}

cout << endl;

}

template<class iterator, class T>

T get_data(iterator current_ptr)

{

return current_ptr->data();

}

template<class iterator, class T>

iterator get_next(iterator current_ptr)

{

return current_ptr->link();

}

=================================================================

//node1.cpp

#include "node1.h"

#include <cassert> // for assert

using namespace std;

namespace main_savitch_5

{

template<class item>

size_t list_length(const node<item>* head_ptr)

{

const node<item>* cursor;

size_t answer;

answer = 0;

for (cursor = head_ptr; cursor != NULL; cursor = cursor->link())

++answer;

return answer;

}

template<class item>

void list_head_insert(node<item>*& head_ptr, const node<int>::value_type& entry)

{

head_ptr = new node<item>(entry, head_ptr);

}

template<class item>

void list_insert(node<item>* previous_ptr, const node<int>::value_type& entry)

{

node<item>* insert_ptr;

insert_ptr = new node<item>(entry, previous_ptr());

previous_ptr->set_link(insert_ptr);

}

template<class item>

node<item>* list_search(node<item>* head_ptr, const node<int>::value_type& target)

{

node<item>* cursor;

for (cursor = head_ptr; cursor != NULL; cursor = cursor->link())

return cursor;

return NULL;

}

template<class item>

const node<item>* list_search(const node<item>* head_ptr, const node<int>::value_type& target)

{

const node<item>* cursor;

for (cursor = head_ptr; cursor != NULL; cursor = cursor->linl())

if (target == cursor->data())

return cursor;

return NULL;

}

template<class item>

node<int>* list_locate(node<int>* head_ptr, size_t position)

{

size_t i;

node<int>* cursor; (0 < position);

cursor = head_ptr;

for (i = 1; (i < position && cursor != NULL);

i++)

cursor = cursor->link();

return cursor;

}

template<class item>

const node<int>* list_locate(const node<int>* head_ptr, size_t position)

{

const node<int>* cursor;

size_t i;

assert(0 < position);

cursor = head_ptr;

for (i = 1; (i < position) && (cursor != NULL); i++)

cursor = cursor->link();

return cursor;

}

template<class item>

void list_head_remove(node<int>* head_ptr)

{

node<int>* remove_ptr;

remove_ptr = head_ptr;

head_ptr = head_ptr->link();

delete remove_ptr;

}

template<class item>

void list_remove(node<int>* previous_ptr)

{

node<int>* remove_ptr;

remove_ptr = previous_ptr->link();

delete remove_ptr;

}

template<class item>

void list_clear(node<int>*& head_ptr)

{

while (head_ptr != NULL)

list_head_remove(head_ptr);

}

template<class item>

void list_copy(const node<int>* source_ptr, node<int>*& head_ptr, node<int>*& tail_ptr) // change the node<int> **tail_ptr to node<int>*& tail_ptr

{

head_ptr = NULL;

tail_ptr = NULL;

if (source_ptr == NULL)

return;

list_head_insert(head_ptr, source_ptr->data());

tail_ptr = head_ptr;

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();


}

}

}


========================================================================

// node1.h

#ifndef MAIN_SAVITCH_NODE1_H

#define MAIN_SAVITCH_NODE1_H

#include <string>

namespace main_savitch_5

{

template<class item>

class node

{

public:

typedef item value_type;

node(const value_type& init_data = value_type(), node* init_link = NULL)

{

data_field = init_data;

link_field = init_link;

}

void set_data(const value_type& new_data)

{

data_field = new_data;

}

void set_link(node<item>* new_link)

{

link_field = new_link;

}

value_type data()const

{

return data_field;

}

const node<item>* link()const

{

return link_field;

}

node<item>* link()

{

return link_field;

}

private:

value_type data_field;

node<item>* link_field;

};

template<class item>

std::size_t list_length(const node<item>* head_ptr);

template<class item>

void list_head_insert(node<item>*& head_ptr, const node<int>::value_type& entry);

template<class item>

void list_insert(node<item>* previous_ptr, const node<int>::value_type& entry);

template<class item>

node<item>* list_search(node<item>* head_ptr, const node<int>::value_type& target);

template<class item>

const node<item>* list_search(const node<item>* head_ptr, const node<int>::value_type& target);

template<class item>

node<item>* list_locate(node<item>* head_ptr, std::size_t position);

template<class item>

const node<item>* list_locate(const node<item>* head_ptr, std::size_t position);

template<class item>

void list_head_remove(node<item>*& head_ptr);

template<class item>

void list_remove(node<item>* previous_ptr);

template<class item>

void list_copy(const node<item>* source_ptr, node<item>*& tail_ptr);

}

#endif

==========================================================================

SEE OUTPUT
clang version 7.0.0-3-ubuntu0.18.04.1 (tags/ ELEASE_700/final) clang++-7 -pthread -o main main.cpp node1.c saved main.cpp Fil

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
there show an error in sample.cpp file that more than one instance of overloaded function find...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • **HELP** Write a function that takes a linked list of items and deletes all repetitions from the ...

    **HELP** Write a function that takes a linked list of items and deletes all repetitions from the list. In your implementation, assume that items can be compared for equality using ==, that you used in the lab. The prototype may look like: void delete_repetitions(LinkedList& list); ** Node.h ** #ifndef Node_h #define Node_h class Node { public: // TYPEDEF typedef double value_type; // CONSTRUCTOR Node(const value_type& init_data = value_type( ), Node* init_link = NULL) { data_field = init_data; link_field = init_link;...

  • Requirements Print a range Write a bag member function with two parameters. The two parameters are...

    Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...

  • I need help implemeting the remove_repetitions() Here is a brief outline of an algorithm: A node...

    I need help implemeting the remove_repetitions() Here is a brief outline of an algorithm: A node pointer p steps through the bag For each Item, define a new pointer q equal to p While the q is not the last Item in the bag If the next Item has data equal to the data in p, remove the next Item Otherwise move q to the next Item in the bag. I also need help creating a test program _____________________________________________________________________________________________________________________________________________________ #ifndef...

  • The goal of this task is to reinforce the implementation of container class concepts using linked...

    The goal of this task is to reinforce the implementation of container class concepts using linked lists. Specifically, the task is to create an implementation file using a linked list. You need to use the header files, set3.h and node1.h, and the test program, test_set3.cpp. Your documentation must include the efficiency of each function. Please make your program as efficient and reusable as possible. set3.h #ifndef _SET_H #define _SET_H #include <cstdlib> #include <iostream> class set { public: typedef int value_type;...

  • C++ programming language: In this program you will create a simplified bag that acts like a...

    C++ programming language: In this program you will create a simplified bag that acts like a stack meaning that the Last item inserted is the First Item that comes out. Your backend implementation must use a linked list. The code should pass the test (there's only 1) and there should be no memory leaks. Note that passing the test does not ensure full credit! The functions are listed in the suggested order of implementation but you may implement them in...

  • The purpose of this program is to help reinforce container class concepts and linked list concepts...

    The purpose of this program is to help reinforce container class concepts and linked list concepts in C++. Specifically, the task is to implement the sequence class using a linked list. You need to use the author's file sequence3.h to create your implementation file named sequence3.cpp. Please make your code as efficient and reusable as possible. Please make sure code can pass any tests. sequence3.h // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is...

  • The purpose of this lab is to help reinforce container class concepts and linked list concepts...

    The purpose of this lab is to help reinforce container class concepts and linked list concepts in C++. Specifically, the lab to repeat the sequence lab from last week except to use a linked list. You need to use the author's files sequence3.h and sequence_exam3.cpp. Author - Michael Main, Book - Data Structures and other objects using c++, 4th edition // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is the header file for the...

  • I have the following c++ data structures assignment: Copy Constructors, Destructors, and Assignment Operators An understanding...

    I have the following c++ data structures assignment: Copy Constructors, Destructors, and Assignment Operators An understanding of how to implement copy constructors, destructors, and assignment operators is essential when working with data structures using dynamic memory allocation. Failure to implement these methods correctly can and probably will result in memory leaks. In this project, you are provided with a working implementation of a doubly-linked list in which the copy constructor, destructor, and assignment operator methods are not complete. To complete...

  • Im making a generic linked list. I cant figure out how to make an object of...

    Im making a generic linked list. I cant figure out how to make an object of my class from main. My 3 files are main.cpp dan.h dan.cpp The error is: 15 6 [Error] prototype for 'void ll<T>::insert()' does not match any in class 'll<T>' #include <iostream> #include <string> #include "dan.h" using namespace std; int main() { ll<int> work; work.insert(55);//THIS IS THE LINE THATS GIVING ME THE ERROR, Without this line it compiles and //runs. } #ifndef DAN_H #define DAN_H #include...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT