Question
Create the Flowchart for this C++ code. #include stdafx.h #include windows.h //#include Wingdi.h #include #include #include using namespace std; #define PI 3.14 #define NMAX 1000
Create the Flowchart for this C++ code.
#include "stdafx.h"
#include "windows.h"
//#include "Wingdi.h"
#include
#include
#include
using namespace std;
#define PI 3.14
#define NMAX 1000
void fEnterData(double &ang, double &v0) {
printf("Enter the angle: ");
scanf_s("%lf", &ang);
printf("Enter the initial velocity: ");
scanf_s("%lf", &v0);
}
void fShowInitials(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; //tiempo de la bala en el aire
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));
}
void fComputeTrajectory(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);
system("pause");
}
void fGenerateGraphic(int N, double x[], double y[], double t[]) {
cout << "Press twice enter to show the graph ";
system("pause");
cin.ignore();
system("CLS"); //clear the screen
cin.ignore();
HWND myconsole = GetConsoleWindow();
HDC mydc = GetDC(myconsole);//hWnd
//SetWindowPos( myconsole, 0, 0, 500, 800, 600, SWP_NOMOVE | SWP_NOZORDER );
RECT rect;
COLORREF RED = RGB(255, 0, 0), BLUE = RGB(0, 0, 255), WHITE = RGB(255, 255, 255);
GetWindowRect(myconsole, &rect);//get console coordinates
//cout << "Console top coords: " << rect.left << " " < //cout << "Console bot coords: " << rect.right << " " < //MoveWindow(myconsole, 0, 0, 800, 600, TRUE); // 800 width, 600 height //GetClientRect(myconsole, &rect);//get console coordinates //cout << "Console top coords: " << rect.left << " " < //cout << "Console bot coords: " << rect.right << " " < int xmiddle = -200 + (rect.right - rect.left) / 2; int ymiddle = (rect.bottom - rect.top) / 2; for (int i = 0; i < ymiddle; ++i) //Positive y axis (starts at top) SetPixel(mydc, xmiddle, i, RED);//Plot y axis for (int i = xmiddle; i < 2 * xmiddle; ++i)//Positive x axis SetPixel(mydc, i, ymiddle, RED); //Plot x axis //Plot the (0,0) coordinate with 5 pixels to paint a bold point SetPixel(mydc, xmiddle, ymiddle, WHITE);//Plot 0,0 SetPixel(mydc, xmiddle - 1, ymiddle, WHITE);//Plot 0,0 SetPixel(mydc, xmiddle + 1, ymiddle, WHITE);//Plot 0,0 SetPixel(mydc, xmiddle, ymiddle - 1, WHITE);//Plot 0,0 SetPixel(mydc, xmiddle, ymiddle + 1, WHITE);//Plot 0,0 int pixel = 0, multip = 50; double xcur, ycur; for (int n = 0; n < N + 1; n++) { xcur = (double)xmiddle + multip*x[n];//Current x coordinate ycur = ymiddle - multip*y[n];//Current y coordinate //Plot 5 pixels per coordinate so it is bold on the screen 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 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); } //SetPixel(mydc,xmiddle,(int)ycur,BLUE); pixel += 10; } ReleaseDC(myconsole, mydc); } int main() { ////////////////////////////////////////////////// double G = 9.81, ang = 53, v0 = 10, v0x, v0y; //Inicializar el angulo y la velocidad inicial v0x = v0*cos(ang*PI / 180); //Velocidad inicial horizontal v0y = v0*sin(ang*PI / 180); //Velocidad inicial vertical fEnterData(ang, v0); fShowInitials(v0, ang, v0x, v0y, G); double tFinal = 2 * v0y / G; //tiempo de la bala en el aire double yMax = v0y*tFinal / 2 - 0.5*G*tFinal / 2 * tFinal / 2; double Ts = 0.1; int N = (int)(tFinal / Ts); double x[NMAX + 2], y[NMAX + 2], t[NMAX + 2]; fComputeTrajectory(Ts, tFinal, v0x, v0y, G, N, x, y, t); ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// fGenerateGraphic(N, x, y, t); cin.ignore(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started