Reputation: 331
I'm still trying to get a handle on C++ programming, and I'm trying to compile a code that is meant to create different personnel objects and save book titles to those personnels using trees. I keep getting an:
unidentified reference to 'insert_Book()'
unidentified reference to 'search_Book()'
in my insert()
function. Why is this? Thank you!
//insert function
void insert(){
char ch;
cout << endl << "@Insertion module...............";
do {
sub_menu();
cin >> ch;
ch = tolower(ch);
switch(ch) {
case 'p': if(insert_personnel() != 0)
cout << "@INSERTION OPERATION FAILED." << endl;
else
cout << "@INSERTED SUCCESSFULLY." << endl;
break;
case 'e': if(insert_employee() != 0)
cout << "@INSERTION OPERATION FAILED." << endl;
else
cout << "@INSERTED SUCCESSFULLY." << endl;
break;
case 'f': if(insert_faculty() != 0)
cout << "@INSERTION OPERATION FAILED." << endl;
else
cout << "@INSERTED SUCCESSFULLY." << endl;
break;
case 's': if(insert_student() !=0)
cout << "@INSERTION OPERATION FAILED." << endl;
else
cout <<"@INSERTED SUCCESSFULLY." << endl;
break;
case 'b': if(insert_Book() !=0)
cout << "@INSERTION OPERATION FAILED." << endl;
else
cout <<"@INSERTED SUCCESSFULLY." << endl;
break;
case 'g': if (search_Book() !=0)
cout << "@INSERTION OPERATION FAILED." << endl;
else
cout <<"@INSERTED SUCCESSFULLY." << endl;
break;
case 'q': cout << endl << "@Exiting the insertion..." << endl;
cin.get();
break;
default: cout << endl << "@ERROR - Invalid input." << endl;
cout << "@Try again....." << endl;
}
}
while (ch != 'q');
}
int search_Book(Book *root,char *ntitle){
if (root == NULL){
cout<<"No Books found";
return -1;
}
else if(ntitle == root->title){
cout<<"Title:\t"<<root->title<<endl<<"URL:\t"<<root->url<<endl;
return 0;
}
else if(ntitle[0] < root->title[0]){
return search_Book(root->left,ntitle);
}
else {
return search_Book(root->right,ntitle);
}
}
int insert_Book(){
char name[50];
char title[100];
char url[100];
Student* node;
cout<<"Enter the name of the student you want the book to be added to: ";
cin>>name;
node = searchstudent(name);
if(node == NULL){
return 1;
}
else{
cout<<"Enter the Title: ";
cin>>title;
cout<<"Enter the url: ";
cin>>url;
add_Book(node->bookTree,title,url);
return 0;
}
}
Upvotes: 0
Views: 192
Reputation: 21514
insert()
uses insert_Book()
and search_Book()
before they are defined (as you define them after insert()
).
Two solutions:
1- Move insert_Book()
and search_Book()
code before insert()
2- Or declare them before insert()
: just write
int insert_Book();
int search_Book(Book *root,char *ntitle);
This tells the compiler not to worry, those will be implemented soon...you can implement them later, after insert()
.
Upvotes: 3