Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <iomanip>
  6. using namespace std;
  7. int main (){
  8. srand(time(NULL)); //Need this for rand #'s
  9. int rad;
  10. double bor;
  11. rad=(-1)*((rand()%11)+5);
  12. bor=(-1)*(rand()%(-1*rad));
  13. double x,y;
  14. double xint;
  15. double overhead;
  16. double launch;
  17. double crater;
  18. double a,h,k;
  19. a=(-1)*((rand()%31)+20);
  20. h=((rand()%31)-20);
  21. k=(rand()&15)+5;
  22. if (h == 0) {
  23.  
  24. h = h + .1;
  25. }
  26. cout << "GIVEN VALUES " << endl;
  27. cout<<"Radar range is "<<rad<<endl;
  28. cout<<"Our border is at "<<bor<<endl;
  29. cout<<"a= "<<a<<endl;
  30. cout<<"h= "<<h<<endl;
  31. cout<<"k= "<<k<<endl;
  32.  
  33.  
  34.  
  35. //y=((1/a)*(pow((x-h),2)+k));
  36. overhead = ((1/a)*(pow(h,2))+k);
  37. xint=sqrt((-1*k)*(a));
  38. launch=(-1*xint)+k;
  39. //overhead is y int
  40. double a1;
  41. a1 = 1/a;
  42. crater=(xint)+k;
  43. if ( h > 0) {
  44.  
  45. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a1 << "(x-" << h << ")^2 + " << k << endl;
  46. }
  47. if (h < 0) {
  48. h = h * -1;
  49. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a1 << "(x+" << h << ")^2 + " << k << endl;
  50. h = h * -1;
  51. }
  52.  
  53.  
  54.  
  55. double b ,c;
  56.  
  57. b = -((2*h)/a);
  58. c = ((h*h)/a) + k;
  59. cout << setprecision (2) << "The equation of the rocket in standard form is y = (" <<a1<< ")x^2 + " << b << "x + " << c << endl << endl << endl;
  60.  
  61. x = 1;
  62. double p1, p2, p3, p4;
  63. double n[3];
  64.  
  65. cout << "CALCULATED VALUES" << endl ;
  66. cout << "We have observed the following points that the rocket has passed through: ";
  67. cout << endl << "The first point is (0," << c << ")" ;
  68. for (int i = 0;i<3;i++)
  69. {
  70.  
  71. y=((1/a)*(pow(x,2)))+(b*x)+c;
  72.  
  73. cout << setprecision(2) << endl << "Another point is (" << x << "," << y <<")";
  74.  
  75. x = x+2;
  76. n[i] = y;
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83. double m[3] = {1 , 3, 0};
  84. double temp1, temp2, num, den;
  85.  
  86. temp1 = (n[1]-c);
  87. temp2 = (m[1]*m[1])*(n[0]-c);
  88. num = temp1 - temp2;
  89. den = (-(m[1]*m[1])+m[1]);
  90. b = num/den;
  91. a = (n[0] - c) - b;
  92. cout << endl << "a = " << a << endl;
  93. cout << "b = " << b <<endl;
  94. cout << "c = " << c <<endl;
  95. cout <<setprecision (2) << "The equation of the rocket in standard form is y = (" << a << ")x^2 + " << b << "x + " << c << endl;
  96.  
  97. h = -(b)/ (2*a);
  98.  
  99. k = (a*h*h) + (b*h) + c;
  100.  
  101.  
  102. if ( h > 0) {
  103. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a << "(x-" << h << ")^2 + " << k << endl;
  104. }
  105. if (h < 0) {
  106. h = h * -1;
  107. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a << "(x+" << h << ")^2 + " << k << endl;
  108. }
  109. if (h == 0)
  110. {
  111.  
  112. cout << endl << "The missle interception has failed. Take cover. ";
  113. return 0;
  114. }
  115.  
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement