Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment you will extend your phonebook program from A 5 . If you are not confident in your solution from A 5 you
In this assignment you will extend your phonebook program from A If you are not confident
in your solution from A you may reference and use parts of the example solution provided.
However, attribution of use of the example solution must be provided, you should
document what you have used, and indicate changes you have made
You may either copy your A phonebook.c and Makefile, or branch from A in your git
repo. git rebase may be helpful here
Question points
Write a Makefile that builds a C program phonebook.c and produces the executable object
file phonebook. Your Makefile should use the compiler flags discussed in class, and have the
all and clean targets as shown previously. You should also include the flag Wextra as
discussed in the lab.
Question points
In this question, you are going to extend the functionality of phonebook.c
a points It is often useful for a phonebook to be kept in alphabetical order for easy
look up We want to modify our phonebook add such that the new entry is inserted
at the correct position The API remains otherwise the same.
b points Sometimes mistakes happen in entry, like the same name getting misspelled
repeatedly, or the phone numbers all missing area codes. We want create a method
called phonebook map. It should take arguments:
a pointer to struct phonebook list
a function pointer of type void func ptrstruct phonebook entry item
This function should iterate the entire list and apply the passed function to each item.
This applies an in place change to each item. The function has no return value. Define
the following functions that could be passed to phonebook map:
a void respellstruct phonebook entry item Which changes the spelling
of John to Jon
b void addAreaCodestruct phonebook entry item Which adds to
the front of all phone numbers remember these are unsigned long ints, you
can assume they are only digit numbers though.
strncmp doenst actually return alphabetical in terms we would normally think, but well use its
sorting
c points Sometimes we need to select all the entries from list which match a criteria.
Create a method called phonebook filter. It should take arguments:
a pointer to a source struct phonebook list
a pointer to a destination struct phonebook list
a function pointer of type struct phonebook entry func ptrstruct phonebook entry
item
This function should iterate the entire source list, apply the passed function, and then
if a nonNULL value is returned it should add that value to the destination list. The
function has no return value. Define the following functions that could be passed to
phonebook filter:
astruct phonebook entry noHomersstruct phonebook entry item Which
removes returns NULL any name containing Homeryou can expect case to
match, but should search the entire string that is MrHomer would still match
bstruct phonebook entry torontoOnlystruct phonebook entry item
Which only keeps numbers starting with
d points Add Map and Filter call to your command line. These will take a number:
or which corresponds to the functions above. ie for map, is addAreaCode.
a for add; eg
a
Jon
This should add a phonebook entry with the given name and phone number.
f for find; eg
f
Jon
In this example, the output should be the value corresponding to Jon if the key
exists in the phonebook, or Key not found if the key is not in the phonebook.
r for remove; eg
r
Jon
The output should be success or fail depending on whether the key was found
and removed.
m for map; eg
m
No output expected.
l for filter; eg
l
Should output the filtered list note this function should work more than once
p for print all; eg
p
The output should be all phonebook entries.
q to quit the program.
Question points
In this part, you will test your phonebook program. But we will use a unittest approach.
Recall from the labs that unittests evaluate individual functions programmatically. For this
section you will create multiple unittest functions of the following functions:
phonebook init test
phonebook add tests
phonebook find test
phonebook remove test
phonebook map tests
phonebook filter tests
Each of these functions total should initialize data it needs and preform a single test
action. ie inserting to an empty list, as well as programmatically validate the result,
returning on success, and on failure. Your unittests should not require outside verification
of your code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started