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

Also, can you make the new code compilable with the existing code? CMPS 370 Fall

ID: 3755344 • Letter: A

Question

Also, can you make the new code compilable with the existing code?

CMPS 370 Fall 2018 Assignment 3 (a) Draw a class diagram representing the classes declared below (b) Declare these classes in a file entitled "BinaryOperators.h", inserting appropriate pre-compilation directives. Define all the non-abstract methods in a source file entitled "BinaryOperators.cpp". Include also the definition of the function Test0. In this function use polymorphism to compute the following: 3+7, 3-5, 3*7, 3/5,3 /0 (c) Define mainO in a source file entitled "main.cpp". Call Test0 in mainO (d) Run you program and turn in the header files, source files, and the output of your program. class Binaryoperator i public: BinaryOperator double opl, double op2 virtual double Doop () const= 0; fopl ( opi, EOp2 ( op2 ) protected: const double fOp1; const double fOp2; class BinaryOperator class Adderpublic BinaryOperator public: Adder double op1, double op2BinaryOperator opi, op2) virtual double Doop const; : I/ class Adder class Subtractorpublic BinaryOperator f public: Subtractor double op1, double op2) : BinaryOperator opi, op2) [ virtual double Doop const; class Subtractor class Multiplierpublic BinaryOperator f public: Multiplier double op1, double op2 ) : BinaryOperator opi, op2) [ virtual double Doop const; : I/ class Multiplier class Dividerpublic BinaryOperator public: Divider ( double opi, double op2) BinaryOperator op1, op2 ) virtual double DoOp const; : I/ class v void Test )

Explanation / Answer

/*-----------BinaryOperators.h--------------*/

#ifndef BINARYOPERATIONS_H

#define BINARYOPERATIONS_H

#include <iostream>

#include <string>

#include <iostream>

#include <string>

using namespace std;

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

/*-----------BinaryOperators.cpp--------------*/

#include <iostream>

#include <string>

#include "BinaryOperators.h"

using namespace std;

double Adder::DoOp() const{

return fOp1 + fOp2 ;

}

double Subtractor::DoOp() const{

return fOp1 - fOp2 ;

}

double Multiplier::DoOp() const{

return fOp1 * fOp2 ;

}

double Divider::DoOp() const{

if (fOp2 == 0){

throw string("Divide by zero");

}

return fOp1 / fOp2 ;

}

void Test(){

  

BinaryOperator *bptr;

  

//3+7

Adder a(3,7);

bptr = &a;

cout <<"Adder output is " << bptr->DoOp() <<endl;

  

// 3-5

Subtractor s(3, 5);

bptr = &s;

cout <<"Subtractor output is " << bptr->DoOp() <<endl;

  

// 3*7

Multiplier m(3, 7);

bptr = &m;

cout <<"Multiplier output is " << bptr->DoOp() <<endl;

  

// 3/5

Divider d(3, 5);

bptr = &d;

cout <<"Divider output is " << bptr->DoOp() <<endl;

  

try{

// 3/0

Divider d1(3,0);

bptr = &d1;

cout <<"Divider output is " << bptr->DoOp() <<endl;

}

catch(string e) {

cout << e << endl;

}

  

}

/*-----------main_binary.cpp--------------*/

#include <iostream>

#include <string>

#include "BinaryOperators.h"

using namespace std;

int main(){

  

Test();

return 0;

}

-----------------output---------------------

Adder output is 10
Subtractor output is -2
Multiplier output is 21
Divider output is 0.6
Divide by zero

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