Total Points : 100

advertisement
COSC 237
Assignment 3
Due : in class on March 29 (Wednesday)
Total Points : 100
Problem
Design and implement a C++ class to generate new telephone directory for two merged
companies using Sorted list in terms of last name. Each directory should contain apace
for up to 100 names, phone numbers, birthday, and room numbers. You should have
functions (public member functions or client functions) to do the following features.
 Create an empty directory (all names blank)
 Read in the telephone directory information from one file (Dir1.txt) and put them
in one sorted list. – use InsertItem public function.
 Read in the telephone directory information from the other file (Dir2.txt) and put
them in the other sorted list. – Use MergeDir client function.
 Merge two directories into one new directory.
 Retrieve the entry corresponding to a given last name.
 Display the new telephone directory – use Print function and GetNexttItem public
function.
 Add a new entry to the new directory. - RetrieveItem and InsertItem functions
 Delete an entry from the directory corresponding to a given last name. – use
RetrieveItem and DeleteItem functions.
Input
Each record in Dir1.txt and Dir2.txt consists of last name (string), first name (string),
middle initial (character), phone number (string), room number(integer), and date of birth
(3 integers).
There are six different interactive options which will be chosen from the menu as
follows:
Selection menu for outputs:
1.
2.
3.
4.
5.
Find the entry corresponding to a given last name.
Display all the telephone directory information
Add a new entry to the directory
Delete an entry from the directory
Quit
Your selection is ---> (1/2/3/4/5)
NOTE:
1. Use a class of sorted list data type.
2. Hand in the hard copy of your source program and your output. (To print out your
screen for each selection.)
3. Use a folder to hand in your assignment including hard copies of your program and a
diskette with the appropriate files (a source file).
4. The source files should be called teldir.cpp
5. All assignments are expected to be INDIVIDUAL work. All work handed in must be
original. Duplicate or very similar programs receive zero points.
Actual data file (Dir1.txt)
JOHNSON JAMES L 4103332222 316 1 31 1975
ANDREWS PETER J 3018884444 217 2 21 1980
LUCKY LUCY L 4107777777 112 5 15 1970
NAKAMURA TOKY O 3018111112 345 4 5 1982
MEDES GLORIA A 2014545454 310 4 21 1973
MARX KARL Z 4104333333 318 8 16 1939
NEWMANN ALFRED X 3014657688 323 9 30 1945
KRONECKER LEO C 2122992828 456 10 31 1966
VIRUS VERA T 9122229292 311 4 17 1980
CUSTER FELICIA C 3019878765 111 7 14 1974
REMBRANDT ANTHONY F 4102222222 222 11 2 1965
PORGY BESS M 4105435667 226 12 1 1962
AUGUSTA ADA T 7048381234 674 6 14 1977
CAESAR JULIE S 4537773635 567 3 8 1980
MACDONALD RONALD B 3018555555 313 2 11 1972
WEERD DEWEY L 2137653927 314 5 1 1963
KIM YANNGON X 9838373635 347 2 21 1977
ROOSEVELT ROSE Y 4102222222 717 3 4 1981
PASCAL BLAZE R 4437635243 387 12 21 1958
Actual data file(Dir2.txt)
BOSTON AMANDA L 4103428273 318 3 31 1974
ANDERSON ROBERT J 3013288322 217 4 21 1978
PHILIP CRAIG L 4107777777 112 6 15 1972
NAKAMURA TOKY O 3018111112 345 4 5 1982
YI JHON A 6487363636 310 4 28 1985
MARX KARL Z 4104333333 318 8 16 1939
TWAROWSKI CHRIS X 4107048888 323 9 4 1958
KRONECKER LEO C 2122992828 456 10 31 1966
PURKEY RACHAEL T 4435673452 233 4 10 1982
ZHOU FENG C 4322736484 114 8 14 1979
PORGY BESS M 4105435667 226 12 1 1962
HULL MATTHEW T 8574747477 574 2 29 1979
CAESAR JULIE S 4537773635 567 3 8 1980
MACDONALD RONALD B 3018555555 313 2 11 1972
BURLIN ERIK L 4436543452 306 5 11 1983
KIM YANNGON X 9838373635 347 2 21 1977
AAMAX JOHN Y 4104325468 717 3 14 1985
1. A sorted list ADT is to be extended by adding one more function named MergeLists
that merges 2 sorted lists into a third sorted list. The resulting list list3 should be a sorted
list that contains all of the items from list1 and list2.
First, add these functions to the specification file, and write the function definitions in the
implementation file.
Modify the existing implementation for a class SortedList (discussed in textbook):
const int MAX_LENGTH = 50;// Maximum possible number of components
#include <string>
using namespace std;
struct rectype
{
// you have to define your rec type.
}
typedef rectype ItemType; // Type of each component
class SortedList {
public:
SortedList();
bool IsEmpty() const;
bool IsFull() const;
void ResetList();
int LengthIs() const;
void InsertItem(ItemType item);
void DeleteItem(ItemType item);
void RetrieveItem(ItemType& item, bool& found);
void GetNextItem(ItemType& item);
bool IsPresent(ItemType item) const;
void Print() const;
private:
int
length;
int
cuurentPos;
ItemType data[MAX_LENGTH];
};
SortedList::SortedList() {
length = 0;
currentPos = -1;
}
bool SortedList::IsEmpty() const {
return (length == 0);
}
bool SortedList::IsFull() const {
return (length == MAX_LENGTH);
}
int SortedList::Length() const {
return length;
}
void SortedList::InsertItem(ItemType item) {
//Implement
}
void SortedList::DeleteItem(ItemType item ) {
//Implement
}
bool SortedList::IsPresent(ItemType item ) const {
}



2. Create a client to test your program. The client should work with 3 sorted lists named
dir1, ldir2 and newdir. Read the data for list1 and list2 from the files Dir1.txt and
Dir2.txt. Merge dir1 and dir2 into newdir and show the menu. After that your program
will be executed interactively based on the new directory.
Download