Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ i have only one houre Question 1: Implement the following two classes: Entry and Directory as described below: Entry Class class Entry (5 points)

C++ i have only one houre

Question 1: Implement the following two classes: Entry and Directory as described below:

Entry Class

class Entry (5 points)

{

public:

Entry();

Entry(sring, int, string);

// create all setters and dont forget to validate the input

int getSSN()

string getLname();

int getNum();

string getAddress()

void print();

private:

int SSN;

string Lname;

int phoneNumber;

string address;

};

Directory Class

Each directory contains unknown number of entries; thus you need to implement class Directory with the following members:

  • Three private data member: (3 points)
    • int maxSize
    • int current to track the current number of entries in the directory.
    • Entry *list a pointer a dynamic array of entries.

  • Two private member functions: (10 points)
    1. void Grow() to expand the dynamic array. The dynamic array size grows by the following (10 points):
      1. Increase the maxSize to maxSize+5.
      2. Create a new array with the size of maxSize+5
      3. Copy the contents of the old dynamic array to the new one
      4. delete the old array

  1. int find(int i) search for SSN=i in the list and returns the index of an entry if found otherwise returns -1.

  • The following public member functions (43 points):
    • Directory(int mx): creates an empty directory of entries and sets maxsize to mx. (2 points)
    • ~Directory(): Deallocate the entry list. (2 points)
    • isFull(), a boolean function that returns true if current == maxSize, and false otherwise.(2 points)

  • void Insert(Entry e): this function needs to do the following (10 points): /*hint for insert function: make use of the grow and find functions*/
    • Insert an entry into the entries list of the directory (only if the entry does not exist). If the entry to be added exists, then, the entry must be modified instead of adding a new entry.
    • If the directory is full, then grow the list, and then add the entry to the list.
  • void Remove(int k): Removes the first k items from list and shifts remaining items, only if list is not empty (k must be either 1 or 2 or 3 i.e. max to be removed is 3). (6 points)
  • void Update(int phone, int x): update the phoneNumber in the list at loc x with the value of phone (only if list is not empty, and if loc is in the rang 0 to current-1). (5 points)
  • void DisplayDirectory(): Display the current directory and prints the details of every entry. (3 points)
  • void setEntry(Entry e, int p) which changes the entries array at position p to e (5 points).
  • Setters and getters for maxSize and current variables. (5 points)
  • Friend function called percentage(Directory d) that calculates and returns the percentage of used entries in a directory. (3points)

  • Make all the functions that do not change the values of the attributes constant. (4 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago