This code would not work on mac so I could not complete assignment 1) Modify the
ID: 3903762 • Letter: T
Question
This code would not work on mac so I could not complete assignment1) Modify the code so that the variables <ang> and <v0> be introduced by the user on the keyboard. Move the code from lines 16 and 17 as a function called fEnterData(...) that will give me v0x and v0y 2) Move the code from lines 18 to 26 including, to a function called fShowInitials(...) 3) Move the code from lined 28-40 including, to a function called fComputeTrajectory(...) //code Blocks: Project Build Options Linker settings Other linker options: add -1gdi32 #4efine _WIN32_WINNT 0x0500 ?include "windows.h" /Iinclude "Wingdi.h'" #include #include #include using namespace std; #define P1 3.14 #define NMAX 1000 int main)( double G-9.81, ang#53,v0-10.v0x,rOy; //inicializar el angulo y la velocidad inicial v0xv0*cos (ang PI/180) //Velocidad inicial horizontal v0yv0 sin (ang PI/180) //velocidad inicial vertical printf ("Initial speed v0: %.2f. Angle 8.2f ",v0 ,ang); : printf ("v0x: %.2f ",vox ); printf ("vOy: %.2f ",voy); double tFinal2 voy/G; I/tiempo de la bala en el aire double yMax - voy tFinal/2-0.5*G tFinal/2*tFinal/2; printf ("tFinal : %.2f " , tFinal); double Ts-o . 1 ; int N- (int) (tFinal/Ts) printf ( "Number of measures: %d " , (N+1 ) ) ; double x[NMAX+2],y[NMAX+2,tNMAX+21; printf ("t: secs. xpos. ypos. vx. vyln") for (int n 0; n
Explanation / Answer
Answer:
Here, I have following programming code as shown below
Code:
#define _WIN32_WINNT 0x0500
#include "windows.h"
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
// set predefine values
#define PI 3.14
#define NMAX 1000
void FirstEnterData(double &ang, double &v0) {
// get user inout
printf("Enter the Angle: ");
scanf("%lf", &ang);
// get velocity
printf("Enter the Initial Velocity: ");
scanf("%lf", &v0);
}
// define a method to show
void firstShowInitials(double v0, double ang, double v0x, double v0y, double G)
{
printf ("Initial Speed v0: %.2f. Angle : %.2f ",v0,ang);
printf ("v0x: %.2f ",v0x);
printf ("v0y: %.2f ",v0y);
double tFinal = 2*v0y/G;
double yMax = v0y*tFinal/2-0.5*G*tFinal/2*tFinal/2;
printf ("tFinal: %.2f ",tFinal);
double Ts=0.1;
int N = (int)(tFinal/Ts);
printf ("Number of measures: %d ",(N+1));
}
// define a method to compute
void firstComputeTrajectory(double Ts, double tFinal, double v0x, double v0y, double G, int N, double x[], double y[], double t[]) {
printf ("t: secs. xpos. ypos. vx. vy ");
for (int n = 0; n <= N; n++) {
t[n]=n*Ts;
x[n]=v0x*t[n];
y[n]=v0y*t[n]-0.5*G*t[n]*t[n];
printf ("t%d: %.2f %.2f %.2f %.2f %.2f ",
n,t[n],x[n],y[n],v0x,v0y-G*t[n]);
}
t[N+1]=tFinal;
x[N+1]=v0x*tFinal;
y[N+1]=v0y*t[N+1]-0.5*G*t[N+1]*t[N+1];
printf ("t%d: %.2f %.2f %.2f %.2f %.2f ",
N+1,t[N+1],x[N+1],y[N+1],v0x,v0y-G*tFinal);
}
// define a method to generate graphic
void firstGenerateGraphic (int N, double x[], double y[], double t[]) {
cout << "Press twice enter to show the graph ";
cin.ignore();
system("CLS"); //to clear the screen
cin.ignore();
HWND myconsole = GetConsoleWindow();
HDC mydc = GetDC(myconsole);//hWnd
RECT rect;
COLORREF RED= RGB(255,0,0),BLUE= RGB(0,0,255), WHITE= RGB(255,255,255);
GetWindowRect(myconsole, &rect);//get console coordinates
// define a variable
int xmiddle= -200+(rect.right - rect.left) / 2;
int ymiddle= (rect.bottom - rect.top) / 2;
for(int i = 0; i < ymiddle; ++i)
SetPixel(mydc, xmiddle, i, RED);
for(int i = xmiddle; i < 2*xmiddle; ++i)
SetPixel(mydc, i,ymiddle , RED);
SetPixel(mydc, xmiddle, ymiddle, WHITE);
SetPixel(mydc, xmiddle-1, ymiddle, WHITE);
SetPixel(mydc, xmiddle+1, ymiddle, WHITE);
SetPixel(mydc, xmiddle, ymiddle-1, WHITE);
SetPixel(mydc, xmiddle, ymiddle+1, WHITE);
int pixel =0,multip=50;
double xcur,ycur;
for(int n = 0; n < N+1; n++){
xcur=(double)xmiddle+multip*x[n];
ycur= ymiddle-multip*y[n];
// create a pixel
SetPixel(mydc,(int)xcur,(int)ycur,WHITE);
SetPixel(mydc,(int)xcur-1,(int)ycur,WHITE);
SetPixel(mydc,(int)xcur+1,(int)ycur,WHITE);
SetPixel(mydc,(int)xcur,(int)ycur-1,WHITE);
SetPixel(mydc,(int)xcur,(int)ycur+1,WHITE);
//Plot each x unit in blue
SetPixel(mydc,xmiddle+multip*n,ymiddle,BLUE);
SetPixel(mydc,xmiddle+multip*n-1,ymiddle,BLUE);
SetPixel(mydc,xmiddle+multip*n+1,ymiddle,BLUE);
SetPixel(mydc,xmiddle+multip*n,ymiddle-1,BLUE);
SetPixel(mydc,xmiddle+multip*n,ymiddle+1,BLUE);
//Plot each y unit in blue if less than ymiddle
if(rect.top+multip*n<ymiddle){
SetPixel(mydc,xmiddle,rect.top+multip*n,BLUE);
SetPixel(mydc,xmiddle-1,rect.top+multip*n,BLUE);
SetPixel(mydc,xmiddle+1,rect.top+multip*n,BLUE);
SetPixel(mydc,xmiddle,rect.top+multip*n-1,BLUE);
SetPixel(mydc,xmiddle,rect.top+multip*n+1,BLUE);
}
pixel+=10;
}
ReleaseDC(myconsole, mydc);
}
int main(){
// declare the variable
double G=9.81,Angle=53,v0=10,v0x,v0y;
// assign the value
v0x = v0*cos(Tset*PI/180);
v0y = v0*sin(Tset*PI/180);
// calls the function
FirstEnterData(Tset, v0);
firstShowInitials(v0, Angle, v0x, v0y, G);
// set double value
double Final = 2*v0y/G;
double yMax = v0y*Final/2-0.5*G*Final/2*Final/2;
double Tset=0.1;
int N = (int)(Final/Tset);
double x[NMAX+2],y[NMAX+2],t[NMAX+2];
firstComputeTrajectory(Tset, Final, v0x, v0y, G, N, x, y, t);
firstGenerateGraphic(N, x, y, t);
cin.ignore();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.