Question
this is C++ The Phone Directory Write a program for a phone directory by reusing the cStrTools module of part one and adding a Phone
this is C++
The Phone Directory
Write a program for a phone directory by reusing the cStrTools module of part one and adding a Phone module and a directory main module.
This program should be set up using a title for the phone directory and a file name for a data file. (see the directory module)
the data file
The data file holds records of a phone number in a tab separated format as follows:
[Name]\t[areaCode]\t[prefix]\t[number]
For example the following information:
Fred Soley (416)555-0123
is kept in the file as follows:
Fred Soley\t416\t491\t0123
Hint: to read the above record use the follwing fscanf format fscanf(fptr, "%[^\t]\t%s\t%s\t%s ",name,area,prefix,number)
view The data file
the maximum length for a name is 50 characters.
Execution
- When running, after showing the title, the program should prompt for a partial name entry.
- After receiving the partial name the program should search through the names in the file and if a name is found containing the partial entry, the matching phone recored is displayed.
- Nothing is displayed if no match is found.
- If the user enters '!' the program exits.
- If the data file could not be opened the program exits displaying an error message
- A thank you message is displayed at the end of the program.
For output formatting and messages, see the execution samples
Phone module
Only one mandatory function is required for the Phone module:
// runs the phone directory appication void phoneDir(const char* programTitle, const char* fileName);
You are free to create any function you find necessary to accomplish this task.
Tester Program
/* ------------------------------------------------------ Workshop 1 part 2 Module: directory Filename: directory.cpp Version 1 Author Fardad Soleimanloo Revision History ----------------------------------------------------------- Date Reason -----------------------------------------------------------*/ #include "Phone.h" using namespace sdds; int main() { phoneDir("Star Wars", "phones.txt"); return 0; }
DIY Execution example (existing data file)
Star Wars phone direcotry search ------------------------------------------------------- Enter a partial name to search (no spaces) or enter '!' to exit > lukE Luke Skywalker: (301) 555-0630 Enter a partial name to search (no spaces) or enter '!' to exit > sky Luke Skywalker: (301) 555-0630 Enter a partial name to search (no spaces) or enter '!' to exit > fett Jango Fett: (905) 555-6016 Boba Fett: (905) 555-9382 Enter a partial name to search (no spaces) or enter '!' to exit > feT Jango Fett: (905) 555-6016 Boba Fett: (905) 555-9382 Enter a partial name to search (no spaces) or enter '!' to exit > Jack Enter a partial name to search (no spaces) or enter '!' to exit > ! Thank you for using Star Wars directory.
DIY unsuccessful execution
#include "Phone.h" using namespace sdds; int main() { phoneDir("Star Wars", "badfile.txt"); return 0; }
DIY unsuccessful Execution example (data file not found)
Star Wars phone direcotry search ------------------------------------------------------- badfile.txt file not found! Thank you for using Star Wars directory. D:\Users\phard\Documents\Seneca\oop244\DEV\Workshops\WS01\DIY\Debug\DIY.exe (process 8424) exited with code 0. Press any key to close this window . . .
Files to submit:
cStrTools.h cStrTools.cpp Phone.h Phone.cpp direcotry.cpp
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