Advertisement
Guest User

calc.cpp

a guest
Jun 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <cstdlib>
  8. #include <string.h>
  9.  
  10. using namespace std;
  11.  
  12.  
  13.    
  14.  
  15. void quad(void)
  16. {
  17.    
  18.   double a = 0, b = 0, c = 0;
  19.     clrscr();
  20.     cout<<"\xDB";
  21. cout<<" please input A\n";
  22.     cin>>a;
  23. cout<<"please input B\n";
  24.     cin>>b;
  25. cout<<"please input C\n";
  26.     cin>>c;
  27.     system("cls");
  28.     cout<<"Your equation is ("<<a<<")x^2 + ("<<b<<")x + ("<<c<<")";
  29.     cin.get();
  30.     cin.get();
  31.     clrscr();
  32. double x1=(-b + sqrt(pow(b,2) - 4*(a*c)))/(2*a);
  33. double x2=(-b - sqrt(pow(b,2) - 4*(a*c)))/(2*a);
  34.    
  35.     double d = (pow(b,2) - 4*(a*c));
  36.   if(d > 0) {
  37.        
  38.      
  39. cout<<"\nYour (X)-intercepts are : \n"<<x1<<" and "<<x2;
  40.         cin.get();
  41.        
  42.    }    
  43.   else  if(d == 0){
  44.    
  45.   cout<<"You have one (X)-intercept";
  46.         cin.get();
  47.        
  48. }
  49.   else  if (d < 0){
  50.        cout<<"You do not have an (X)-intercept";
  51.         cin.get();
  52.        
  53.     }
  54.    
  55. }
  56.  
  57.  
  58. void add (void)
  59. {
  60. double a = 0, b = 0, c = 0;
  61.     clrscr();
  62. cout<<" Please input the two numbers you would \n like to add\n input :\n ";
  63.     cin>>a;
  64.     cout<<"\n ";
  65.     cin>>b;
  66.    
  67. c = a+b;
  68.     cout<<"\n The answer is "<<c;
  69.     cin.get();
  70.     cin.get();
  71.  
  72. }
  73.  
  74. void sub (void)
  75. {
  76. double a = 0, b = 0, c = 0;
  77.     clrscr();
  78. cout<<" Please input the two numbers you would \n like to subtract\n input :\n ";
  79.     cin>>a;
  80.     cout<<"\n ";
  81.     cin>>b;
  82.    
  83. c = a-b;
  84.     cout<<"\n The answer is "<<c;
  85.     cin.get();
  86.     cin.get();
  87.  
  88. }
  89.    
  90.  
  91. void trig (void){
  92. double a = 0, b = 0, c = 0;
  93.     clrscr();
  94. cout<<"please input A";
  95.     cin>>a;
  96. cout<<"please input B";
  97.     cin>>b;
  98.  
  99.     clrscr();
  100.     c = sqrt(pow(b,2)+pow(a,2));
  101. cout<<" Your answer is "<<c;
  102.     cin.get();
  103.     cin.get();
  104. }
  105.  
  106. void perc (void)
  107. {
  108.  
  109.     double number, percent, result;
  110.     clrscr();
  111.     cout<<"please input the base number :";
  112.     cin>>number;
  113.     clrscr();
  114.     cout<<"please input your percent :";
  115.     cin>>percent;
  116.    
  117.     result = number * 100;
  118.     result = (result / 100) * percent;    
  119.     result /= 100;
  120.     cout<<"your answer is "<<result;
  121.     cin.get();
  122.     cin.get();
  123. }
  124.  
  125. void slope (void){
  126.     clrscr();
  127.     float y1, y2, m, x1, x2, b;
  128. char x, y;
  129.  
  130.  
  131. cout<<"Enter first X: ";
  132. cin>> x1;
  133. cout<<"Enter second X: ";
  134. cin>> x2;
  135. cout<<"Enter first Y: ";
  136. cin>> y1;
  137. cout<<"Enter second Y: ";
  138. cin>> y2;
  139.  
  140. m=(y2-y1)/(x2-x1);
  141. cout<<"The slope is: "<< m <<"\n";
  142. cin.get();
  143.  
  144. b=y1-(m*x1);
  145. cout<<"The y intercept is: "<< b <<"\n";
  146. cout<<"The line equation is: "<< "y="<<m<<"x+"<<"("<<b<<")"<<"\n";
  147. cin.ignore();
  148. cin.get();
  149. }
  150.  
  151. void prime (void){
  152.  int i, n;
  153.  cout <<" enter a possitive integer";
  154.  cin>>n;
  155.  for(i = 2; i <= n / 2; i++)
  156.  {
  157.     if(n % i == 1)
  158.     {
  159.        
  160.         cout<<n;
  161.         cin.get();
  162.        
  163.     }
  164.  }
  165. }
  166.  
  167. int main(){
  168.  
  169.    for(;;)
  170. {
  171.       clrscr();
  172. cout<<" Please select what type of function \n you would like to use.\n 'q' - Quadratic Formula\n 'a' - Addition\n 's' - Subtraction\n 'p' - Percent\n 't' - Pythagorean theorem\n 'f' - Slope of a line\n Input :";
  173.         char q;
  174.         cin>>q;
  175.         switch(q){
  176.            
  177. case 'q' :
  178.    quad();
  179.             break;
  180.             break;
  181. case 'a' :
  182.    add();
  183.             break;
  184.             break;
  185. case 's' :
  186.    sub();
  187.             break;
  188.             break;
  189. case 't' :
  190.    trig();
  191.             break;
  192.             break;
  193. case 'p' :
  194.    perc();
  195.             break;
  196.             break;
  197. case 'f' :
  198.    slope();
  199.             break;
  200. case 'r' :
  201.     prime();
  202.             break;
  203. default :
  204.             clrscr();
  205.            
  206.         }
  207.     }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement