Question
Please code in C++, thanks! In this lab assignment, please re-use the Calculator class definition in week3, as our Based/Parent class, and in the Derived/Child
Please code in C++, thanks!
In this lab assignment, please re-use the Calculator class definition in week3, as our Based/Parent class, and in the Derived/Child class, we will have a binary calculator that will return binary output of addition(), subtraction(), multiplication(), division() class BinaryCalculator : public Calculator { public: //overriding functions: int addition () { return binaryOf(num1+num2); } int subtraction () .... etc. int binaryOf( int val) //here we use int datatype to represent bin value { //step1: store binary of val in an array[], i.e.: 0100 //step2: construct an int value to represent that binary value in array. i.e: int outputBIn = 0x1000 + 1x100 + 0x10 + 0x1; //return outputBin } } The program should be able to read a set of calculators from text file, each line in the text file has 3 values, the first two are 2 inputs, and the last value is either 10 (decimal calculator - the parent class), or 2 (binary calculator - the child class) After that the program will print 4 calculations output for each calculator in the set. i.e.: file calculatorList.csv 1 1 2 3 5 10 output: binary calculator 0: addition: 10, subtraction: 00, multiplication: 01, division: 01 decimal calculator 1: addition: 8, subtraction: -2, multiplication: 15, division: 0.6 This will be a good practice for Vectors, Class, Inheritance, Overriding, Virtual Function, Polymorphism, and File Processing.. Thanks, ps: please use this input file calculators.csv
1 1 2 5 3 10 4 2 2 7 9 10 9 3 2
Base class:
main.cpp
#include
#include "Class.h"
using namespace std;
int main()
{
int x,y;
cout<<"Please enter two values : ";
cin>>x>>y;
Calculator obj(x,y);
cout<<"Addition::"< cout<<"Subtraction::"< cout<<"Multiplication::"< cout<<"Division::"< return 0; } Class.h class Calculator { private: int input1; int input2; public: Calculator(); Calculator(int,int); int addition(); int subtraction(); int multiplication(); float division(); int getinput1(); int getinput2(); void setinput1(int); void setinput2(int); }; Class.cpp #include "Class.h" Calculator::Calculator() { input1=1; input2=1; } Calculator::Calculator(int x,int y) { input1=x; input2=y; } int Calculator::addition() { return input2+input1; } int Calculator::subtraction() { return input1-input2; } int Calculator::multiplication() { return input2*input1; } float Calculator::division() { return input1/input2; } int Calculator::getinput1() { return input1; } int Calculator::getinput2() { return input2; } void Calculator::setinput1(int input1) { this->input1=input1; } void Calculator::setinput2(int input2) { this->input2=input2; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started