What's new

C & C++ Patulong po sa codes ko about Tellist c++

Soobin_ms

Eternal Poster
Established
Joined
Oct 24, 2020
Posts
802
Solutions
3
Reaction
298
Points
380
eto po codes ko

// telList_t.cpp

#include "telList.h"
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
inline void cls()
{ cout << "\033[2J\n";
}
inline void go_on()
{
cout << "\n\nGo on with return! ";
cin.sync(); cin.clear();
while( cin.get() != '\n')
;
}
int menu();
char header[] =
"\n\n ***** Telephone List *****\n\n";
TelList myFriends;
int main()
{
int action = 0;
string name;
myFriends.append("Lucky, Peter", "0203-1234567");
while( action != 'B')
{
action = menu();
cls();
cout << header << endl;
switch( action)
{
case 'D':
myFriends.print();
go_on();
break;
case 'F':
cout <<
"\n--- To search for a phone number ---\n"
"\nEnter the beginning of a name: ";
getline( cin, name);
if( !name.empty())
{
myFriends.print( name);
go_on();
}
break;
case 'A':
myFriends.getNewEntries();
break;
case 'E':
cout <<
"\n--- To delete a telephone entry. ---\n "
"\nEnter the complete name: ";
getline( cin, name);
if( !name.empty())
{
if( !myFriends.erase( name))
cout << name << " not found!"
<< endl;
else
cout << "Entry for " << name
<< " deleted!" << endl;
go_on();
}
break;
case 'T': cls();
break;
}
}
return 0;
}
int menu()
{
static char menuStr[] =
"\n\n D = Display all entries"
"\n\n F = Find a telephone number"
"\n\n A = Append a new entry "
"\n\n E = Erase an entry "
"\n\n Q = Quit the program"
"\n\n Your choice: ";
cls();
cout << header << menuStr;
char choice;
cin.sync(); cin.clear();
if( !cin.get(choice))
choice = 'B';
else
choice = toupper(choice);
cin.sync();
return choice;
}


// telList.h

#include "telList.h"
#include <iostream>
#include <iomanip>
using namespace std;
bool TelList::append( const string& name,
const string& telNr)
{
if( count < MAX
&& name.length() > 1
&& search(name) == PSEUDO)
{
v[count].name = name;
v[count].telNr = telNr;
++count;
return true;
}
return false;
}
bool TelList::erase( const string& key )
{
int i = search(key);
if( i != PSEUDO )
{
v = v[count-1]; --count;
return true;
}
return false;
}
int TelList::search(const string& key )
{
for( int i = 0; i < count; i++ )
if( v.name == key )
return i;
return PSEUDO;
}

inline void tabHeader()
{
cout << "\n Name Telephone #\n"
"----------------------------------------------"
<< endl;
}
inline void printline( const Element& el)
{
cout << left << setw(30) << el.name.c_str()
<< left << setw(20) << el.telNr.c_str()
<< endl;
}
void TelList::print()
{
if( count == 0)
cout << "\nThe telephone list is empty!" << endl;
else
{
tabHeader();
for( int i = 0; i < count; ++i)
printline( v);
}
}
int TelList::print( const string& name) const
{
int matches = 0, len = name.length();
for( int i = 0; i < count; ++i)
{
if( v.name.compare(0, len, name) == 0)
{
if( matches == 0) tabHeader();
++matches;
printline( v);
}
}
if( matches == 0)
cout << "No corresponding entry found!" << endl;
return matches;
}
int TelList::getNewEntries()
{
int inputCount = 0;
cout << "\nEnter new names and telephone numbers:"
"\n(Terminate by empty input) "
<< endl;
Element el;
while( true)
{
cout << "\nNew last name, first name: ";
cin.sync(); getline( cin, el.name);
if( el.name.empty())
break;
cout << "\nTelephone number: ";
cin.sync(); getline( cin, el.telNr);
if( !append( el))
{
cout << "Name has not been found!" << endl;
if( count == MAX)
{
cout << "The Table is full!" << endl;
break;
}
if( search( el.name) != PSEUDO)
cout << "Name already exists!" << endl;
}
else
{
++inputCount;
cout << "A new element has been inserted!"
<< endl;
}
}
return inputCount;
}


// telList.h

#ifndef TelList
#define TelList
#include <string>
using namespace std;
#define PSEUDO -1
#define MAX 100
struct Element { string name, telNr; };
class TelList
{
private:
Element v[MAX];
int count;
public:
TelList(){ count = 0;}
int getCount() const { return count; }
Element *retrieve( int i )
{
return (i >= 0 && i < count)? &v : NULL;
}
bool append( const Element& el )
{
return append( el.name, el.telNr);
}
bool append( const string& name,
const string& telNr);
bool erase( const string& name);
int search( const string& name);
void print();
int print( const string& name);
int getNewEntries();
};
#endif

eto po errors niya

telList_t.cpp:(.text+0x88): undefined reference to `TelList::append(std::string const&, std::string const&)'
telList_t.cpp:(.text+0x12a): undefined reference to `TelList::print()'
telList_t.cpp:(.text+0x180): undefined reference to `TelList::print(std::string const&)'
telList_t.cpp:(.text+0x196): undefined reference to `TelList::getNewEntries()'
telList_t.cpp:(.text+0x1eb): undefined reference to `TelList::erase(std::string const&)'
D:\Dev\collect2.exe [Error] ld returned 1 exit status
 

Similar threads

Back
Top