Homework Help Question & Answers

c++ question MyClass has an internal 2-D array of dynamically allocated doubles, pointed to by the...

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.
0 0
Next > < Previous
ReportAnswer #1

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)

Know the answer?
Add Answer to:
c++ question MyClass has an internal 2-D array of dynamically allocated doubles, pointed to by the...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    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()...

  • NEEDED ASAP!!! 2D array in C++

    Write a program that finds the greatest sum of three adjacent numbers in any direction (up, down, left, right, or diagonally) in a 20x20 grid of numbers.All input data must be obtained from the stdin prompt. You can feed in the data from a file by using input redirection. The input file will contain the matrix ofnumbers from the top left to bottom right.Example input file: (input.txt)08 02 22 97 38 15 00 40 00 75 04 05 07 78...

  • This Program should run in C++ In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleTyp...

    This Program should run in C++ In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class...

  • Write the de?nition of a class that has the following properties

    Write the de?nition of a class that has the following properties:The name of the class is secretType.The class secretType has four member variables: with name of typestring, age and weight of type int, and height of type double.The class secretType has the following member functions. (Makeeach accessor function constant.)– print - outputs the data stored in the member variables withthe appropriate titles.– setName - function to set the name– setage - function to set the age– setWeight - function to...

  • Help with C++ program lifesaver

    http://img329.imageshack.us/img329/2827/pa3id8.jpgassignment: reread the code in display10.9 ^^. THENThen write a class TowD thatimplements the two-dimensional dynamic array of doubles using ideasfrom this display in its constructors. Youshould haveaprivate number of type pointer to double to point to the dynamicarray, and two int( or unsigned int) values that are MaxRows andMaxCols.Youshould supply a default constructor for which you areto choose a default maximum row and column sizes and aparameterized constructor that allows the programmer toset maximumrow and column sizes.Further, you should...

  • In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we...

    In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class should contain the following functions: •...

  • C++

    Need Help with this homework assignment:Week 4: Constructors and Destructors - iLab HelpLab 4 of 7: C++ Constructors (40 Points)L A B O V E R V I E WSummaryIn this lab, you will apply the knowledge you have gained this week by illustrating solutions to a programming problem using Visual Studio and C++. Use your textbookand lecture as a resource in completing the requirements of this lab.Deliverables1. Submit to Week 4's Dropbox, a single Notepad file containing the source...

  • SOMEONE PLS PLS DO THIS PROGRAM FOR Me C++ lifesaver Due at Midnight

    http://img329.imageshack.us/img329/2827/pa3id8.jpgassignment: reread the code in display10.9 ^^. THENThen write a class TowD thatimplements the two-dimensional dynamic array of doubles using ideasfrom this display in its constructors. Youshould haveaprivate number of type pointer to double to point to the dynamicarray, and two int( or unsigned int) values that are MaxRows andMaxCols.Youshould supply a default constructor for which you areto choose a default maximum row and column sizes and aparameterized constructor that allows the programmer toset maximumrow and column sizes.Further, you should...

  • Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

    Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static variables. Ensure integer variables input are within a range that will not cause integer overflow. Uses proper design techniques including reading UML Class Diagrams Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class...

  • 2-d array java (look for assignment7.java and customer.java at the end)

    In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified bya user. Then it will attempt to assign each customer to a seat in a movie theatre.1. First, you need to add one additional constructor method into Customer.java file.MethodDescription of the Methodpublic Customer (String customerInfo)Constructs a Customer object using the string containing customer's info. Use the split method of the String class...

Free Homework App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.