OUTCOMES
After you finish this assignment, you will be able to do the following:
DESCRIPTION
A binary arithmetic operation takes two double operands (left and right) to perform addition, subtraction, multiplication, or division on. For example, 10 + 11 is an addition (+) whose two operands are 10 and 11. When this operation is performed, the result will be 21. We can also write this operation as + 10 11.
Write a program that reads basic arithmetic operation instructions (without results) from a given input file named operations-in.txt(see below), performs the operations, and saves their results to an output file named operations-out.txt. For example, if the input file has the following operation commands:
+ 20 11 - 96 75 * 87 70 / 22 9
The program output file should be like this:
20.00 + 11.00 = 31.00 96.00 - 75.00 = 21.00 87.00 * 70.00 = 6090.00 22.00 / 9.00 = 2.44
While there are many ways to implement this program, this assignment asks you to do it in an Object-Oriented Programming (OOP) way using what you learned in the past few weeks. That means creating an abstract class called Operation with two members one for the left operand and the other for the right operand. Then we create a class Addition that inherits from Operation and can perform the actual addition of the left operand to the right operand. Similarly, we create three more classes (also inheriting from Operation): Subtraction, Multiplication, and Division.
The following instructions should guide you through the implementation of this program:
The Operation class should also define a friend function that overloads the <<operator. The prototype of this function should be like this:
friend ostream& operator<<(ostream& out, const Operation& opr); This operator prints out the operation and its result to the output stream out in a format similar to that of the output file above. Use the setw, fixed, and setprecision manipulators to achieve that format.
OPERATIONS-IN.TXT
+ 20 11
- 96 75
- 84 44
+ 19 54
/ 20 46
* 99 74
* 87 70
/ 22 9
/ 3 24
+ 39 17
+ 12 23
* 80 77
- 3 65
+ 10 16
* 52 8
/ 71 77
+ 27 14
* 80 87
+ 37 35
/ 65 22
Short Summary:
Source Code:
Operation.h:
#ifndef OPERATION_H
#define OPERATION_H
#include <string>
using namespace std;
class Operation{
protected:
// two members one for the left operand and the other for the
right
double left;
double right;
public:
//parameterized constrctor
Operation(double, double);
// pure virtual functions
virtual double perform() const = 0;
virtual char symbol() const = 0;
//default destructor
~Operation();
// friend function
friend ostream& operator<<(ostream& , const
Operation&);
};
#endif
Operation.cpp:
#include "Operation.h"
#include <iostream>
#include <iomanip>
using namespace std;
//parameterized constrctor
Operation :: Operation(double l, double r){
left = l;
right = r;
}
//default destructor
Operation :: ~Operation(){}
/**
* Function: operator << overload
* It uses ostream and an Operation object
* It displays the result in proper format
*/
ostream& operator<<(std::ostream& out, const
Operation &opr)
{
out << fixed << setprecision(2) <<
opr.left << setw(5) << opr.symbol() << setw(10)
<< opr.right << " = " << setw(10) <<
opr.perform();
//return the output stream
return out;
}
addition.h:
#ifndef ADDITION_H
#define ADDITION_H
#include <iostream>
#include "Operation.h"
using namespace std;
class Addition : public Operation {
public:
Addition(double,double);
~Addition();
double perform() const;
char symbol() const;
};
#endif
addition.cpp:
#include "addition.h"
#include <iostream>
using namespace std;
Addition :: Addition(double l, double r):Operation(l, r){
}
Addition :: ~Addition(){}
double Addition :: perform() const {
return left + right;
}
char Addition :: symbol() const{
return '+';
}
subtraction.h:
#ifndef SUBTRACTION_H
#define SUBTRACTION_H
#include <iostream>
#include "Operation.h"
using namespace std;
class Subtraction : public Operation{
public:
Subtraction(double,double);
~Subtraction();
double perform() const;
char symbol() const;
};
#endif
subtraction.cpp:
#include "subtraction.h"
#include <iostream>
using namespace std;
Subtraction :: Subtraction(double l, double r):Operation(l,
r){
}
Subtraction :: ~Subtraction(){}
double Subtraction :: perform() const {
return left - right;
}
char Subtraction :: symbol() const{
return '-';
}
multiplication.h:
#ifndef MULTIPLICATION_H
#define MULTIPLICATION_H
#include <iostream>
#include "Operation.h"
using namespace std;
class Multiplication : public Operation{
public:
Multiplication(double,double);
~Multiplication();
double perform() const;
char symbol() const;
};
#endif
multiplication.cpp:
#include "multiplication.h"
#include <iostream>
using namespace std;
Multiplication :: Multiplication(double l, double
r):Operation(l, r){
}
Multiplication :: ~Multiplication(){}
double Multiplication :: perform() const {
return left * right;
}
char Multiplication :: symbol() const{
return '*';
}
division.h:
#ifndef DIVISION_H
#define DIVISION_H
#include <iostream>
#include "Operation.h"
using namespace std;
class Division : public Operation{
public:
Division(double,double);
~Division();
double perform() const;
char symbol() const;
};
#endif
division.cpp:
#include "division.h"
#include <iostream>
using namespace std;
Division :: Division(double l, double r):Operation(l, r){
}
Division :: ~Division(){}
double Division :: perform() const {
return left / right;
}
char Division :: symbol() const{
return '/';
}
InputFile:
operations-in.txt
+ 20 11
- 96 75
- 84 44
+ 19 54
/ 20 46
* 99 74
* 87 70
/ 22 9
/ 3 24
+ 39 17
+ 12 23
* 80 77
- 3 65
+ 10 16
* 52 8
/ 71 77
+ 27 14
* 80 87
+ 37 35
/ 65 22
Sample Run:
Console output:

OUTPUT FILE : operations-out.txt :

**************************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
**************************************************************************************
OUTCOMES After you finish this assignment, you will be able to do the following: Define an...
C++ A rational number is of the form a/b, where a and b are integers, and b is not equal 0. Develop and test a class for processing rational numbers. Details: Your program should have 3 files: a driver file to test the operations, a header file for the class definition and any operator overloads you need, and an implementation file with the definitions of the items in the header file. The class should read and display all rational numbers...
This is a quick little assignment I have to do, but I missed alot
of class due to the Hurricane and no one here knows what theyre
doing. please help! this is Java with intelli-J
Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...
Complex number class:: Question Changed to just the Java portion Design a class in and Java that represents complex numbers and supports important operations such as addition, subtraction, multiplication and division. (the following is for the c++ and python version, not sure if its needed for this) op: Complex × Complex → Complex op: Complex × double → Complex op: double × Complex → Complex Where op is one of +, -, *, or /. In addition, you will need...
Header file for the Rational class:
#ifndef RATIONAL_H
#define RATIONAL_H
class Rational
{
public:
Rational( int = 0, int = 1 ); // default constructor
Rational addition( const Rational & ) const; // function
addition
Rational subtraction( const Rational & ) const; // function
subtraction
Rational multiplication( const Rational & ) const; // function
multi.
Rational division( const Rational & ) const; // function
division
void printRational () const; // print rational format
void printRationalAsDouble() const; // print rational as...
C++ must use header files and implementation files as separate files. I’ll need a header file, implementation file and the main program file at a minimum. Compress these files into one compressed file. Make sure you have adequate documentation. We like to manipulate some matrix operations. Design and implement a class named matrixMagic that can store a matrix of any size. 1. Overload the addition, subtraction, and multiplication operations. 2. Overload the extraction (>>) and insertion (<<) operators to read...
Please use 2 new classes! Overview Develop an interactive multi-purpose calculator to input, calculate, and display results for operations on a variety of mathematical types. The different types include a basic Floating-point type, a Vector type, and a Fraction type. Write a system that allows a user to perform basic operations on each of these types by entering the type of calculator, operation, and left and right operands. The system will perform the selected operation, print the results, and continue...
General Description: A rational number is of the form a/b, where a and b are integers, and b is not equal 0. Develop and test a class for processing rational numbers. Details: Your program should have 3 files: a driver file to test the operations, a header file for the class definition and any operator overloads you need, and an implementation file with the definitions of the items in the header file. The class should read and display all rational...
A protocol is a set of rules that define some operation. For
example, the Internet Protocol (IP)
specifies how messages are routed throughout the internet. In
this problem, you are asked to
implement your 1st messaging protocol (MP1). MP1 is a binary
protocol that is used to efficiently
encode a set of arithmetic operations using a 4-byte data type
(e.g., int). The specification of the
protocol is as follow. Using a 4-byte (32-bit stream), MP1
messages encode the ‘+’, ‘-‘,...
C++ A rational number is of the form a/b, where a and b are integers, and b is not equal 0. Develop and test a class for processing rational numbers.Pointers aren't needed and it should be able to handle all of these examples and more. Details: Your program should have 3 files: a driver file to test the operations, a header file for the class definition and any operator overloads you need, and an implementation file with the definitions of...
Objectives:
1. Classes and Data Abstraction?2. User-defined classes?3.
Implementation of a class in separate files
Part 1:
In this assignment, you are asked:
Stage1:?Design and implement a
class named memberType
with the following requirements:
An object of memberType holds the following
information: • Person’s first name (string)?• Person’s last name
(string)?• Member identification number (int)
• Number of books purchased (int)?• Amount of money spent
(double)?The class memberType has member functions that
perform operations on objects of memberType. For the...