c++ question
MyClass has an internal 2-D array of dynamically allocated doubles, pointed to by the member named data:
class MyClass
{
private:
double **data;
int width, height;
// other stuff
}
Assume width and height are set by constructors and mutators, and the class deals with them and all other data management correctly. Here is the method we are interested in analyzing:
void MyClass::allocateDynArray(int newHeight, int newWidth)
{
int row;
if ( !valid( newHeight, newWidth ) )
return;
height = newHeight;
width = newWidth;
// delete and NULLs the data
deallocateDynArray();
data = new double*[height];
for ( row = 0; row < height; row++ )
data[row] = new double[width];
setArrayToAllZeros();
}
Check the true statements (there will be one and possible more):
| A. | A destructor is essential for this class. | |
| B. | The invocation of deallocateDynArray() needs to be repositioned to a different place in the code in order to avoid a potential crash or memory leak. | |
| C. | It's fine as is. | |
| D. | We have to set data = NULL before we do our error return near the top | |
| E. |
setArrayToAllZeros() needs parameters to know what
bounds to use for its (likely) internal loops. |
anything allocated with new is created on the heap and must be de-allocated with delete.
A. true.
B. true
C.false(its not fine)
D. true(its a good practice but not necessary)
E.false (doesnot need parameters it can directly initialize all the values pointed by instance memeber data to 0)
c++ question MyClass has an internal 2-D array of dynamically allocated doubles, pointed to by the...
please write in c++.
4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...
I need this in C++. This is all
one question
Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...
Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...