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

c++ question: //definition of class Rectangle class Rectangle { public: double a

ID: 3693328 • Letter: C

Question

c++ question:

//definition of class Rectangle

class Rectangle             

{   

     public:       double area();                    

                      double perimeter();               

                      Rectangle();                    

                      Rectangle(double x, double y);  

     private:     double length;

                    double width;

};

Consider the segment of code above. Which of the following declarations is correct?__________ (2 points)

Select one:

a. Rectangle rect;

b. rect Rectangle ;

c. rect Rectangle.area();

d. class Rectangle rect;

Explanation / Answer

C++ code:

#include <bits/stdc++.h>
using namespace std;

class Rectangle{   
public:   
   double area(){
       return length*width;
   };
   double perimeter(){
       return 2*(length+width);
   };   
   Rectangle(){
       length=0;
       width=0;
   };
   Rectangle(double x, double y){
       length=x;
       width=y;
   };

private:   
   double length;
   double width;
};

int main(){
     
   return 0;
}

b and c are not correct declarations because in these variable name comes first and then the class name.
But it should be the other way round. class name first and then variable name.

a and d are correct.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote