- Write a function bool DeleteRecord(List *list, T record) that can be used to delete record from a linked list. You can use it to delete record in Student list or Book list. If delete from Student list, use id to find student and if delete from Book list, use call number to find book. The record variable will store id or call number of the object to be deleted. The function will return true if successfully delete and false if student cannot be found in the list.
this is the function:
template <class T>
bool DeleteRecord(List<T> *list, T record)
{
T temp, check_ls;
bool del = false;
cout << "\nDeleting record......";
strcpy(temp, record);
for (int i = 1; i <= (*list).size(); i++)
{
(*list).get(i, check_ls);
if (check_ls == temp){
(*list).remove(i);
del = true;
break;
}
}
if (del){ return true; }
else { return false; }
}
this if findID:
string findID(){
string id;
bool valid = false;
while (!valid){
cout << "\nEnter ID of Student: ";
cin >> id;
valid = true;
if (id.length() != 7)
{
cout << "\nError! Enter 7 digits";
id = "";
valid = false;
}
else
{
if (!alldigit(id))
{
valid = false;
cout << "\nError! Enter digit only.";
}
}
}
return id;
}
this is my code so far (main.cpp)
int main(){
system("cls");
cout << "Delete Record\n";
//cout << findID().c_str();
id=findID();
cout << id;
if (DeleteRecord(stulist, id)){ cout << "Success! Record deleted.\n"; }
else { cout << "\n\nError! No such record.\n"; }
cout << "\nInfo: " << (*stulist).size() << " record(s) remaining.\n\n";
system("pause");
return 0;
}
there is a problem when i call the DeleteRecord function. it say no instance of function template matches the argument list. Anyone can help me to solve this problem?