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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.