Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Homework Questions 1)There is ambiguity in the variable names in the following function that sets the private instance variables width and height to the
C++ Homework Questions
1)There is ambiguity in the variable names in the following function that sets the private instance variables width and height to the incoming parameter values:
bool Rectangle::setWidthHeight(double width, double height) { if ( width <= 0 || height <= 0 ) { // don't allow negative width or height return false; } else { width = width; // oops! height = height; return true; } }
Which of the following should you use to correct this?
a) | bool Rectangle::setWidthHeight(double width, double height) { if ( width <= 0 || height <= 0 ) { // don't allow negative width or height return false; } else { this->width = width; this->height = height; return true; } } |
b) | bool Rectangle::setWidthHeight(double width, double height) { if ( width <= 0 || height <= 0 ) { // don't allow negative width or height return false; } else { width = this->width; height = this->height; return true; } } |
c) | bool Rectangle::setWidthHeight(double width, double height) { if ( width <= 0 || height <= 0 ) { // don't allow negative width or height return false; } else { this->width = that->width; this->height = that->height; return true; } } 3)Which of the following is a static function of the Dog class?
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started