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

This program is supposed to take 2 numbers add, subtract, multiply, and divide t

ID: 3630234 • Letter: T

Question

This program is supposed to take 2 numbers add, subtract, multiply, and divide them. I have 3 files; main.cpp, BinaryOperator.cpp, and BinaryOperator.h. When I run the compiler I get the following error messages;
1. "prototype for void Adder::DoOp() const does not match any class Adder

2. virtual double Adder::DoOp() const

3. void Adder::DoOp() const and virtual doubleAdder::DoOp() const cannot be overloaded

4. In function void Test(): no matching function for call to Adder::Adder(int)

I am only dealing with the "Adder Function" right now but based on results I am sure I will get the same error messages.

How do I fix this?

Here are my files:

/*main.cpp
*/
#include <cstdlib>
#include <iostream>

#include "BinaryOperator.h"

int main(int argc, char *argv[]){
Test();

system("PAUSE");
return 0;
}


/*BinaryOperator.cpp
*/

#include "BinaryOperator.h"
#include <iostream>
#include <iomanip>
#include <vector>

void Adder::
DoOp () const {
fOp1;
fOp2;
}// Adder Function
/*
void Subtracter::
DoOp() const{

}//Subtracter Function

void Multiplier::
DoOp() const{

}// Multiplier Function

void Divider::
DoOp() const{

}// Divider Function */
void Test (){
std::vector<BinaryOperator*> operators;
operators.push_back (new Adder (3+5));
// operators.push_back (new Multiplier (3*5));
// operators.push_back (new Multiplier (2*0));

for(std::size_t i= 0; i < operators.size (); ++i){
operators.at (i)-> DoOp ();//example of polymorphism
}// for i

}// Test


/*BinaryOperator.h
*/

#ifndef BINARYOPERATOR_H
#define BINARYOPERATOR_H

class BinaryOperator {

public:
BinaryOperator ( double op1, double op2 ) : fOp1 ( op1 ), fOp2 ( op2 ) {}
virtual double DoOp () const = 0;

protected:
const double fOp1;
const double fOp2;
}; // class BinaryOperator

class Adder : public BinaryOperator {

public:
Adder ( double op1, double op2 ) : BinaryOperator (op1, op2) {}
virtual double DoOp () const;
}; // class Adder

class Subtractor : public BinaryOperator {

public:
Subtractor ( double op1, double op2 ) : BinaryOperator ( op1, op2 ) {}
virtual double DoOp () const;
}; // class Subtractor

class Multiplier : public BinaryOperator {

public:
Multiplier ( double op1, double op2 ) : BinaryOperator ( op1, op2 ) {}
virtual double DoOp () const;
}; // class Multiplier

class Divider : public BinaryOperator {

public:
Divider ( double op1, double op2 ) : BinaryOperator ( op1, op2 ) {}
virtual double DoOp () const;
}; // class divider

void Test ();

#endif

Explanation / Answer

My friend in the implementation of the function DoOp u wrote it in the class as a value returning function (double) and in the implementation it is void !! and i can`t understand what u r doing with this function operators.push_back (new Adder (3.0+5.0)); so i can help u :)

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