Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
12 Cards in this Set
- Front
- Back
TDP default constructor that initializes x, y, and z to 0 |
TDP() : x(0.0), y(0.0), z(0.0) {} |
|
TDP constructor taking 3 double parameters to initialize the 3 data members |
TDP(double xx, double yy, double zz) { x = xx; y == yy; z = zz; } |
|
TDP TDP has 3 private data members: x, y, z of type double |
private: double x, y, z; |
|
TDP declare objects pt1 and pt2 of type TDP w/ pt1 initialized to (1.0, 1.0, 2.0) and pt2 initialized to (-1.0, 0.0, 1.0). |
TDP pt1(1.0, 1.0, 2.0); TDP pt2(-1.0, 0.0, 1.0); |
|
TDP Do we need to write a copy constructor for the TDP class? Why or why not? |
No constructor needed because there are no pointers. The default copy constructor is sufficient. |
|
TDP Write an accessor member function which returns the value of the data member x. |
double TDP::getx() const { return x; } |
|
TDP Write a mutator member function which takes a single double value and assigns that value to the data member y. |
void TDP::setx(double n) { y = n; } |
|
TDP Write a statement to declare a pointer called ptPtr to a TDP and initialize it to reference the pt1 (which you declared in part b). |
TDP *ptPtr = &pt1; |
|
TDP Use ptPtr and the mutator written in part e to modify pt1’s y data member to 4.0. Do NOT use the variable pt1 to access the mutator. |
ptPtr->sety(4.0); |
|
TDP Write a statement to declare a vector of TDP called myVector such that myVector has an initial size of one. You may assume has already been included. |
vector myVector(1); |
|
TDP Write a statement using ptPtr which you declared and initialized in part f to assign the value of pt1 to the first position (i.e., index 0) in myVector. |
myVector[0] = *ptPtr; |
|
TDP Write a statement to assign the value of pt2 to the second position (i.e., index 1) in myVector. |
myVector.push_back(pt2); |