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

The following code segment will not compile. Describe the errors in your own wor

ID: 666551 • Letter: T

Question

The following code segment will not compile. Describe the errors in your own words.
(Do not copy compiler output)

#include <iostream>

using namespace std;

class Adder

{

private:

      float left, right;

      float result;

     

public:

     Adder(float l, float r)

      {

            left = l;

            right = r;

            result = 0.0;

      }

      float Calc()

      {

            result = left + right;

            return result;

      }

      int Calc( )

      {

            result = left + right;

            return int( result );

      }

};

class Calculator

{

private:

      Adder a;

public:

      Calculator(float l, float r) {}

};

Explanation / Answer

Compiling ADDER.CPP:
Error ADDER.CPP 29: Multiple declaration for 'Adder::Calc()'
Error ADDER.CPP 47: Cannot find default constructor to initialize member 'a' in function Calculator::Calculator(float,float)

we declared calc () as float and integer.

we dint use any variable in function calculator

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote