Question: Hey guys, this is the study guide I have for a test but the professor hasn't posted the answers to it yet. I understand most
Hey guys, this is the study guide I have for a test but the professor hasn't posted the answers to it yet. I understand most of it but I'd like another persons input on completing this. Thanks!
17. Consider the following class declaration when answering this question
class DB_Arrays
{
public:
DB_Arrays( ); //default constructor.
DB_Arrays(const DB_Arrays & Org); //copy constructor.
~DB_Arrays( ); //destructor.
void Print_Arrays( ); //prints the contents of both arrays (DB1 followed by DB2)
void Insert(const string &, const int & loc); //adds a string to the back of DB1 if loc =1; otherwise string is added
// to the back of DB2.
void Remove(const string & key, const int & loc); // 1)removes key from DB1 if loc = 1 and it is there;
//AND 2) removes key from DB2 if loc =2 and it is there;
int Find(const string & key, cons tint & loc ); //1)returns location of key in DB1 if loc=1 and if it is there; otherwise -1 is returned
//AND 2) returns location of key in DB2 if loc=2 and if it is there; otherwise -2 is returned
int Total_Keys( ); //returns the total number of cells occupied in both arrays (DB1 and DB2).
void Triple_Size( ); //this function triples the capacities of DB1 and DB2. Note that DB1 and DB2 may have different
//capacities and counts.
private:
int DB1_capacity; //total number of cells allocated for DB1.
int DB2_capacity; //total number of cells allocated for DB2.
int DB1_ count; //total number of strings stored in DB1.
int DB2_count //total number of strings stored in DB2.
string *DB1, *DB2; //arrays DB1 and DB2
};
Figure 1
HINT: I INCLUDED FUNCTION PROTOTYPES AS THE APPEAR IN THE CLASS DECLARATION FOR EACH QUESTION. ALSO REMEMBER TO QUANTIFY ALL MEMBER FUNCTIONS WITH THE CLASS NAME AND ::. FINALLY REMEMBER TO CHECK ALL NECESSARY CASES WHEN IMPLEMENTING THE CLASS FUNCTIONS.
a.Implement the destructor. // ~DB_Arrays( );
b.Implement the function Print_Arrays which prints the contents of both arrays (DB1 followed by DB2).
// void Print_Arrays( );
c.Implement the default constructor. The default constructor will read all the data from a file called my_data1.txt into the arrays, DB1 and DB2(s), respectively; at this point DB1 and DB2 will be identical. The file is composed of strings. Start off with an initial capacity of 5 for each array. You may use any functions declared in the class even if you are not asked to implement them. Keep in mind that WHILE you are reading the arrays may become FULL. Used the class declaration in Figure 1 above.// DB_Arrays( );
d.Implement the copy constructor. Remember, that the copy constructor will perform a deep copy (DB1 and DB2 will have there own memory; keep in mind that DB1 and DB2 may have different capacities, counts and hold different stings.
//DB_Arrays(const DB_Arrays & Org);
e.Implement the function Triple_Size; this function triples the capacities of DB1 and DB2. Note that DB1 and DB2 may have different capacities and counts, and store different strings. // void Triple_Size( );
f.Implement the function Find. Note the following: 1) Find returns the location of key in DB1 if loc = 1 and if it is there; otherwise -1 is returned, and 2) Find returns the location of key in DB2 if loc=2 and if it is there; otherwise -2 is returned.
//int Find(const string & key, cons tint & loc );
g.Implement the function Remove. Note the following: 1)Remove removes key from DB1 if loc = 1 and it is there. if it is not there nothing is done. 2) Remove removes key from DB2 if loc =2 and it is there; if it is not there nothing is done.
//void Remove(const string & key, const int & loc);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
