Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++

Name: Anonymous 2007-10-16 13:44

Anyone feel like doing some C++ programs for me???
Itll be fun!
And you will be loved forever!

Consider two vectors A and B specified in rectangular coordinates that have their tails fixed at the origin (x, y, z) = (0, 0, 0). The cosine of the included angle  between the vectors is given by

    cos y = (A  B) / (|A| |B| )

where the “dot product” is defined as

A . B = xA xB + yA yB + zA zB

and the magnitudes of the vectors are defined as

    |A| = sqrt (xA2 + yA2 + zA2)

    |B| = sqrt (xB2 + yB2 + zB2)


Knowing the rectangular components of the vectors, we can use the above formulas to compute cos y and from it the included angle y.


For this project, write a C program that prompts the user for the two vectors and calculates the angle between them. This program should employ user-defined functions to improve its structure and readability. Specifically, the program should do the following:

1.    Prompt the user for the coordinates of the first vector one at a time.

2.    Prompt the user for the coordinates of the second vector one at a time.

3.    Calculate the angle y in degrees; define and use a function gamma for this purpose. Gamma in turn should call a function dot_prod that calculates the dot product of two vectors and a function vector_mag that calculates the magnitude of a vector.

4.    Print the value of y to the screen.

5.    Prompt the user to enter ‘c’ to continue with another pair of vectors or ‘q’ to quit.

Name: Anonymous 2007-10-16 16:16

NO WAY TO TEST IT?! WTF?! Use a fucking compiler...

sean@mars:~/Devel/misc$ gcc vector.c
vector.c: In function ‘main’:
vector.c:12: error: conflicting types for ‘gamma’
vector.c:40: error: ‘degrees_Y’ undeclared (first use in this function)
vector.c:40: error: (Each undeclared identifier is reported only once
vector.c:40: error: for each function it appears in.)
vector.c:40: error: too few arguments to function ‘gamma’
vector.c:47: error: expected ‘;’ before ‘}’ token
vector.c:52: error: expected ‘;’ before ‘return’
vector.c: In function ‘gamma’:
vector.c:63: error: ‘vector_mag_A’ redeclared as different kind of symbol
vector.c:58: error: previous definition of ‘vector_mag_A’ was here
vector.c:63: error: ‘vector_mag_B’ redeclared as different kind of symbol
vector.c:58: error: previous definition of ‘vector_mag_B’ was here
vector.c:63: error: ‘dot_prod’ redeclared as different kind of symbol
vector.c:58: error: previous definition of ‘dot_prod’ was here
vector.c:63: error: ‘angle_cos’ redeclared as different kind of symbol
vector.c:58: error: previous definition of ‘angle_cos’ was here
vector.c:63: error: ‘degrees_Y’ redeclared as different kind of symbol
vector.c:58: error: previous definition of ‘degrees_Y’ was here
vector.c:67: error: ‘x1’ undeclared (first use in this function)
vector.c:67: error: ‘x2’ undeclared (first use in this function)
vector.c:67: error: ‘y2’ undeclared (first use in this function)
vector.c:67: error: ‘z1’ undeclared (first use in this function)
vector.c:67: error: ‘z2’ undeclared (first use in this function)
vector.c:71: error: invalid operands to binary *
vector.c:76: error: subscripted value is neither array nor pointer

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List