Question
Answered step-by-step
Hello, I need help with making the driver for this program....
Hello, I need help with making the driver for this program. Included my header and cpp files for the calculato. just need t
...
Question
Answered step-by-step
Hello, I need help with making the driver for this program....
Hello, I need help with making the driver for this program. Included my header and cpp files for the calculato. just need the menu and missing functions.
ASSIGNMENT INSTRUCTIONS.
driver.cpp
main()
Functionality: The main function should display the types of calculator modes and allow the user to choose one. If the user chooses Option 1, the program should run an integer calculator. If the user chooses Option 2, the program should run a floating point calculator. If the user chooses Option 3, the program should run a complex number calculator. The program should exit if the user chooses Option 0, and an error message should be displayed if the user does not choose a valid option.
In addition to the main functions, your driver should have at minimum 5 more functions:
getCalcType()
Input Parameters: none
Returned Output: integer number corresponding to the calculator type
Functionality: This function should display the calculator mode options to the screen. It should get the user's choice and return it to the calling function.
getOperation()
Input Parameters: none
Returned Output: integer number corresponding to the arithmetic operation
Functionality: This function should display the caculator arithmetic operations to the screen. It should get the user's choice and return it to the calling function.
integerCalculator()
Input Parameters: none
Returned Output: none
Functionality: This function should create the appropriate calculator. It should prompt the user for the arithmetic operation. If the user did not choose Option 0, they should be prompted for the operands. The appropriate result should be displayed to the user, based on the arithmetic operation the user chose. Don't forget, you can't divide by zero!
floatingCalculator()
Input Parameters: integer number of faculty, array of Faculty
Returned Output: none
Functionality: This function should create the appropriate calculator. It should prompt the user for the arithmetic operation. If the user did not choose Option 0, they should be prompted for the operands. The appropriate result should be displayed to the user, based on the arithmetic operation the user chose. Don't forget, you can't divide by zero!
complexCalculator()
Input Parameters: none
Returned Output: integer user choice
Functionality: This function should create the appropriate calculator. It should prompt the user for the arithmetic operation. If the user did not choose Option 0 or Option 4, they should be prompted for the operands. The appropriate result should be displayed to the user, based on the arithmetic operation the user chose. Don't forget, you can't perform division on a complex number!
WHAT I HAVE.
Calculator.h
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include
using namespace std;
template
class Calculator {
T operand1, operand2;
public:
Calculator ();
Calculator (T o1, T o2);
void getOperands();
T addition();
T subtraction();
T multiplication();
T division();
};
#endif
Calculator.cpp
#include
#include "Calculator.h"
template
Calculator :: Calculator() {
operand1 = 0;
operand2 = 1;
}
template
Calculator :: Calculator (T o1, T o2) {
operand1 = o1;
operand2 = o2;
}
template
void Calculator :: getOperands() {
std::cout << "Enter the first operand: ";
std::cin >> operand1;
std::cout << "Enter the second operand: ";
std::cin >> operand2;
}
template
T Calculator :: addition() {
return operand1 + operand2;;
}
template
T Calculator :: subtraction() {
return operand1 - operand2;;
}
template
T Calculator :: multiplication() {
return operand1 * operand2;;
}
template
T Calculator :: division() {
return operand1 / operand2;;
}
Complex.h
#ifndef COMPLEX_H
#define COMPLEX_H
#include
#include
using namespace std;
class ComplexNumber
{
private:
double real;
double imaginary;
public:
ComplexNumber();
ComplexNumber(double r,double i);
ComplexNumber operator+ (const ComplexNumber &cmp);
ComplexNumber operator- (const ComplexNumber &cmp);
ComplexNumber operator* (const ComplexNumber &cmp);
ComplexNumber operator/ (const ComplexNumber &cmp);
double getReal();
void setReal(double r);
double getImaginary();
void setImaginary(double i);
friend ostream& operator<<(ostream& os, const ComplexNumber& cmp);
friend istream& operator>>(istream& is, ComplexNumber& cmp);
};
#endif
Complex.cpp
#include "complex.h"
#include
ComplexNumber::ComplexNumber()
{
real = 0;
imaginary = 0;
}
ComplexNumber::ComplexNumber(double rl,double i)
{
real = rl;
imaginary = i;
}
ComplexNumber ComplexNumber:: operator+ (const ComplexNumber &cmp)
{
ComplexNumber tmpComplexNum;
tmpComplexNum.real = real+cmp.real;
tmpComplexNum.imaginary = imaginary + cmp.imaginary;
return tmpComplexNum;
}
ComplexNumber ComplexNumber:: operator- (const ComplexNumber &cmp)
{
ComplexNumber tmpComplexNum;
tmpComplexNum.real = real-cmp.real;
tmpComplexNum.imaginary = imaginary - cmp.imaginary;
return tmpComplexNum;
}
ComplexNumber ComplexNumber:: operator* (const ComplexNumber &cmp)
{
ComplexNumber tmpComplexNum;
tmpComplexNum.real = real*cmp.real - imaginary*cmp.imaginary;
tmpComplexNum.imaginary = imaginary*cmp.real + real*cmp.imaginary;
return tmpComplexNum;
}
ComplexNumber ComplexNumber:: operator/ (const ComplexNumber &cmp)
{
ComplexNumber tmpComplexNum;
double numerator = ((real*cmp.real)+(imaginary*cmp.imaginary));
double denominator = (pow(cmp.real,2)+pow(cmp.imaginary,2));
tmpComplexNum.real = numerator/denominator;
numerator = (imaginary*cmp.real) - (real*cmp.imaginary);
tmpComplexNum.imaginary = numerator/denominator;
return tmpComplexNum;
}
ostream& operator<<(ostream& os, const ComplexNumber& cmp)
{
if(cmp.imaginary >= 0)
os << cmp.real << "+" << cmp.imaginary<< "i";
else if(cmp.imaginary < 0)
os << cmp.real << cmp.imaginary<< "i";
return os;
}
istream& operator>>(istream& is, ComplexNumber& cmp)
{
cout<<"Please enter real No: ";
is >> cmp.real;
cout<<"Please enter imaginary No: ";
is >> cmp.imaginary;
return is;
}
double ComplexNumber::getReal()
{
return real;
}
void ComplexNumber::setReal(double r)
{
real = r;
}
double ComplexNumber::getImaginary()
{
return imaginary;
}
void ComplexNumber::setImaginary(double i)
{
imaginary = i;
[Show More]