Write a program that implements an address book for your friends using linked lists. Each person has name, last name, and phone number. Data should be stored in ordered based on last name. The program should include the following menu:
1.Add a friend
2.Delete a friend
3.List all friends with their phone numbers in the address book
4.Find the phone number of a friend given his/her last name.
5.Find the phone number of a friend given his/her first name. You may not remember his/her last name. (linked list is ordered based on last name not first name)

6.Find the names and phone number of the person whose name is closest to the given name. (For example you enter BRWN for the last name and program finds a person with last name BROWN)

Dani AI

Generated

For : several replies here asked for effort first (, , ); the short, practical scaffold below gives a minimal, working basis to finish the assignment without handing in a full solution. It expands on ’s direction but adds safe handling, case-insensitive comparisons and a simple fuzzy match for "closest" last name.

Design notes: keep a singly linked list sorted by last name (use first name as tie-breaker). Operations are linear time: insert/delete/find/list are O(n). For the "closest" match use Levenshtein distance to pick the smallest edit distance (example: BRWN -> BROWN). Normalize names to lowercase for comparisons and trim whitespace on input.

A compact C++14+ skeleton (safely manages memory with std::unique_ptr):

#include <string>
#include <memory>
#include <algorithm>
#include <vector>
#include <numeric>

struct Node {
    std::string first, last, phone;
    std::unique_ptr<Node> next;
    Node(std::string f, std::string l, std::string p)
      : first(std::move(f)), last(std::move(l)), phone(std::move(p)), next(nullptr) {}
};

static std::string lower(std::string s){
    std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c){ return std::tolower(c); });
    return s;
}

static bool lessName(const std::string &aL, const std::string &aF,
                     const std::string &bL, const std::string &bF){
    auto A = lower(aL), B = lower(bL);
    if(A != B) return A < B;
    return lower(aF) < lower(bF);
}

/* insertSorted, removeByFullName, findByFirst/Last, listAll...
   implement using the unique_ptr traversal pattern shown above. */

For fuzzy matching implement Levenshtein distance (DP) and scan the list to find the node with minimal distance to the given last name. Common pitfalls: forget case-folding, mishandle head insertion/deletion, or not handling duplicate last names (return all matches or confirm which to delete). For a concise Levenshtein reference, see Levenshtein distance.

Recommended Answers

All 6 Replies

No code = no effort shown = no help.

No code = no effort shown = no help.

Why ?? please help me!! this is my homework !!

You should make a structure containing the variables for holding one persons data, then use it just like any other "Node" in linked list. But you should first try urself.

Why ?? please help me!! this is my homework !!

Thats why you have to do it. Its YOUR homework.

you're hopeless...show some effort before posting threads here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.