Calculating Displacement vector, velocity vector, and frames

I'm not even sure where to start, i had a horrible professor my last programming class, and i am struggling with the current one.

here is what i need to do.

You will input from the screen the 2D initial pixel point (x_i,y_i), the final pixel point (x_f,y_f), and the time t (in seconds) that it took to travel. The points will be arrays.

The output of the program will be the displacement vector, the velocity vector (in pixels per second), and the number of frames (a whole number) it took to move from (x_i,y_i) to (x_f,y_f) in the time span of t seconds. You may use that one frame is 1/30th of a second.

here is the code so far...

// Using a user specified initial point, final point, and time
// This program will calculate the displacement vector, the velocity vector
// and total number of frames it took to move from the initial, to the final point
// in the user specified time span

#include <cstdlib>
#include <iostream>


// This function g calculates the average velocity of an object in
// 2D or 3D. The initial vector, final vector, time (in seconds),
// and array size n are passed to it. Displ is the
// displacement vector
// r_i is the initial point
// r_f is the final point

void g(float r_i[], float r_f[], float t, float Displ[], float avg_vel[], int n)
{

for (int k=0; k <= n-1; k++)
{
Displ[k] = r_f[k] - r_i[k] ;
avg_vel[k] = Displ[k]/t ;
}
}

using namespace std;


int main(int argc, char *argv[])
{

// welcoming output statements

cout << "Welcome to this Calculation program\n" << endl;
cout << "This program will calculate:\n" << endl;
cout << "- Displacement \n- Average Velocity \n- Total number of frames it took from the initial to the final point \n" << endl;
cout << "Please follow the next few prompts carefully, thank you \n" << endl;


system("PAUSE");
return EXIT_SUCCESS;
}


the function in the program came from the course shell and needs to be in the program, i cant think of how to properly input information into the initial and final point arrays.

any help to get this thing started would be great, thanks.
Last edited on
closed account (D80DSL3A)
I think you are over complicating the task. Why not something simple like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main()
{		
	int xi=0, yi=0, xf=0, yf=0;
	int time=0;
	int frameRate = 30;
    
	cout << "Enter xi: ";
	cin >> xi;
	cout << "Enter yi: ";
	cin >> yi;
	cout << "Enter xf: ";
	cin >> xf;
	cout << "Enter yf: ";
	cin >> yf;
	cout << "Enter time: ";
	cin >> time;
	printf("Displacement Vector = (%d,%d)\n",xf-xi,yf-yi);
	float vx = (float)(xf-xi)/(float)(time*frameRate);
	float vy = (float)(yf-yi)/(float)(time*frameRate);
	printf("Velocity Vector = (%f,%f)\n",vx,vy);
	cout << "Number of frames = " << time*frameRate << endl;
	system("PAUSE");
	return 0;
}
i have to utilize the void function in the code somehow.
Topic archived. No new replies allowed.