struct PhoneNumber
{
std::string number;
std::string name;
};
class PhoneBook
{
Phonenumber listing[MAX_PN];
unsignedint count;
public:
void add(PhoneNumber pn);
voiddelete(int index);
void edit(int index);
void search(std::string search_string);
};
int PhoneBook::search(std::string search_string)
{
for (int i = 0 ; i< MAX_PN; i++)
{
//pseudocode
if search_string is find in either number or name then return the index number
}
//pseudocode
if nothing found return negative number
}
int main ()
{
PhoneNumber p1 = { "123456", "some name"};
PhoneNumber p2 = { "123789", "some other name"};
PhoneBook book;
book.add(p1);
book.add(p2);
int s;
s = book.search("123456");
//pseudocode
if s >= 0, print out data, otherwise print "nothing found"return 0;
}
To be safe there should go some array boundary checking in there.