Guest User

Untitled

a guest
Jul 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. #include <iostream>
  2. #include<cmath>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. #define PI 3.14159265
  8.  
  9. class calculator{
  10. double num1, num2;
  11. public:
  12. int factorial(int x){
  13. int m = 1;
  14. for(int i = x; i > 0; i--){
  15. m = m * i;
  16. }
  17. return m;
  18. }
  19. double summation(double x, double y){
  20. return x+y;
  21. }
  22. double substraction(double x, double y){
  23. return x-y;
  24. }
  25. double multiplication(double x, double y){
  26. return x*y;
  27. }
  28. double divition(double x, double y){
  29. return x/y;
  30. }
  31. double power(double x, double y){
  32. return pow(x,y);
  33. }
  34. int modulas(int x, int y){
  35. return (x%y);
  36. }
  37. double SIN(double x){
  38. return sin(x*PI/180); // converted to degree
  39. }
  40. double COS(double x){
  41. return cos(x*PI/180); // converted to degree
  42. }
  43. double TAN(double x){
  44. return tan(x*PI/180); // converted to degree
  45. }
  46.  
  47. //inverse functions begin here........
  48.  
  49. double ASIN(double x){
  50. return asin(x)* 180 / PI; // converted to degree
  51. }
  52. double ACOS(double x){
  53. return acos(x)* 180 / PI; // converted to degree
  54. }
  55. double ATAN(double x){
  56. return atan(x)* 180 / PI; // converted to degree
  57. }
  58. };
  59.  
  60. int main()
  61. {
  62. calculator c;
  63. int c1, c2;
  64. double a,b,p;
  65. char op;
  66. string t;
  67.  
  68. cout<<" Follow the instruction"<<endl;
  69. cout << "------------------------------------------------------------------------------------------------------------"<<endl;
  70. cout << "|----------------------------------------------------------------------------------------------------------|"<<endl;
  71. cout<<"|| For algebra -- press 0 |";cout<<" For tangent -- press 1 |";cout<<" For inverse tangent -- press 2 ||"<<endl;
  72. cout<<"||# For SUMMATION -- press (a+b) |";cout<<"# For sin(a) -- press (asin)|";cout<<"# For sin inverse (a) -- press (a sini)||"<<endl;
  73. cout<<"||# For SUBSTRACTION -- press (a-b) |";cout<<"# For cos(a) -- press (acos)|";cout<<"# For cos inverse (a) -- press (a cosi)||"<<endl;
  74. cout<<"||# For MULTIPLICATION -- press (a*b)|";cout<<"# For tan(a) -- press (atan)|";cout<<"# For tan inverse (a) -- press (a tani)||"<<endl;
  75. cout<<"||# For DIVITION -- press (a/b) |";cout<<" |";cout<<" ||"<<endl;
  76. cout<<"||# For square -- press (a^b) |";cout<<" |";cout<<" ||"<<endl;
  77. cout<<"||# For modulas -- press (a%b) |";cout<<" |";cout<<" ||"<<endl;
  78. cout << "|----------------------------------------------------------------------------------------------------------|"<<endl;
  79. cout << "------------------------------------------------------------------------------------------------------------"<<endl;
  80. start:
  81. cout<<"Enter Your choice: ";
  82. cin >> c1;
  83. if(c1 == 0){
  84. goto first;
  85. }
  86. else if(c1 == 1){
  87. goto second;
  88. }
  89. else if(c1 == 2){
  90. goto third;
  91. }
  92. else{
  93. goto end;
  94. }
  95.  
  96. first: //first starts here
  97. cin >> a;
  98. first_reused:
  99. cin >> op;
  100. if(op == '!'){
  101. p = c.factorial(a);
  102. cout << "= "<< p << endl;
  103. }
  104. else if(op == '+'){
  105. cin >> b;
  106. p = c.summation(a,b);
  107. cout << "="<< p << endl;
  108. }
  109. else if(op == '-'){
  110. cin >> b;
  111. p = c.substraction(a,b);
  112. cout << "= "<< p << endl;
  113. }
  114. else if(op == '*'){
  115. cin >> b;
  116. p = c.multiplication(a,b);
  117. cout << "= "<< p << endl;
  118. }
  119. else if(op == '/'){
  120. cin >> b;
  121. p = c.divition(a,b);
  122. cout << "= "<< p << endl;
  123. }
  124. else if(op == '^'){
  125. cin >> b;
  126. p = c.power(a,b);
  127. cout << "= "<< p << endl;
  128. }
  129. else if(op == '%'){
  130. cin >> b;
  131. p = c.modulas(a,b);
  132. cout << "= "<< p << endl;
  133. }
  134. cout<<endl<<"To continue algebra -- press 0"<<endl;
  135. cout<<"To continue tangent -- press 1"<<endl;
  136. cout<<"To continue inverse tangent -- press 2"<<endl;
  137. cout<<"To start new -- press 3"<<endl;
  138. cout<<"To quit -- press 4"<<endl;
  139.  
  140. cin>> c2;
  141. if(c2 == 0){
  142. a = p;
  143. cout << "Ans ";
  144. goto first_reused;
  145. }
  146. else if(c2 == 1){
  147. a = p;
  148. cout << "Ans ";
  149. goto second_reused;
  150. }
  151. else if(c2 == 2){
  152. a = p;
  153. cout << "Ans ";
  154. goto third_reused;
  155. }
  156. else if(c2 == 3){
  157. p = 0;
  158. goto start;
  159. }
  160. else {
  161. p = 0;
  162. goto end;
  163. }
  164. second: //Second starts here
  165. cin >> a;
  166. second_reused:
  167. cin >> t;
  168. if(t == "sin"){
  169. p = c.SIN(a);
  170. cout << "= "<< p << endl;
  171. }
  172. else if(t == "cos"){
  173. p = c.COS(a);
  174. cout << "= "<< p << endl;
  175. }
  176. else if(t == "tan"){
  177. p = c.TAN(a);
  178. cout << "= "<< p << endl;
  179. }
  180.  
  181. cout<<endl<<"To continue algebra -- press 0"<<endl;
  182. cout<<"To continue tangent -- press 1"<<endl;
  183. cout<<"To continue inverse tangent -- press 2"<<endl;
  184. cout<<"To start new -- press 3"<<endl;
  185. cout<<"To quit -- press 4"<<endl;
  186.  
  187. cin>> c2;
  188. if(c2 == 0){
  189. a = p;
  190. cout << "Ans ";
  191. goto first_reused;
  192. }
  193. else if(c2 == 1){
  194. a = p;
  195. cout << "Ans ";
  196. goto second_reused;
  197. }
  198. else if(c2 == 2){
  199. a = p;
  200. cout << "Ans ";
  201. goto third_reused;
  202. }
  203. else if(c2 == 3){
  204. p = 0;
  205. goto start;
  206. }
  207. else {
  208. p = 0;
  209. goto end;
  210. }
  211. //Third starts here
  212.  
  213. third:
  214. cin >> a;
  215. third_reused:
  216. cin >> t;
  217. if(t == "sini"){
  218. p = c.ASIN(a);
  219. cout << "= "<< p << endl;
  220. }
  221. else if(t == "cosi"){
  222. p = c.ACOS(a);
  223. cout << "= "<< p << endl;
  224. }
  225. else if(t == "tani"){
  226. p = c.ATAN(a);
  227. cout << "= "<< p << endl;
  228. }
  229. cout<<endl<<"To continue algebra -- press 0"<<endl; //change these lines into cout
  230. cout<<"To continue tangent -- press 1"<<endl;
  231. cout<<"To continue inverse tangent -- press 2"<<endl;
  232. cout<<"To start new -- press 3"<<endl;
  233. cout<<"To quit -- press 4"<<endl;
  234.  
  235. cin>> c2;
  236. if(c2 == 0){
  237. a = p;
  238. cout << "Ans ";
  239. goto first_reused;
  240. }
  241. else if(c2 == 1){
  242. a = p;
  243. cout << "Ans ";
  244. goto second_reused;
  245. }
  246. else if(c2 == 2){
  247. a = p;
  248. cout << "Ans ";
  249. goto third_reused;
  250. }
  251. else if(c2 == 3){
  252. p = 0;
  253. goto start;
  254. }
  255. else {
  256. p = 0;
  257. goto end;
  258. }
  259. end:
  260. cout <<endl<< "Thanks For Using! " << endl;
  261. return 0;
  262. }
Add Comment
Please, Sign In to add comment