Difference between revisions of "C++:3D Exercises"

From Progzoo
Jump to: navigation, search
Line 1: Line 1:
 +
<question>
 +
Calculate the dot product of two vectors.
 +
Fill in the details in the function '''dotproduct'''
 +
 +
Wikipedia includes a good article on dot products.
 +
http://en.wikipedia.org/wiki/Dot_product#Definition
 +
<prog><![CDATA[
 +
#include <math.h>
 +
#include <iostream>
 +
using namespace std;
 +
 +
float dotproduct(float a[3], float b[3]){
 +
  float r = 0; // Your code goes here
 +
  return r;
 +
}
 +
 +
int main(int argc, char **argv)
 +
{
 +
  float A[]={1,0,1};
 +
  float B[]={1,1,2};
 +
  float d = dorproduct(A,B);
 +
  cout << d<< endl;
 +
  return 0;
 +
}
 +
]]></prog>
 +
 +
<answer><![CDATA[
 +
#include <math.h>
 +
#include <iostream>
 +
using namespace std;
 +
 +
float dorproduct(float a[3], float b[3]){
 +
  float r = a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
 +
  return r;
 +
}
 +
 +
int main(int argc, char **argv)
 +
{
 +
  float A[]={1,0,1};
 +
  float B[]={1,1,2};
 +
  float d = dorproduct(A,B);
 +
  cout << d<< endl;
 +
  return 0;
 +
}
 +
]]></answer>
 +
</question>
 +
 
<question>
 
<question>
 
Calculate the cross product of two vectors.
 
Calculate the cross product of two vectors.

Revision as of 08:30, 23 November 2011

Calculate the dot product of two vectors. Fill in the details in the function dotproduct

Wikipedia includes a good article on dot products. http://en.wikipedia.org/wiki/Dot_product#Definition



[Font] [Default] [Show] [Resize] [History] [Profile]

Calculate the cross product of two vectors. Fill in the details in the function crossproduct

Wikipedia includes a good article on cross products. http://en.wikipedia.org/wiki/Cross_product#Coordinate_notation



[Font] [Default] [Show] [Resize] [History] [Profile]