正文

简单的计算器代码2006-12-23 21:48:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wwwzrccom/21862.html

分享到:

#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 /**************************************************************************

阅读(3169) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册