Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 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. int i = 0;
  20.  
  21. while(i == 0 )
  22. {
  23. a=(-1)*((rand()%31)+20);
  24. h=((rand()%31)-20);
  25. k=(rand()&15)+5;
  26.  
  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. if (h == 0) {
  34.  
  35. h = h + .1;
  36. }
  37.  
  38. //y=((1/a)*(pow((x-h),2)+k));
  39. overhead = ((1/a)*(pow(h,2))+k);
  40. xint=sqrt((-1*k)*(a));
  41. launch=(-1*xint)+h;
  42. crater=(xint)+h;
  43.  
  44. if(launch<=bor)
  45. {
  46. i++;
  47. }
  48. }
  49. double a1;
  50. a1 = 1/a;
  51. crater=(xint)+k;
  52. if ( h > 0) {
  53.  
  54. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a1 << "(x-" << h << ")^2 + " << k << endl;
  55. }
  56. if (h < 0) {
  57. h = h * -1;
  58. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a1 << "(x+" << h << ")^2 + " << k << endl;
  59. h = h * -1;
  60. }
  61.  
  62.  
  63.  
  64. double b ,c;
  65.  
  66. b = -((2*h)/a);
  67. c = ((h*h)/a) + k;
  68. cout << setprecision (2) << "The equation of the rocket in standard form is y = (" <<a1<< ")x^2 + " << b << "x + " << c << endl << endl << endl;
  69.  
  70. x = 1;
  71. double p1, p2, p3, p4;
  72. double n[3];
  73.  
  74. cout << "CALCULATED VALUES" << endl ;
  75. cout << "We have observed the following points that the rocket has passed through: ";
  76. cout << endl << "The first point is (0," << c << ")" ;
  77. for (int i = 0;i<3;i++)
  78. {
  79.  
  80. y=((1/a)*(pow(x,2)))+(b*x)+c;
  81.  
  82. cout << setprecision(2) << endl << "Another point is (" << x << "," << y <<")";
  83.  
  84. x = x+2;
  85. n[i] = y;
  86.  
  87. }
  88.  
  89.  
  90.  
  91.  
  92. double m[3] = {1 , 3, 0};
  93. double temp1, temp2, num, den;
  94.  
  95. temp1 = (n[1]-c);
  96. temp2 = (m[1]*m[1])*(n[0]-c);
  97. num = temp1 - temp2;
  98. den = (-(m[1]*m[1])+m[1]);
  99. b = num/den;
  100. a = (n[0] - c) - b;
  101. cout << endl << "a = " << a << endl;
  102. cout << "b = " << b <<endl;
  103. cout << "c = " << c <<endl;
  104. cout <<setprecision (2) << "The equation of the rocket in standard form is y = (" << a << ")x^2 + " << b << "x + " << c << endl;
  105.  
  106. h = -(b)/ (2*a);
  107.  
  108. k = (a*h*h) + (b*h) + c;
  109.  
  110.  
  111. if ( h > 0) {
  112. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a << "(x-" << h << ")^2 + " << k << endl;
  113. }
  114. if (h < 0) {
  115. h = h * -1;
  116. cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a << "(x+" << h << ")^2 + " << k << endl;
  117. }
  118. if (h == 0)
  119. {
  120.  
  121. cout << endl << "The missle interception has failed. Take cover. ";
  122. return 0;
  123. }
  124.  
  125. cout<<"overhead (y)= "<<overhead<<endl;
  126. cout<<"launch (x start)= "<<launch<<endl;
  127. cout<<"crater (x finish)= "<<crater<<endl;
  128. double whatis; //how far interceptor can make it
  129. double whatneedstobe; //how far rocket is from base
  130. double timeinterval = 0.001;
  131.  
  132.  
  133. for (x=rad;x<=crater;x=x+timeinterval){
  134. y=((1/a)*(pow((x-h),2))+k);
  135. whatneedstobe=sqrt((pow(x,2))+(pow(y,2)));
  136.  
  137. double xveloc, yvelocnew, yvelocold, yveloc, rocketveloc;
  138. xveloc=(pow(x-(x-timeinterval),2));
  139. yvelocnew=((1/a)*(pow((x-h),2))+k);
  140. yvelocold=((1/a)*(pow(((x-timeinterval)-h),2))+k);
  141. yveloc=(yvelocnew-yvelocold)*(yvelocnew-yvelocold);
  142. rocketveloc=sqrt(xveloc+yveloc);
  143.  
  144.  
  145. if (x>bor){
  146. double time=x+(sqrt(rad*rad));
  147. double oops = (time-(abs(rad)-abs(bor)));
  148. whatis=5*oops;
  149. //cout<<" # "<<x<<" # "<<y<<" # "<<whatneedstobe<<" # "<<whatis<<" # "<<oops<< endl;
  150. if (whatneedstobe<=whatis){
  151. cout<<endl;
  152. cout<<"Interception at ( "<<x<<", "<<y<<")"<<endl;
  153. cout<<"Interception took "<<oops<<" seconds"<<endl;
  154. return 0;}
  155. if (x==crater){
  156. cout<<"Failure"<<endl;
  157. return 0;}
  158. //cout<<"whatis = "<<whatis<<" "<<"whatneedstobe = "<<whatneedstobe<<endl;
  159.  
  160.  
  161.  
  162. }
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement