Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is to be written in C programming. Im quite new to programming, so please keep it simple and do not use arrays and strings.

This is to be written in C programming. Im quite new to programming, so please keep it simple and do not use arrays and strings. Thanks
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
here is the template for 3.2:

#include

#include


// Purpose: Computes the dot product of the vectors (x1, y1, z1) and (x2, y2, z2)

// Args: float x1, float y1, float z1, float x2, float y2, float z2

// Returns: float - the dot product

float dot_product( float x1, float y1, float z1, float x2, float y2, float z2 ){

//Your code here

}



/*

* Purpose: Computes the cross product of the vectors (x1, y1, z1) and (x2, y2, z2)

* and stores the result using the pointers result_x, result_y and result_z

* Args: float x1, float y1, float z1, float x2, float y2, float z2,

* float* result_x, float* result_y, float* result_z

*/

void cross_product( float x1, float y1, float z1,

float x2, float y2, float z2,

float* result_x, float* result_y, float* result_z){

//Your code here

}



// Purpose: Computes the norm of the vector (x, y, z)

// Args: float x, float y, float z

// Returns: float - the norm

//You may want to use the sqrt() function from math.h

/otice that it is included above and instructions for use in CLion below.

float norm( float x, float y, float z ){

//Your code here

}


int main(){


float x1, y1, z1;

float x2, y2, z2;

float x3, y3, z3;


x1 = 1;

y1 = 2;

z1 = 3;


x2 = 4;

y2 = 5;

z2 = 6;


float d = dot_product(x1,y1,z1, x2,y2,z2);


cross_product(x1,y1,z1, x2,y2,z2, &x3,&y3,&z3);


float n1 = norm(x1,y1,z1);

float n2 = norm(x2,y2,z2);


printf("v1 = (%f %f %f) ", x1, y1, z1);

printf("v2 = (%f %f %f) ", x2, y2, z2);


printf("v1 (dot) v2 = %f ", d);

printf("v3 = v1 x v2 = (%f %f %f) ", x3, y3, z3);

printf("norm(v1) = %f ", n1);

printf("norm(v2) = %f ", n2);


//Since (x3, y3, z3) is the cross product of v1 and v2, it should be

//orthogonal to both v1 and v2 (so the dot product should be zero).

float d13 = dot_product(x1,y1,z1, x3,y3,z3);

float d23 = dot_product(x2,y2,z2, x3,y3,z3);


printf("v1 (dot) v3 = %f ", d13);

printf("v2 (dot) v3 = %f ", d23);


return 0;

}

image text in transcribed
Part 1 2.2 Exercise 2: Using scanf to gather multiple pieces of data from the user TODO: Define and test a function called sum_user_input which uses scanf and a while loop to read floating point values from the user until the user enters the value 0. After the value o is entered, the function returns the sum of all values entered. For example, if the user enters the sequence 6 10 1.7 1.87 0, the function should return 19.57. The function should be able to read as many values as the user can provide. 2.3 Exercise 3: Handling invalid input TODO: Using your program from Exercise 2 as a basis, write a function which reads floating point values (including the value "0", if it appears) from the user until an invalid input (such as "asdf" or "q") is encountered, then returns the sum of all values entered up until the invalid input and exits. For example, if the user enters the sequence 6 10 0 1.7 1.87 O quit, the output should be "Sum: 19.57". The program should be able to read as many values as the user can provide. Part 2 3.1 Exercise 4: Define function read_vector Complete the missing function read vector below, which takes three pointers to float values as arguments. The function should read three floating point values from the user and store the result in the destination of the three pointers. If all values can be read successfully, the function will return 1. Otherwise (if any values cannot be read), the function will return 0. When the function works correctly, running the program will prompt the user to enter two vectors and then print those vectors back out. Do not modify the main function. #include int read_vector (float* px, float* py, float* pz) { //Your code here // (Don't forget the return statement) int main() { float xl, yi, 21; float x2, y2, 22; int success; printf("Enter a vector: "); success = read_vector (&xl, &i, &zl); if (success == 0) { printf("Couldn't read the first vector, exiting... "); return 0; //Returning from main() will exit the program. printf("Enter another vector: "); success = read_vector (&x2, &y2, &z2); if (success == 0) { printf ("Couldn't read the second vector, exiting... "); return 0; printf("The first vector is: $f sf &f ", xl, yl, zl); printf("The second vector is: $f %f $f ", x2, y2, 22); return 0; 3.2 Exercise 5: Define vector helper functions TODO: Complete the dot_product, cross_product and norm functions in the program below. Do not modify the main() function. Note: Since cross_product produces a vector, it must use pointers instead of a return value. Recall: To use the function in math.h you must do the following: Include math.h file in your program (just like the stdio.h file is included to allow you to call the print function When your code is correct, the program will produce the following output. v1 = (1.000000 2.000000 3.000000) v2 = (4.000000 5.000000 6.000000) v1 (dot) v2 = 32.000000 v3 = v1 x v2 = (-3.000000 6.000000 -3.000000) norm (v1) = 3.741657 norm (v2) = 8.774964 v1 (dot) v3 = 0.000000 v2 (dot) v3 = 0.000000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

1. How might volunteering help the employer and the employee?

Answered: 1 week ago