void StringLinkedList::addBack (const string& e, double &m) {
StringNode* v = new StringNode;
v->elem = e;
v->miles = m;
tail->next = v;
tail = tail->next;
}
//---------------------------------------------------
//function to print contents of list
void StringLinkedList::searchAndPrint(){
//node to traverse the list
//initialized to head
StringNode *currentNode = head;
string val;
cout << "Enter code to search. ";
cin >> val;
while(invalidCode(val)){
cout << "Please enter 3 character code with capital letters. ";
cin >> val;
}
for (int i = 0; i < val.size(); i++)
val.at(i) = toupper(val.at(i));
//print all entries, until
//currentNode points to null
while(currentNode){
//print content of current node
cout << currentNode->elem << " " << currentNode->miles << " ";
//move to next node
currentNode = currentNode->next;
}
}
bool StringLinkedList::invalidCode(string& c)
{
if(c.size()!=3)
return true;
for (int i = 0; i < c.size(); i++) {
if(!isalpha(c.at(i)))
return true;
}
return false;
}
//return 0 to mark successful termination
system("pause");
return 0;
}
void showMenu(){
cout << "\n1. Insert new entry";
cout << "\n2. Search code and print";
cout << "\n3. Quit\n";
}
void readStr(string& c, double &m){
cout << "Enter 3 character airport code with capital letters: ";
cin >> c;
while(invalidCode(c)){
cout << "Please enter 3 character code with capital letters. ";
cin >> c;
}
for (int i = 0; i < c.size(); i++)
c.at(i) = toupper(c.at(i));
cout << "Enter miles from the last airport: ";
cin >> m;
//validate input
while(m < 0){
cout << "Please enter nonnegative value: ";
cin >> m;
}
}
bool invalidCode(string& c)
{
if(c.size()!=3)
return true;
for (int i = 0; i < c.size(); i++) {
if(!isalpha(c.at(i)))
return true;
}
return false;
}