Advertisement
Guest User

nadav

a guest
Mar 28th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5.  
  6. double a,b,c,d,f,imax,imin;
  7. cout<< "y(x) = a + b*x + c*x^2 + d*x^3"<<endl;
  8. cout<< "Select a:"<<endl;
  9. cin>>a;
  10. cout<< "Select b:"<<endl;
  11. cin>>b;
  12. cout<< "Select c:"<<endl;
  13. cin>>c;
  14. cout<< "Select d:"<<endl;
  15. cin>>d;
  16.  
  17. if(a<0)
  18. cout<<"y(x) = ("<<a<<")"; //i check if the nubmer is //
  19. else cout<<"y(x) = "<<a;
  20.  
  21. if(b<0)
  22. cout<<" + ("<<b<<")*x";
  23. else cout<<" + "<<b<<"*x";
  24.  
  25. if(c<0)
  26. cout<<" + ("<<c<<")*x^2" ;
  27. else cout<<" + "<<b<<"*x";
  28.  
  29. if(d<0)
  30. cout<<" + ("<<d<<")*x^3"<<endl;
  31. else cout<<" + "<<d<<"*x^3"<<endl;
  32. cout<<endl;
  33.  
  34. for (int i=10;i>=-10;i--) // it is the Y for the grafh
  35. {
  36. // //
  37. imax=i-0.5;
  38. imin=i+0.5;
  39.  
  40. for(int j=-35;j<=35;j++) // it is the X for the grafh
  41. {
  42.  
  43. f= a+b*j+c*j*j+d*j*j*j;
  44.  
  45. if(f>=imax&&f<=imin)
  46. cout<<"*";
  47.  
  48. else if( (i==0) && (j==0) && (!(f>=imin-0.5&&f<=imax+0.5)) )
  49. cout<<"+";
  50.  
  51. else if(j==0&&!(f>=imin-0.5&&f<=imax+0.5))
  52. cout<<"|";
  53.  
  54. else if(i==0&&!(f>=imin-0.5&&f<=imax+0.5))
  55. cout<<"-";
  56.  
  57. else
  58. cout<<" ";
  59.  
  60. }
  61. cout<<endl;
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement