23.1.23011000. 20 loptica ispaljuje se horizontalno jedna za drugom. Putanja i domet loptice zavise od početne visine i brzine koje se računaju f-jom za slučajne brojeve.
Opis rješenja:
Listing programa:
/* 23011000 20 loptica ispaljuje se horizontalno jedna za drugom. Putanja i domet loptice zavise od početne visine i brzine koje se računaju f-jom za slučajne brojeve*/
#include <cstdlib>
#include <iostream>
#include <winbgim.h>
#include <cmath>
using namespace std;
int main()
{ int gdriver=6; int gmode=2; char buffer [33];
initgraph(&gdriver,&gmode,"");
setbkcolor(BLUE); setcolor(WHITE);
cleardevice();
srand(time(NULL));rand();
int krug[2][50];
for (int i=0; i < 20;i++) {krug[0][i]=120+i*40; krug[1][i]=24;}
int kr(0);
float x(20), y0(50), v0(5), g(9.81), y, tn, el(.85), xp, kos, sin, px, py;
for (int pon=0; pon < 20;pon++)
{y0 = 50+400*rand()/RAND_MAX; v0 = 2+10*rand()/RAND_MAX;
line(0,620,1024,620);
for (float t=0; t < 200;t=t+.05)
{x=v0*t; y=y0+g*t*t/2;
if (y>600) {tn=t-.05;break;}
setcolor(BLUE);circle((int)px,(int)py,20);
setcolor(WHITE);
outtextxy (10,50,"Loptica:"); outtextxy(krug[0][kr]-10,50,itoa(kr+1,buffer,10));
outtextxy (10,70,"Visina:"); outtextxy(krug[0][kr]-10,70,itoa((int)(600-y0),buffer,10));
outtextxy (10,90,"Brzina:"); outtextxy(krug[0][kr]-10,90,itoa((int)v0,buffer,10));
outtextxy (10,110,"Elastičnost sudara: "); outtextxy(200,110,itoa((int)(el*100),buffer,10));
circle((int)x,(int)y,20);putpixel(int(x), int(y),RED);
px=x;py=y;for (int i=1;i < 3700000;i++);
}
kos=x/sqrt(x*x+(600-y0)*(600-y0));
sin=(600-y0)/sqrt(x*x+(600-y0)*(600-y0));
v0=sqrt(v0*v0+g*g*tn*tn);
for(int i=1;i < 30;i++)
{
v0=v0*el;
xp=x;line(0,620,1024,620);
for (float t=.01; t < 20;t=t+.05)
{x=xp+v0*t*kos; y=600 - v0*t*sin +g*t*t/2;
setcolor(BLUE);circle((int)px,(int)py,20);
setcolor(WHITE);
if (y > 600) {tn=t-.01;break;}
circle((int)x,(int)y,20); putpixel(int(x), int(y),RED);
px=x;py=y;for (int i=1;i < 3700000;i++);
for (int i=0;i < 20;i++) circle(krug[0][i],krug[1][i],20);
}
}
circle((int)x,(int)y,20);
krug[0][kr] = (int)x; krug[1][kr] = (int)y; kr++;
outtextxy ((int)x-10,635,itoa(kr,buffer,10));
line(0,620,1024,620);
}
getch();
closegraph();
return EXIT_SUCCESS;
}
Ispis na ekranu:
Riješeni zadaci Index
|
|