Frooster

Scientific Calculator

May 17th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.47 KB | None | 0 0
  1. /* involves exclusively outline functions
  2. 1.Passing of values from the main function to the sub function
  3. and calling of the function
  4.  
  5. */
  6.  
  7.  
  8. #include <iostream>
  9. #include <conio.h>
  10. #include <math.h>
  11.  
  12. using namespace std;
  13. double cores (double);
  14. double res (double);
  15.  
  16. float sub(float ,float);
  17. float div(float,float);
  18. float mul(float,float);
  19. float add(float,float);
  20. float ramp(float,float);
  21. double modulus_(double);
  22. void menu();
  23.  
  24. float a,b,c,ch;
  25. int ch1;
  26.  
  27. int main()
  28. {
  29.  system("cls");
  30.  
  31.   menu();
  32.  
  33.   cin >> ch;
  34.  if (ch == 1)
  35.  {
  36.   c = mul(a, b);
  37.   cout << "the multilication result is" << c;
  38.  }
  39.  else if (ch == 2)
  40.  {
  41.   c = add(a, b);
  42.   cout << "the result is" << c;
  43.  }
  44.  else if (ch == 3)
  45.  {
  46.   c = sub(a, b);
  47.   cout << "the result is" << c;
  48.  }
  49.  else if (ch == 4)
  50.  {
  51.   c = div(a, b);
  52.   cout << "the result is " << c;
  53.  }
  54.  else if (ch == 5)
  55.  {
  56.   cout << "the power is";
  57.   c = ramp(a, b);
  58.   cout << "the result is" << c;
  59.  }
  60.  else if (ch == 6)
  61.  {
  62.   cout << "the modulus o9f the no. is" << endl;
  63.   c = modulus_(a);
  64.   cout << c;
  65.  }
  66.  else if (ch == 7)
  67.  {
  68.   cout << "the cos value is" << endl;
  69.   c = cores(a);
  70.   cout << c;
  71.  }
  72.  else if (ch == 8)
  73.  {
  74.   cout << "the sin value is" << endl;
  75.   c = res(a);
  76.   cout << c;
  77.  }
  78.  else
  79.  {
  80.   cout << "out of credentials sorry";
  81.  }
  82.  
  83.   system("pause");
  84.  
  85.   return 0;
  86. }
  87.        
  88.        
  89.            
  90. float mul(float x, float y)
  91. {
  92.  float res;
  93.  
  94.   res = x*y;
  95.  
  96.   return (res);
  97. }
  98.  
  99. float add(float x, float y)
  100. {
  101.  float res;
  102.  
  103.   res = x + y;
  104.  
  105.   return (res);
  106. }
  107.  
  108. float sub(float x, float y)
  109. {
  110.  float res;
  111.  
  112.   res = x - y;
  113.  return (res);
  114. }
  115.  
  116. float div(float x, float y)
  117. {
  118.  float res;
  119.  
  120.   res = x / y;
  121.  
  122.   return (res);
  123. }
  124.  
  125. float ramp(float x, float y)
  126. {
  127.  float i, s = 1;
  128.  for (i = 1; i <= y; i++)
  129.  {
  130.   s = s*x;
  131.  }
  132.  
  133.   return (s);
  134. }
  135.  
  136. double modulus_(double x)
  137. {
  138.  double res;
  139.  
  140.   res = fabs(x);
  141.  
  142.   return (res);
  143. }
  144. void menu()
  145. {
  146.  cout << "=======PROGRAM FOR SCIENTIFIC CALCULATOR=======" << endl;
  147.  cout << "enter the variabes" << endl;
  148.  
  149.   cout << "eneter a:" ;
  150.  
  151.   cout << "enter b: " ;
  152.  cin>>a;
  153.  cin >> b;
  154.  
  155.  
  156.  
  157.   cout << "enter the function which you want to perform" << endl;
  158.  
  159.   cout << "1.mult" << endl << "2.add" << endl << "3.sub" << endl << "4.div" << endl << "5.pow" << endl << "6.modulus" << endl;
  160.  cout << "7.cos(0,30,60,90,45,37,53)" << endl << "8.sin(0,30,45,60,90,37,53)" << endl;
  161.  
  162. }
  163.  
  164. double cores(double ang)
  165. {
  166.  double result = 0;
  167.  if (ang == 45)
  168.  {
  169.   a = b = 1;
  170.   c = a*a + b*b;
  171.   cout << "the cos value of 45 deg is" << endl;
  172.   result = (b / sqrt(c));
  173.  
  174.  
  175.   }
  176.  else if (ang == 60)
  177.  {
  178.   b = 1, c = 2;
  179.   c = 2 * b;
  180.   a = ((c*c) - (b*b));
  181.  
  182.  
  183.    cout << "the cos value is" << result;
  184.  }
  185.  else if (ang == 30)
  186.  {
  187.   b = 1, c = 2;
  188.   c = 2 * b;
  189.   a = ((c*c) - (b*b));
  190.  
  191.    result = (sqrt(a) / c);
  192.  
  193.  
  194.  
  195.   }
  196.  else if (ang == 90)
  197.  {
  198.   result = 1;
  199.  
  200.    cout << "cos value is ";
  201.  }
  202.  else if (ang == 37)
  203.  {
  204.   a = 3, b = 4;
  205.   c = ((a*a) + (b*b));
  206.   result = b / sqrt(c);
  207.  
  208.    cout << "the cos value of 37 is ";
  209.  }
  210.  else if (ang == 53)
  211.  {
  212.   a = 4, b = 3;
  213.   c = ((a*a) + (b*b));
  214.   result = a / sqrt(c);
  215.  
  216.    cout << "the cos value of 53 is ";
  217.  }
  218.  else if (ang == 0)
  219.  {
  220.   result == 1;
  221.  
  222.    cout << "the cos value is";
  223.  }
  224.  else
  225.  {
  226.   cout << "sorry out of the given credentials";
  227.  }
  228.  
  229.  
  230.  
  231.   //getch();
  232.  
  233.   return (result);
  234. }
  235.  
  236. double res(double ang)
  237. {
  238.  double result = 0;
  239.  
  240.   if (ang == 45)
  241.  {
  242.   a = b = 1;
  243.   c = a*a + b*b;
  244.   cout << "the cos value of 45 deg is" << endl;
  245.   result = (b / sqrt(c));
  246.   cout << result;
  247.  }
  248.  else if (ang == 60)
  249.  {
  250.   b = 1, c = 2;
  251.   c = 2 * b;
  252.   a = ((c*c) - (b*b));
  253.  
  254.  
  255.    result = (sqrt(a) / c);
  256.   cout << "\n" << "the sin value is" << result;
  257.  }
  258.  else if (ang == 30)
  259.  {
  260.   b = 1, c = 2;
  261.   c = 2 * b;
  262.   a = ((c*c) - (b*b));
  263.  
  264.  
  265.    result = (b / c);
  266.   cout << "\n" << "the sin value is" << result;
  267.  
  268.   }
  269.  else if (ang == 90)
  270.  {
  271.  
  272.    result = 0;
  273.   cout << "\n" << "the value of sin wll be" << result;
  274.  }
  275.  else if (ang == 37)
  276.  {
  277.   a = 3, b = 4;
  278.   c = ((a*a) + (b*b));
  279.  
  280.    result = a / sqrt(c);
  281.   cout << "\n" << "the sin value of 37 is" << result;
  282.  }
  283.  else if (ang == 53)
  284.  {
  285.   a = 4, b = 3;
  286.   c = ((a*a) + (b*b));
  287.  
  288.    result = b / sqrt(c);
  289.   cout << "\n" << "the sin value of 53 is" << result;
  290.  }
  291.  else if (ang == 0)
  292.  {
  293.  
  294.    result == 0;
  295.   cout << "\n" << "the sin value is " << result;
  296.  }
  297.  else
  298.  {
  299.   cout << "sorry out of the given credentials";
  300.  }
  301.  
  302.   //getch();
  303.  
  304.   return (result);
  305. }
Advertisement
Add Comment
Please, Sign In to add comment