Question: Question #1: Consider the following class declaration when answering the parts of this question: class List { public: List(); //Default constructor; The list will have
Question #1: Consider the following class declaration when answering the parts of this question:
class List
{
public:
List(); //Default constructor; The list will have an initial size equal to 1
//and count equal to 0. Initialize the values in all the cells of
//the list to 0.
List(const List &); //copy constructor
~List(); //destructor
bool IsEmpty(){return count ==0;}; //returns true if List is empty.
bool IsFull(){return count == size;}; //returns true is List is full.
void Add(const int &); //adds an item, inorder, into the List. Items may be shifted if
//necessary. Also if the array is full its size of tripled.
int Subtract(const List & L2); //subtracts the values in L2 from their corresponding values in L
//and stores the results (difference) in the corresponding
//cells in L. The sum of the values stored in L is then returned.
//Assume L and L2 have the same count and capacity.
int Find(const int &); // returns the location of item in the list; otherwise -1;
friend ostream & operator<<(ostream & out, const List & Org);
//Overload the operator<< with chaining. This function will print
//all the values stored in L.
private:
int *L; //dynamic array
int size; //capacity of the dynamic array, L
int count; //number of items stored in the dynamic array, L
};
a. Implement the default constructor.
b. Implement the copy constructor.
c. Implement Add.
d. Implement the code necessary to overload operator<< as a friend function with chaining.
e. Implement Subtract.
f. What is the output from the following sequence of List operations?
List A, B;
int X:
A.Add(5);
A.Add(40);
A.Add(3);
A.Add(10);
B.Add(15);
B.Add(40);
B.Add(13);
B.Add(0);
X=A.Subtract(B);
A.Add(X);
B.Add(X);
X=B.Subtract(A);
B.Add(X);
cout<
cout< g. How many times is the function DoubleSize called when the following statement are executed. List A, B; int X; A.Add(5); A.Add(40); A.Add(3); A.Add(10); Question #2: T/F 1._________The array name of a dynamic array is a constant pointer to the first element in the array. 2._________The copy constructor is always called during the declaration of an object 3._________Friend functions of a class have access to its private members. 4._________The function new allows us to allocate memory during compile time. 5._________The function delete is used to de-allocate memory allocated by new. 6._________Typedef defines a new type for higher program efficiency. 7._________An ADT defines data and the operations that operate on that data. 8._________this is an object. 9.__________The open function binds a stream to a filename. 10.__________Overloaded functions can have the same name and return type, but they must have different argument lists. 11.__________An array is accessed randomly because the first element is accessed quicker than the last element in the array. 12.__________Objects can be passed explicitly through *this. 13._________The copy constructor is called during a call-by-value. 14._________The state of a class is the public data members. 15._________ A deep copy is a bit-by-bit copy done by the copy constructor.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
