Advertisement
MDell95

calculatortxt

Jul 22nd, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. //calculator
  2.  
  3. #include <iostream>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. float addition (float a);
  9. float subtraction (float a, float b);
  10. float multiplication (float a);
  11. float division (float a, float b);
  12. float power (float a, float b);
  13. float radix (float a, float b);
  14. float sincostan (float a);
  15. float log (float a);
  16. float pythagorasc (float a, float b);
  17. float pythagorasb (float a, float c);
  18. float arcsincostan (float a);
  19. float quadrateq (float a, float b,float c, float x);
  20. float percentage (float a, float b);
  21. float systems2 (float a, float b, float c, float d, float e, float f, float x, float y);
  22.  
  23. int main(int x, float a, float b, float c, float d, float e, float f, float y, int p)
  24. {
  25. loop:
  26. cout << endl;
  27. cout << "D-CALC (powered by D-CODES) V 1.1" << endl;
  28. cout << endl;
  29. cout << "1 for addition" << endl;
  30. cout << "2 for subtraction" << endl;
  31. cout << "3 for multiplication" << endl;
  32. cout << "4 for division" << endl;
  33. cout << "5 for power" << endl;
  34. cout << "6 for root" << endl;
  35. cout << "7 for sin/cos/tan" << endl;
  36. cout << "8 for logarythmus" << endl;
  37. cout << "9 for pythagoras: hypotenuse unknown" << endl;
  38. cout << "10 for pythagoras: leg unknown" << endl;
  39. cout << "11 for arcsin/-cos/-tan" << endl;
  40. cout << "12 for quadratic equation" << endl;
  41. cout << "13 for percentage" << endl;
  42. cout << "14 for quadratic systems" << endl;
  43. cout << endl;
  44. cout << "Select an operation: ";
  45. cin >> x;
  46. cout << endl;
  47. if (x==1)
  48. addition (a);
  49. else if (x==2)
  50. subtraction (a, b);
  51. else if (x==3)
  52. multiplication (a);
  53. else if (x==4)
  54. division (a, b);
  55. else if (x==5)
  56. power (a, b);
  57. else if (x==6)
  58. radix (a, b);
  59. else if (x==7)
  60. sincostan (a);
  61. else if (x==8)
  62. log (a);
  63. else if (x==9)
  64. pythagorasc (a, b);
  65. else if (x==10)
  66. pythagorasb (a, c);
  67. else if (x==11)
  68. arcsincostan (a);
  69. else if (x==12)
  70. quadrateq (a, b, c, x);
  71. else if (x==13)
  72. percentage (a, b);
  73. else if (x==14)
  74. systems2 (a, b, c, d, e, f, x, y);
  75. cout << endl;
  76. cout << "Thank's for using D-CODES software";
  77. cout << endl;
  78. cout << endl;
  79. cout << "Enter 1 to repeat / 0 to finish: ";
  80. cin >> p;
  81. if (p==1)
  82. {
  83. goto loop;
  84. }
  85.  
  86.  
  87. return 0;
  88. }
  89.  
  90. float addition (float a)
  91. {
  92. for (;a>0;)
  93. {
  94. float b;
  95.  
  96. cout << "Enter addend (0 for sum): ";
  97. cin >> a;
  98. b+=a;
  99.  
  100. if (a==0)
  101. {
  102. cout << endl;
  103. cout << "The sum of the entered numbers is: " << b << endl;
  104. }
  105. }
  106. }
  107.  
  108. float subtraction (float a, float b)
  109. {
  110. float c;
  111.  
  112. cout << "Enter subtrahend: ";
  113. cin >> a;
  114. cout << "Enter minuend (press 0 for difference): ";
  115. cin >> b;
  116. c=a-b;
  117.  
  118. for (;a>0;)
  119. {
  120.  
  121. cout << "Enter minuend (press 0 for difference): ";
  122. cin >> b;
  123. c-=b;
  124.  
  125. if (b==0)
  126. {
  127. cout << endl;
  128. cout << "The difference of the entered numbers is: " << c << endl;
  129. break;
  130. }
  131. }
  132.  
  133. }
  134.  
  135. float multiplication (float a)
  136. {
  137. float b;
  138.  
  139. cout << "Enter factor (press 1 for product): ";
  140. cin >> a;
  141. cout << "Enter factor (press 1 for product): ";
  142. cin >> b;
  143. b=a*b;
  144.  
  145. for (;a>0;)
  146. {
  147. cout << "Enter factor (press 1 for product): ";
  148. cin >> a;
  149. b*=a;
  150.  
  151. if (a==1)
  152. {
  153. cout << endl;
  154. cout << "The product of the entered numbers is: " << b << endl;
  155. break;
  156. }
  157. }
  158. }
  159.  
  160. float division (float a, float b)
  161. {
  162. float c;
  163.  
  164. cout << "Enter dividend: ";
  165. cin >> a;
  166. cout << "Enter divisor (press 1 for difference): ";
  167. cin >> b;
  168. c=a/b;
  169.  
  170. for (;a>0;)
  171. {
  172.  
  173. cout << "Enter divisor (press 1 for difference): ";
  174. cin >> b;
  175. c/=b;
  176.  
  177. if (b==1)
  178. {
  179. cout << endl;
  180. cout << "The quotient of the entered numbers is: " << c << endl;
  181. break;
  182. }
  183. }
  184.  
  185. }
  186.  
  187. float power (float a, float b)
  188. {
  189. cout << "Enter base: ";
  190. cin >> a;
  191. cout << "Enter exponent: ";
  192. cin >> b;
  193. cout << a << "^" << b << " = " << pow(a,b) << endl;
  194. }
  195.  
  196. float radix (float a, float b)
  197. {
  198. cout << "Enter radicand: ";
  199. cin >> a;
  200. cout << "Enter order: ";
  201. cin >> b;
  202. cout << b << "^sqrt(" << a << ") = " << pow(a,(1/b)) << endl;
  203. }
  204.  
  205. float sincostan (float a)
  206. {
  207. cout << "Enter a number: ";
  208. cin >> a;
  209. cout << "sin(" << a << ") = "<< sin(a) << endl;
  210. cout << "cos(" << a << ") = "<< cos(a) << endl;
  211. cout << "tan(" << a << ") = "<< tan(a) << endl;
  212. }
  213.  
  214. float log (float a)
  215. {
  216. cout << "Enter a number: ";
  217. cin >> a;
  218. cout << "log10(" << a << ") = " << log10(a) << endl;
  219. }
  220.  
  221. float pythagorasc (float a, float b)
  222. {
  223. cout << "Enter first leg: ";
  224. cin >> a;
  225. cout << "Enter second leg: ";
  226. cin >> b;
  227. cout << "sqrt( " << a << "^2 + " << b << "^2 ) = " << sqrt((pow(a,2))+(pow(b,2))) << endl;
  228. }
  229.  
  230. float pythagorasb (float a, float c)
  231. {
  232. cout << "Enter leg: ";
  233. cin >> a;
  234. cout << "Enter hypotenuse: ";
  235. cin >> c;
  236. cout << "sqrt( " << a << "^2 - " << c << "^2 ) = " << sqrt((pow(a,2))-(pow(c,2))) << endl;
  237. }
  238.  
  239. float arcsincostan (float a)
  240. {
  241. cout << "Enter a number: ";
  242. cin >> a;
  243. cout << "arcsin(" << a << ") = "<< asin(a) << endl;
  244. cout << "arccos(" << a << ") = "<< acos(a) << endl;
  245. cout << "arctan(" << a << ") = "<< atan(a) << endl;
  246. }
  247.  
  248. float quadrateq (float a, float b,float c, float x)
  249. {
  250. cout << "Enter coefficient (a) of x^2: ";
  251. cin >> a;
  252. cout << "Enter coefficient (b) of x: ";
  253. cin >> b;
  254. cout << "Enter constant (c): ";
  255. cin >> c;
  256. cout << "x1 = (" << b << " + sqrt(" << b << "^2 - 4*" << a << "*" << c <<"))/( 2*" << a << ") = " << (b+sqrt(pow(b,2)-4*a*c))/(2*a) << endl;
  257. cout << "x2 = (" << b << " - sqrt(" << b << "^2 - 4*" << a << "*" << c <<"))/( 2*" << a << ") = " << (b-sqrt(pow(b,2)-4*a*c))/(2*a) << endl;
  258. }
  259.  
  260. float percentage (float a, float b)
  261. {
  262. cout << "Enter a number: ";
  263. cin >> a;
  264. cout << "Enter the percentage: ";
  265. cin >> b;
  266. cout << b << "% of " << a << " is: " << a*(b/100) << endl;
  267. }
  268.  
  269. float systems2 (float a, float b, float c, float d, float e, float f, float x, float y)
  270. {
  271. cout << "Enter coefficient (a) of x: ";
  272. cin >> a;
  273. cout << "Enter coefficient (b) of y: ";
  274. cin >> b;
  275. cout << "Enter constant (c): ";
  276. cin >> c;
  277. cout << a << "*x + " << b << "*y = " << c << endl;
  278. cout << "Enter coefficient (d) of x: ";
  279. cin >> d;
  280. cout << "Enter coefficient (e) of y: ";
  281. cin >> e;
  282. cout << "Enter constant (f): ";
  283. cin >> f;
  284. cout << d << "*x + " << e << "*y = " << f << endl;
  285. cout << "x is: " << ((b*f)-(e*c))/((b*d)-(a*e)) << endl;
  286. cout << "y is: " << (c-(a*x))/b << endl;
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement