1 #include

2 #include

3 #include

4 #include

5

6 using namespacestd;7

8 //四则运算

9 template classElementaryArithmetic{10 private:11 T result;12 T operand1, operand2;13 charoperators;14 public:15 //四则运算

16 voidCalculate();17 //加法运算

18 voidadd(T, T);19 //减法运算

20 voidsubtraction(T, T);21 //乘法运算

22 voidmultiplication(T, T);23 //除法运算

24 voiddivide(T, T);25 //输出运算符重载

26 template friend ostream &operator< &);27 };28

29 //四则运算

30 template void ElementaryArithmetic::Calculate(){31 inttype;32

33 loop1:34 system("cls");35 cout << endl << "*******************" <>type;44 if (type != 1 && type != 2 && type != 3 && type != 4)45 throw 1;46 }47 catch (inte){48 cout << endl << "输入错误,请重新输入选项...";49 system("pause");50 gotoloop1;51 }52

53 cout << endl << "请输入两个数字:";54 cin >> operand1 >>operand2;55 if (type == 1){56 add(operand1, operand2);57 operators = '+';58 }59 else if (type == 2){60 subtraction(operand1, operand2);61 operators = '-';62 }63 else if (type == 3){64 multiplication(operand1, operand2);65 operators = '*';66 }67 else if (type == 4){68 divide(operand1, operand2);69 operators = '/';70 }71

72 }73

74 //加法运算

75 template void ElementaryArithmetic::add(T operand1,T operand2){76 result = operand1 +operand2;77 }78

79 //减法运算

80 template void ElementaryArithmetic::subtraction(T operand1, T operand2){81 result = operand1 -operand2;82 }83

84 //乘法运算

85 template void ElementaryArithmetic::multiplication(T operand1, T operand2){86 result = operand1 *operand2;87 }88

89 //除法运算

90 template void ElementaryArithmetic::divide(T operand1, T operand2){91 try{92 //除数为0,出现异常

93 if ((operand2 - 0) < 1e-8 && (operand2 - 0) > -1e-8)94 throw 0;95 }96 catch (int){97 throw;98 }99 result = operand1 /operand2;100 }101

102 //输出运算符重载

103 template ostream& operator< &result){104 os << endl << "计算结果 :" << result.operand1 << result.operators << result.operand2 << '=' << result.result <

108 //三角函数

109 classTrigonometric{110 private:111 doubleradian;112 stringtype;113 doubleresult;114 public:115 //三角函数计算

116 voidCalculate();117 //输出运算符重载

118 friend ostream &operator<

121 //三角函数计算

122 voidTrigonometric::Calculate(){123 intoption;124

125 loop2:126 system("cls");127 cout << "*******************" <>option;135 if (option != 1 && option != 2 && option != 3 && option != 4)136 throw 2;137 }138 catch (inte){139 cout << endl << "输入错误,请重新输入选项...";140 system("pause");141 gotoloop2;142 }143

144

145 cout << endl << "请输入弧度:";146 cin >>radian;147

148 if (option == 1){149 result =sin(radian);150 type = "sin";151 }152 else if (option == 2){153 result =cos(radian);154 type = "cos";155 }156 else if (option == 3){157 result =tan(radian);158 type = "tan";159 }160 }161

162 //输出运算符重载

163 ostream &operator<

168 intmain(){169 inttype;170

171 loop:172 while (true){173 system("cls");174 cout << "*******主菜单**********" <

183 try{184 cin >>type;185 if (type != 1 && type != 2 && type != 3)186 throw - 1;187

188 if (type == 1){189 ElementaryArithmeticcalc;190 calc.Calculate();191 cout <

210 }211 cout <

java三角函数计算器_c++实现简单计算器相关推荐

  1. 求java简单计算器源代码_java简单计算器源代码

    简单计算器代码 package calcultorthree; import java.awt.BorderLayout;//导入边界布局管理器类 import java.awt.GridLayout ...

  2. java做计算器_java实现简单计算器

    本文实例为大家分享了java实现简单计算器的具体代码,供大家参考,具体内容如下 思路:定义一个主框架Frame,我们对原设计的草图进行划分,以方便后面的布局 下面我们来对主框架进行划分 如图,我们将主 ...

  3. java 简单的计算器程序_java 简单计算器

    做的很简陋  慢慢学习中!!!!!! import java.awt.*; public class 计算 { public static void main(String[] args) { win ...

  4. js装修计算器java代码_JavaScript代码实现简单计算器

    本文实例为大家分享了JavaScript代码实现简单计算器的具体代码,供大家参考,具体内容如下 一.实现功能 (1)利用css样式.javascript语言和html语言实现计算器的算法 (2)对计算 ...

  5. php编写一个简单计算器程序,PHP 简单计算器代码实现

    /* * 简单计算器 */ error_reporting(E_ALL & ~E_NOTICE); if(isset($_POST['sub'])){ $a = $_POST['num1']; ...

  6. android复杂计算器代码,android简单计算器代码

    <android简单计算器代码>由会员分享,可在线阅读,更多相关<android简单计算器代码(9页珍藏版)>请在人人文库网上搜索. 1.package class Calcu ...

  7. php自定义函数计算器,PHP实现简单计算器

    PHP简单计算器 table{ border:1px solid #CC9999; width:600px; } th{ background:#CCCCCC; } td{ background:#C ...

  8. java实现计算器_Java 实现简单计算器

    最后一次更新于2019/07/08 效果演示图 功能与流程 要制作一个简易计算器,首先你要清楚GUI里要显示什么: 结果显示框 0-9的数字 删除功能 清楚功能 搜寻历史记录功能 计算结果的功能 括号 ...

  9. js 月份间隔计算器_js实现简单计算器

    参考部分资料,编写一个简单的计算器案例,虽然完成了正常需求,但是也有不满之处,待后续实力提升后再来补充,先把不足之处列出: 1:本来打算只要打开页面,计算器的输入框会显示一个默认为0的状态,但是在输入 ...

最新文章

  1. 【C++】重载运算符(一)
  2. socket.io实现在线群聊
  3. typescript接口定义
  4. 常用c语言小程序,c语言经典小程序汇总大全
  5. 2021-07-23 小记
  6. python调用扫描仪_使用Python编写简单的端口扫描器的实例分享
  7. 2017.10.10 Perm 排列计数 失败总结
  8. python如何用pip升级_手把手教你怎么用Python pip怎么升级pip?,专家详解
  9. Java、素数的个数
  10. 小米笔记本Pro14 黑苹果失败<经验>
  11. 阿里RocketMQ创始人首次分享出这份RocketMQ技术内木神级架构手册
  12. 交互式应用中的视线跟踪技术
  13. PHP遍历文件夹下的所有子文件夹及文件
  14. 笔记本电脑更改计算机驱动怎么进不去,笔记本电脑进入不了BIOS的原因与解决办法...
  15. python百度地图api经纬度_详解用Python调用百度地图正/逆地理编码API
  16. 计算机网络之简单概念
  17. Python 函数代码示例
  18. JDK的下载与安装配置教程2022最新
  19. 【科创人】瑞云创始人汪忠田:售后服务SaaS市场拓荒者
  20. 教你怎么0基础学编程

热门文章

  1. 转:3D游戏引擎技术剖析
  2. pcb设计布线工程师谈
  3. 动手学深度学习 - 11.7. d2lzh 包索引
  4. WOJ 1006-Language of Animals解题心得
  5. Docker教程:Dockerfile中sed的使用
  6. linux平铺窗口管理器,5个大的平铺窗口管理器为Linux | MOS86
  7. sonar添加(集成)阿里java代码p3c规则
  8. animate改变背景颜色_CSS 颜色体系详解,看完弄懂,直通大厂(近万字精华)
  9. 如何表达自己对计算机网络的喜欢,关于形容身边的人对自己很重要的表白心迹的爱情句子...
  10. English trip V1 - B 5.Is It Cold Outside? 外面很冷? Teacher:Corrine Key: weather