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

whenAnalyze the following code - which of the following statements accurately re

ID: 3801963 • Letter: W

Question

whenAnalyze the following code - which of the following statements accurately reflect the state of what is happening

class Circle

{

public:

     Circle(unsigned r) : m_radius(r) { }

     ~Circle() { }

     double getArea(void) {    

              return 3.14*(m_radius*m_radius);

      }

private:

    double m_radius;

};

#include

int main(int argc, char* argv[])

{

   using std::cout;

   using std::endl;

     cout << Circle(5.0).getArea() << endl;

     cout << (new Circle(7.86))->getArea() << endl;

     return 0;

}

The program has a syntax error on Circle(5.0).getArea()

The program compiles, but cannot run

C -

The program has a syntax error on new Circle(5).getArea()

D - The program compiles and runs, but the line

cout << (new Circle(7.86))->getArea() << endl; creates an anonymous object on the heap which subsequently leaks memory.


A -

The program has a syntax error on Circle(5.0).getArea()

B-

The program compiles, but cannot run

C -

The program has a syntax error on new Circle(5).getArea()

D - The program compiles and runs, but the line

cout << (new Circle(7.86))->getArea() << endl; creates an anonymous object on the heap which subsequently leaks memory.

Explanation / Answer

The Answer is D

There is no sysntax error in this program.So,the other options A,B,D are wrong.

The Program is getting compiling and running.But getting the wrong output in case of cout << (new Circle(7.86))->getArea() << endl;