#include <iostream> #include "SimpleCalculator.h" using std::cout;using std::endl; int main(){ double a = 10.0; double b = 20.0; /* Declare any other variables needed here */ /* Instantiate an object of type SimpleCalculator */SimpleCalculator sc;// cout << "The value of a is: " << a << "\n" << "The value of b is: " << b << "\n\n"; double addition=sc.add(a, b); /* Write a line that adds a & b through your SimpleCalculator object; assign the result to a variable named "addition" */ cout << "Adding a and b yields " << addition << "\n"; double subtraction=sc.subtract( a, b ); cout << "Subtracting b from a " << subtraction << "\n"; double multiplication = sc.multiply( a, b ); cout << "Multiplying a and b yields " << multiplication << "\n"; double division=sc.divide(a,b); /* write a line that divides a and b through the SimpleCalculator object; assign the result to a variable named "division" */ cout << "Dividing a by b yields " << division << endl; return 0; } // end main****************************************** // Chapter 7 of C++ How to Program// Chapter 7 of C++ How to Program// Simplecalculator.cpp#include "simplecalculator.h" /* write definition for add method */double SimpleCalculator::add(double a,double b) const{return a + b;}// function subtract definitiondouble SimpleCalculator::subtract( double a, double b ) const{ return a - b; } // end function subtract // function multiply definitiondouble SimpleCalculator::multiply( double a, double b ) const{ return a * b; } // end function multiply /* write definition for divide method */double SimpleCalculator::divide(double a,double b) const {return a/b;} /************************************************************************** // Chapter 7 of C++ How to Program// Simplecalculator.h // class SimpleCalculator definitionclass SimpleCalculator { public: double add(double,double) const; /* write prototype for add method */ double subtract( double, double ) const; double multiply( double, double ) const; /* write prototype for divide method */ double divide(double ,double) const; }; // end class SimpleCalculator /**************************************************************************

评论