Question: The square and Triangle classes shown above will be used for remainder of the questions. 9 . Which code snippet correctly implements the parametrized A

The square and Triangle classes shown above will be used for remainder of the questions.
9. Which code snippet correctly implements the parametrized A) Square constructor which takes in x, y, and side?
Square(float x, float y, float side){ this ->side = side;}
B) Square(float x, float y, float side) : Shape(x, y){ this ->side = side;}
C) Square(float x, float y, float side){ this ->x = x; this ->y = y; this ->side = side; }
D) All of the above
E) Only B and C
10. Which code snippet correctly implements the draw method for the Square class?
A) void draw(){
glColor3f(color.r, color.g, color.b);
glBegin(GL_POLYGON); glVertex2f(getX(), getY()); glVertex2f(getX()+ side, getY()); glVertex2f(getX()+ side, getY()- side); glVertex2f(getX(), getY()- side);
glEnd (); }
B) void draw(){
glColor3f(color.r, color.g, color.b);
glBegin(GL_POLYGON);
glVertex2f(x, y);
glVertex2f(x + side, y); glVertex2f(x + side, y - side); glVertex2f(x, y - side);
glEnd (); }
C) void draw(){
Color c = getColor ();
glColor3f(c.r, c.g, c.b);
glBegin(GL_POLYGON); glVertex2f(getX(), getY()); glVertex2f(getX()+ side, getY()); glVertex2f(getX()+ side, getY()- side); glVertex2f(getX(), getY()- side);
glEnd (); }
D. All of the above
E. Only A and C
11. Which code snippet correctly implements the parametrized Triangle constructor which takes in x, y, base, and height?
A) Triangle(float x, float y, float base, float height){
setX(x);
setY(y);
this ->base = base; this->height = height;
}
B Triangle(float x, float y, float base, float height) : Shape(x,y){
this ->base = base;
this->height = height; }
C) Triangle(float x, float y, float base, float height){
this ->x = x;
this ->y = y; this->base = this->height; )
D) All of the above
E) Only A and B
12. Which code snippet correctly implements the parametrized Triangle constructor which takes in x, y, and color?
A) Triangle(float x, float y, Color color){ this ->x = x;
this ->y = y; this->color = color; base =0.3f;
height =0.2f;}
B) Triangle(float x, float y, Color color){ setX(x);
setY(y); setColor(color); base =0.3f; height =0.2f;}
C) Triangle(float x, float y, Color color) : Shape(x, y){ this->color = color; base =0.3f; height =0.2f; }
D) Triangle(float x, float y, Color color) : Shape(x, y, color){ base =0.3f; height =0.2f; }
E) All of the above, except A
13. Which of the following statements is false?
A. Triangle publicly inherits from Shape.
B. Square publicly inherits from Shape.
C. Shape is the parent of both Triangle and Square
D. Triangle and Square need to implement their own draw method. E. All of the above statements are true.
14. Which data members of Shape are accessible to Triangle and Square? A. xandy
B. color
C. x, y, and color D. None of the above
15. Which code snippet correctly creates an instance of Square, not on the heap?
A) Square* square = new Square();
B) Square square = Square ();
C) Shape* shape = new Square();
D) Shape shape = Square ();
E) Both B and D
16. Which code snippet correctly creates an instance of Triangle on the heap?
A) Triangle* triangle = new Triangle();
B) Triangle triangle = Triangle ();
C) Shape* shape = new Triangle();
D) Shape shape = Triangle ();
E) Both A and C
17. Which code snippet correctly creates an array of Squares of size 7, on the heap?
A) Square* squares[7];
B) Square* squares = new Square[7];
C) Square squares *[7];
D) Square* squares*[7];
E) Both A and B
18. Which code snippet correctly releases the memory from the previous question?
A) delete squares;
B) delete[] squares;
C) for (int i =0; i 7; i++){ delete squares[i];}
D) for (int i =0; i 7; i++){ delete squares[i];} delete[] squares;
E) None of the above
19. Which code snippet correctly creates an array of Shape pointers of size 7?
A) Shape shapes [7];
B) Shape shapes *[7];
C) Shape ** shapes = new Shape [7];
D) Shape ** shapes = new Shape *[7];
E) Both C and D
20. Which code snippet correctly releases the memory from the previous question?
A) delete shapes;
B) delete[] shapes;
C) for (int i =0; i 7; i++){ delete shapes[i];}
D) for (int i =0; i 7; i++){ delete shapes[i]; } delete[] shapes;
E) None of the above
The square and Triangle classes shown above will

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!