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 15:27

OP here im almsot done but i need help on the last part were i need to convert the cos into degrees take a look and any help is appreciated.


/* This program compute the cos of y and the angle y of 2 given vectors*/

#include <stdio.h>
#include <math.h>

int main(void)
{
    /*Declare Variables and functions*/
    double x1,x2,y1,y2,z1,z2;
    double gamma (double vector_mag_A, double vector_mag_B, double dot_prod, double angle_cos, double degrees_Y);
   
    /*Ask user for vector A*/
    printf("Please input the first vector A:   \n \n");
    printf("Vector A X:    \n")
    scanf(" %lf", &x1);
    printf("Vector A Y:    \n")
    scanf(" %lf", &y1);
    printf("Vector A Z:    \n")
    scanf(" %lf", &z1);
   
   
     /*Ask user for vector B*/
    printf("Please input the second vector B:   \n \n");
    printf("Vector B X:    \n")
    scanf(" %lf", &x2);
    printf("Vector B Y:    \n")
    scanf(" %lf", &y2);
    printf("Vector B Z:    \n")
    scanf(" %lf", &z2);
   
    /*Print the value of angle Y*/
    printf(" The Value for degrees is - %10.3lf \n", gamma(degrees_Y));
   
    /*Exit Program*/
    return 0;
}

/*---------------------------------------------------------*/
  /*This function converts the vectors in order to make gamma into degrees*/

double gamma (double vector_mag_A, double vector_mag_B, double dot_prod, double angle_cos, double degrees_Y

{
       /*Declare Varibles*/
       double vector_mag_A, vector_mag_B, dot_prod, angle_cos, degrees_Y;
      
       /*dot product*/
       dot_prod= x1*x2 + y1*y2 + z1*z2;
      
       /*Vector magnitudes*/
       vector_mag_A= sqrt(x1*x1 + y1*y1 + z1*z1)
       vector_mag_B= sqrt(x2*x2 + y2*y2 + z2*z2)
      
       /*compute  degrees of Y*/
       angle_cos= [(dot_prod) / (vector_mag_A * vector_mag_B)]
       degrees_Y= ?
      

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