in c language. finish the fillCVector function. Also, add the following function
ID: 3736566 • Letter: I
Question
in c language.
finish the fillCVector function. Also, add the following function prototypes to your header file
// adds two cartesian vectors together
// when adding cartesian vectors:
// the new x coordinate is the SUM of the individual x coordinates
// the new y coordinate is the SUM of the individual y coordinates
struct cVector addCVector( struct cVector vec1, struct cVector vec2 );
// adds two polar vectors together
// hint, it is easier to add cartesian vectors...
struct pVector addPVector( struct pVector vec1, struct pVector vec2 );
// take the DOT product of two cartesian vectors
// To get the dot product
// the new x coordinate is the PRODUCT of the individual x coordinates
// the new y coordinate is the PRODUCT of the individual y coordinates
struct cVector dotCVector( struct cVector vec1, struct cVector vec2 );
// take the DOT product of two polar vectors
// hint, it is easier to dot product cartesian vectors...
struct pVector dotPVector( struct pVector vec1, struct pVector vec2 );
Then implement these four functions.
Explanation / Answer
struct cVector addCVector( struct cvector vec1, struct cvector vec2) {
struct cvector temp;
/* adding x cordinates of two cartesian vectors */
temp.x = vec1.x + vec2.x;
/* adding ycordinates of two cartesian vectors */
temp.y = vec1.y + vec2.y;
/* returning the result */
return temp;
}
struct pvector addPVector( struct pvector vec1, struct pvector vec2) {
struct pvector temp;
/* adding x cordinates of two cartesian vectors */
temp.x = vec1.x + vec2.x;
/* adding ycordinates of two cartesian vectors */
temp.y = vec1.y + vec2.y;
/* returning the result */
return temp;
}
struct cvector dotCVector( struct cvector vec1, struct cvector vec2 ) {
struct cvector temp;
/* find the dot product of y cordinates */
temp.x = ( vec1.x ) * ( vec2.x );
/* find the dot product of y cordinates */
temp.y = ( vec1.y ) * ( vec2.y );
/* returning the result */
return temp;
}
struct pvector dotPVector( struct pvector vec1, struct pvector vec2 ) {
struct pvector temp;
/* find the dot product of y cordinates */
temp.x = ( vec1.x ) * ( vec2.x );
/* find the dot product of y cordinates */
temp.y = ( vec1.y ) * ( vec2.y );
/* returning the result */
return temp;
}
/* hope this helps */
/* if any queries please do comment */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.