Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Allocate memory for houseHeight using the new operator. #include <iostream> u

ID: 3763024 • Letter: 1

Question

1. Allocate memory for houseHeight using the new operator.

#include <iostream>
using namespace std;

int main() {
double* houseHeight = 0;

/* Your solution goes here */

*houseHeight = 23;
cout << "houseHeight is " << *houseHeight;

return 0;
}

2. Deallocate memory for kitchenPaint using the delete operator.

#include <iostream>
using namespace std;

class PaintContainer {
public:
~PaintContainer();
double gallonPaint;
};

PaintContainer::~PaintContainer() { // Covered in section on Destructors.
cout << "PaintContainer deallocated." << endl;
return;
}

int main() {
PaintContainer* kitchenPaint;

kitchenPaint = new PaintContainer;
kitchenPaint->gallonPaint = 26.3;

/* Your solution goes here */

return 0;
}

Explanation / Answer

#include <iostream>
using namespace std;
int main() {
double* houseHeight = 0;
/* Your solution goes here */
houseHeight = new double;
*houseHeight = 23;
cout << "houseHeight is " << *houseHeight;
return 0;
}

#include <iostream>
using namespace std;
class PaintContainer {
public:
~PaintContainer();
double gallonPaint;
};
PaintContainer::~PaintContainer() { // Covered in section on Destructors.
cout << "PaintContainer deallocated." << endl;
return;
}
int main() {
PaintContainer* kitchenPaint;
kitchenPaint = new PaintContainer;
kitchenPaint->gallonPaint = 26.3;
/* Your solution goes here */
delete kitchenPaint;
return 0;
}