Working on an OOP calculator program
Let’s create a new project, MyCPP_04
, and create the main.cpp
, Calculator.cpp
, and Calculator.h
files. What we mainly want to do is to create a Calculator
class and then make the Add
functions the class methods.
Follow these steps:
- Type the following code into the
main.cpp
file:#include <iostream>
#include "Calculator.h"
using namespace std;
void main()
{
Calculator calculator; //defines the calculator object
cout << "My Calculations: " << calculator.GetName() << endl;
float input1, input2;
while (true)
{
cout << "Input the first value (0 to exit): ";
cin >> input1;
if (input1 == 0) //exit if the...