Fill This Form To Receive Instant Help
Homework answers / question archive / 1
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;
}
#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;
}