I know im not doing something right but i cant figure out atm. Ive tried looking up the error at microsofts page and i cant really make much sense of it. I have a client program that has:
Code:
#include "bintree.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
struct datanode
{
int key;
float gpa;
};
int menu();
void holdscreen();
int main()
{
Binary_tree<datanode> tree;
datanode data;
Binary_node<datanode> * pointer;
int choice, key;
float gpa;
do
{
system("cls");
choice = menu();
switch(choice)
{
case 1: tree.fill_tree(); break;
case 2: {
cout << "Enter key and gpa:";
cin >> key >> gpa;
data.key = key;
data.gpa = gpa;
tree.insert(data);
} break;
case 3: tree.inorder(); holdscreen(); break;
case 4: tree.preorder(); holdscreen(); break;
case 5: tree.postorder(); holdscreen(); break;
case 6: tree.descending(); holdscreen(); break;
case 7: { cout << "Size = " << tree.size() << endl; holdscreen(); } break;
case 8: { cout << "Average = " << tree.average() << endl; holdscreen(); } break;
case 9: { cout << "Enter key to search for:";
cin >> key;
tree.search(key, pointer);
if (pointer == NULL) cout<<"NOT FOUND\n";
else
cout << "key = " << pointer->data.key << " gpa = " << pointer->data.gpa << endl;
holdscreen();
} break;
case 10: {cout << "Enter key of node to delete:";
cin >> key;
if (!tree.remove(key)) cout << "NOT FOUND\n"; holdscreen();
}break;
case 11: break;
default: {cout << "Invalid choice\n"; holdscreen();}
}
}while (choice != 11);
return 0;
}
int menu()
{
int choice = 0;
cout << "1. Fill tree from file LAB5.in" << endl;
cout << "2. Insert a node into the tree" << endl;
cout << "3. Print Keys only in ascending order" << endl;
cout << "4. Print Keys with GPSs in preorder" << endl;
cout << "5. Print Keys with GPSs in postorder" << endl;
cout << "6. Print Keys with GPSs in descending order" << endl;
cout << "7. Count nodes in tree" << endl;
cout << "8. Calculate average of GPAs in tree" << endl;
cout << "9. Search for a Key in the tree" << endl;
cout << "10. Delete a node from the tree" << endl;
cout << "11. Quit" << endl;
cin >> choice;
return choice;
}
void holdscreen()
{
cin.ignore();
cin.ignore();
}
and when i try to compile it all i get is this:
Code:
Linking...
: error LNK2001: unresolved external symbol "public: bool __thiscall Binary_tree<struct datanode>::remove(int)" (?remove@?$Binary_tree@Udatanode@@@@QAE_NH@Z)
: error LNK2001: unresolved external symbol "public: void __thiscall Binary_tree<struct datanode>::search(int,struct Binary_node<struct datanode> * &)" (?search@?$Binary_tree@Udatanode@@@@QAEXHAAPAU?$Binary_node@Udatanode@@@@@Z)
: error LNK2001: unresolved external symbol "public: float __thiscall Binary_tree<struct datanode>::average(void)const " (?average@?$Binary_tree@Udatanode@@@@QBEMXZ)
: error LNK2001: unresolved external symbol "public: int __thiscall Binary_tree<struct datanode>::size(void)const " (?size@?$Binary_tree@Udatanode@@@@QBEHXZ)
: error LNK2001: unresolved external symbol "public: void __thiscall Binary_tree<struct datanode>::descending(void)const " (?descending@?$Binary_tree@Udatanode@@@@QBEXXZ)
: error LNK2001: unresolved external symbol "public: void __thiscall Binary_tree<struct datanode>::postorder(void)const " (?postorder@?$Binary_tree@Udatanode@@@@QBEXXZ)
: error LNK2001: unresolved external symbol "public: void __thiscall Binary_tree<struct datanode>::preorder(void)const " (?preorder@?$Binary_tree@Udatanode@@@@QBEXXZ)
: error LNK2001: unresolved external symbol "public: void __thiscall Binary_tree<struct datanode>::inorder(void)const " (?inorder@?$Binary_tree@Udatanode@@@@QBEXXZ)
: error LNK2001: unresolved external symbol "public: void __thiscall Binary_tree<struct datanode>::insert(struct datanode const &)" (?insert@?$Binary_tree@Udatanode@@@@QAEXABUdatanode@@@Z)
lab5.obj : error LNK2001: unresolved external symbol "public: void __thiscall Binary_tree<struct datanode>::fill_tree(void)" (?fill_tree@?$Binary_tree@Udatanode@@@@QAEXXZ)
: error LNK2001: unresolved external symbol "public: __thiscall Binary_tree<struct datanode>::Binary_tree<struct datanode>(void)" (??0?$Binary_tree@Udatanode@@@@QAE@XZ)
Debug/btree.exe : fatal error LNK1120: 11 unresolved externals
Error executing link.exe.
lab5.exe - 12 error(s), 0 warning(s)
bintree.h
Code:
#ifndef BINARY_TREE_H
#define BINARY_TREE_H
template <class Entry>
struct Binary_node
{
Entry data;
Binary_node<Entry> *left;
Binary_node<Entry> *right;
Binary_node();
Binary_node(const Entry &x);
};
template <class Entry>
class Binary_tree
{
public:
Binary_tree();
void insert(const Entry &);
void fill_tree();
void inorder() const;
void preorder() const;
void descending() const;
void postorder() const;
int size() const;
float average() const;
void search (int target_key, Binary_node<Entry> * & target_pointer);
bool remove(int target);
private:
Binary_node<Entry> * root;
recursive_insert(Binary_node<Entry>* &, const Entry &);
//more to come
};
#endif
bintree.cpp
Code:
#include "bintree.h"
#include <fstream>
#include <assert.h>
#include <iostream>
using namespace std;
template <class Entry>
Binary_node<Entry>::Binary_node()
{
left = right = NULL;
}
template <class Entry>
void Binary_tree<Entry>::insert(const Entry & data)
{
recursive_insert(root, data);
}
template <class Entry>
void Binary_node<Entry>::recursive_insert(Binary_node<Entry>* & sub_root, const Entry & data)
{
if(sub_root == NULL) sub_root = new Binary_node<Entry> (data);
else if (data.key < sub_root->data.key)recursive_insert(sub_root->left, data);
else recursive_insert(sub_root->right, data);
}
template <class Entry>
void Binary_tree<Entry>::fill_tree()
{
datanode data;
ifstream infile("C:LAB5.in");
assert( !infile.fail() );
while( !infile.eof() )
{
infile >> data.key >> data.gpa;
insert(data);
}
}
template <class Entry>
void Binary_tree<Entry>::descending() const
{cout<<"in descending";}
template <class Entry>
int Binary_tree<Entry>::size() const
{cout<<"in size";}
template <class Entry>
float Binary_tree<Entry>::average() const
{cout<<"in avg";}
template <class Entry>
void Binary_tree<Entry>::search (int target_key, Binary_node<Entry> * & target_pointer)
{
/*
in progress
*/
}
template <class Entry>
bool Binary_tree<Entry>::remove(int target)
{cout<<"in remove";}
template <class Entry>
void Binary_tree<Entry>::inorder(Binary_node<Entry> *root) const
{
if( root == NULL ) return;
inorder(root->left);
cout << root->key << endl;
inorder(root->right);
}
template <class Entry>
void Binary_tree<Entry>::preorder(Binary_node<Entry> *root) const
{
if( root == NULL ) return;
cout << root->key << " " << root->gpa << endl;
preorder(root->left);
preorder(root->right);
}
template <class Entry>
void Binary_tree<Entry>::postorder(Binary_node<Entry> *root) const
{
if( root == NULL ) return;
postorder(root->left);
postorder(root->right);
cout << root->key << " " << root->gpa << endl;
}
thnxs in advance