Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main (){
- srand(time(NULL)); //Need this for rand #'s
- int rad;
- double bor;
- rad=(-1)*((rand()%11)+5);
- bor=(-1)*(rand()%(-1*rad));
- double x,y;
- double xint;
- double overhead;
- double launch;
- double crater;
- double a,h,k;
- int i = 0;
- while(i == 0 )
- {
- a=(-1)*((rand()%31)+20);
- h=((rand()%31)-20);
- k=(rand()&15)+5;
- cout<<"Radar range is "<<rad<<endl;
- cout<<"Our border is at "<<bor<<endl;
- cout<<"a= "<<a<<endl;
- cout<<"h= "<<h<<endl;
- cout<<"k= "<<k<<endl;
- if (h == 0) {
- h = h + .1;
- }
- //y=((1/a)*(pow((x-h),2)+k));
- overhead = ((1/a)*(pow(h,2))+k);
- xint=sqrt((-1*k)*(a));
- launch=(-1*xint)+h;
- crater=(xint)+h;
- if(launch<=bor)
- {
- i++;
- }
- }
- double a1;
- a1 = 1/a;
- crater=(xint)+k;
- if ( h > 0) {
- cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a1 << "(x-" << h << ")^2 + " << k << endl;
- }
- if (h < 0) {
- h = h * -1;
- cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a1 << "(x+" << h << ")^2 + " << k << endl;
- h = h * -1;
- }
- double b ,c;
- b = -((2*h)/a);
- c = ((h*h)/a) + k;
- cout << setprecision (2) << "The equation of the rocket in standard form is y = (" <<a1<< ")x^2 + " << b << "x + " << c << endl << endl << endl;
- x = 1;
- double p1, p2, p3, p4;
- double n[3];
- cout << "CALCULATED VALUES" << endl ;
- cout << "We have observed the following points that the rocket has passed through: ";
- cout << endl << "The first point is (0," << c << ")" ;
- for (int i = 0;i<3;i++)
- {
- y=((1/a)*(pow(x,2)))+(b*x)+c;
- cout << setprecision(2) << endl << "Another point is (" << x << "," << y <<")";
- x = x+2;
- n[i] = y;
- }
- double m[3] = {1 , 3, 0};
- double temp1, temp2, num, den;
- temp1 = (n[1]-c);
- temp2 = (m[1]*m[1])*(n[0]-c);
- num = temp1 - temp2;
- den = (-(m[1]*m[1])+m[1]);
- b = num/den;
- a = (n[0] - c) - b;
- cout << endl << "a = " << a << endl;
- cout << "b = " << b <<endl;
- cout << "c = " << c <<endl;
- cout <<setprecision (2) << "The equation of the rocket in standard form is y = (" << a << ")x^2 + " << b << "x + " << c << endl;
- h = -(b)/ (2*a);
- k = (a*h*h) + (b*h) + c;
- if ( h > 0) {
- cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a << "(x-" << h << ")^2 + " << k << endl;
- }
- if (h < 0) {
- h = h * -1;
- cout <<setprecision (2) << "The equation of the rocket in vertex form is y = " << a << "(x+" << h << ")^2 + " << k << endl;
- }
- if (h == 0)
- {
- cout << endl << "The missle interception has failed. Take cover. ";
- return 0;
- }
- cout<<"overhead (y)= "<<overhead<<endl;
- cout<<"launch (x start)= "<<launch<<endl;
- cout<<"crater (x finish)= "<<crater<<endl;
- double whatis; //how far interceptor can make it
- double whatneedstobe; //how far rocket is from base
- double timeinterval = 0.001;
- for (x=rad;x<=crater;x=x+timeinterval){
- y=((1/a)*(pow((x-h),2))+k);
- whatneedstobe=sqrt((pow(x,2))+(pow(y,2)));
- double xveloc, yvelocnew, yvelocold, yveloc, rocketveloc;
- xveloc=(pow(x-(x-timeinterval),2));
- yvelocnew=((1/a)*(pow((x-h),2))+k);
- yvelocold=((1/a)*(pow(((x-timeinterval)-h),2))+k);
- yveloc=(yvelocnew-yvelocold)*(yvelocnew-yvelocold);
- rocketveloc=sqrt(xveloc+yveloc);
- if (x>bor){
- double time=x+(sqrt(rad*rad));
- double oops = (time-(abs(rad)-abs(bor)));
- whatis=5*oops;
- //cout<<" # "<<x<<" # "<<y<<" # "<<whatneedstobe<<" # "<<whatis<<" # "<<oops<< endl;
- if (whatneedstobe<=whatis){
- cout<<endl;
- cout<<"Interception at ( "<<x<<", "<<y<<")"<<endl;
- cout<<"Interception took "<<oops<<" seconds"<<endl;
- return 0;}
- if (x==crater){
- cout<<"Failure"<<endl;
- return 0;}
- //cout<<"whatis = "<<whatis<<" "<<"whatneedstobe = "<<whatneedstobe<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement