在C++程序中怎样编写两个向量的内积与外积(成员函数)

作者&投稿:玉吴 (若有异议请与网页底部的电邮联系)
在C++程序中怎样编写两个向量的内积与外积(~

示例:
class Vector
{
public:
Vector(double cx, double cy, double cz) : x(cz), y(cy), z(cz){}
Vector OuterProduct(const Vector & v)
{
double nx = y * v.z - z * v.y;
double ny = z * v.x - x * v.z;
double nz = x * v.y - y * v.x;
return Vector(nx, ny, nz);
}
double InnerProduct(const Vector & v)
{
return x * v.x + y * v.y + z * v.z;
}
private:
double x;
double y;
dobule z;
};

如:
class Vector
{
public:
Vector(double cx, double cy, double cz) : x(cz), y(cy), z(cz){}
Vector OuterProduct(const Vector & v)

如:
class Vector
{
public:
Vector(double cx, double cy, double cz) : x(cz), y(cy), z(cz){}
Vector OuterProduct(const Vector & v)
{
double nx = y * v.z - z * v.y;
double ny = z * v.x - x * v.z;
double nz = x * v.y - y * v.x;
return Vector(nx, ny, nz);
}
double InnerProduct(const Vector & v)
{
return x * v.x + y * v.y + z * v.z;
}

private:
double x;
double y;
dobule z;
};

CrossMutiplier();
不过这是DirectX里的,不是C++里的,呵呵自己研究一下3D几何吧.


用c++编写程序
include <iostream> using namespace std;class student { private:class node { public:int num;int grade;node* next;node(int m,int n):num(m),grade(n),next(NULL){} };node* head;public:student():head(NULL){} ~student(void){ clear();} void clear(void){ node* p = head;...

用C++编写程序:输入一个表示月份的整数,分别代表日期的年、月、日,计 ...
include<iostream> include<cmath> using namespace std;class Date { public:Date(int y=1900,int m=1, int d=1);bool isleapyear();bool isendofmounth();void add_day(int dd);void print_mdy();int jiange_day();private:void setdate(int yy,int mm,int dd);void add_oneday()...

用C++编写程序统计学生某一课程考试成绩
\/\/代码:include<iostream.h> void main(void){ cout<<"请输入全班同学的的成绩:(以输入负数为结束标志)\\n";int score[150];int i,n=0,max,min;double sum=0;for(i=0;;i++){ cin>>score[i];if(score[i]<0)break;n++;\/\/统计总共输入了多少个人的成绩 }\/\/以输入负数为结束标志...

c++编写一个简单程序1
include<iostream> include<string> using namespace std;class Student { string sid;string sname;static int n;public:Student(); \/\/无参构造函数 Student(string id,string name);\/\/有参构造函数 Student(Student &stu);\/\/复制构造函数 void output();\/\/输出学号和姓名 static void showStuNum...

用C++编写。题目:编一个程序,程序中包含以下内容
include<cmath> using namespace std;float PI=3.1415926;class Circle{ double radius,Area,perimeter;public:Circle(double a=0);Circle(Circle &);void SetR(double R);double GetR(){return r;} double GetAreaCircle(){return Area;} double Getperimeter(){return Circumference;} };Circle:...

c++编写程序:数组中相同的数保留一个
include <stdio.h>int main(){int n,i,j,k; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-1;i++) {for(j=i+1;j<n;j++) if(a[j]==a[i]) {for(k=j;k<n-1;k++) a[k]=a[k+1]; n--; j--; ...

c++程序编写和执行顺序的问题
如:#include <iostream> using namespace std;void printstar(void){ cout<<'$'<<'$'<<'$'<<endl;} int main(){ printstar();cout<<"C++ 123"<<endl;printstar();return 0;} 这就是个很简单的函数定义与调用,程序里main函数调用了printstar函数,我们在调用前就定义了printstar函数,...

c++编写程序有十个学生,每个学生的数据包括学号 姓名 5门功课的成绩...
include <iostream>using namespace std;\/\/ 声明一个结构体保存学生的信息struct Student{ int id; char name[11]; \/\/这里限制了name的长度 int score[5]; \/\/这里声明了一个长度为5的int数组};\/\/ 声明并定义函数计算学生5门成绩的总和int sum_score(int *score){ int sum = 0;...

C++编程序题:(一)定义一个圆类XY,计算圆的面积和周长(). 要求:1.该...
【题意分析】本题是最基础的C++类使用习题,主要就是练习类的定义,私有成员,外部成员,成员变量,成员函数的使用等。下面这段代码每行都有注释,除了实现题中的功能,还有一些基础的示例对理解C++的类很有帮助,具体代码如下: 【程序代码】#include <iostream> \/\/控制台操作头文件 class XY \/\/定义...

用c++编写一个程序
楼主稍等片刻,我正在帮你编,快好了,写好后我会将代码献上。以下是代码:include<iostream>#include<string>using namespace std;\/*编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为...

普安县13693902266: 在C++程序中怎样编写两个向量的内积与外积(成员函数) -
咎彩加利: 如:class Vector{public: Vector(double cx, double cy, double cz) : x(cz), y(cy), z(cz){} Vector OuterProduct(const Vector & v) { double nx = y * v.z - z * v.y; double ny = z * v.x - x * v.z; double nz = x * v.y - y * v.x; return Vector(nx, ny, nz);} double ...

普安县13693902266: c++中 用指针编写程序 求两个向量的内积,,急急急,,望高手救救小弟 不胜感激 -
咎彩加利: #include <iostream> using namespace std; class V { double x,y; public: V(){} V(double a,double b) { x=a; y=b; } friend V operator*(V a,V b) { V c; c.x=a.x*b.x; c.y=a.y*b.y; return c; } void show() {cout<<x<<" "<<y<<endl;} }; int main() { V v1(1,3),v2(2,5)...

普安县13693902266: 利用指针形式编写一个程序,求两个向量的乘积.C++ -
咎彩加利: #include <iostream> int main() { int * p = new int ; int * p1 = new int ; printf("输入第一个向量\n"); scanf("%d",p1); printf("输入第二个向量\n"); scanf("%d",p); printf("乘积为""%d\n",(*p)*(*p1)); delete p; delete p1; system("pause"); }

普安县13693902266: C++中如何编写一个向量? -
咎彩加利: 向量的乘法有两种,分别成为内积和外积.内积也称数量积,因为其结果为一个数(标量),向量a,b的内积为|a||b|cos(其中表示a与b的夹角)向量外积也叫叉乘,其结果为一个向量,方向是按右手系垂直与a,b所在平面|a||b|sin

普安县13693902266: C++ 两个向量 距离 -
咎彩加利: float a1, b1, a2, b2, len; cout << "input the value of a"; cin >> a1 >> b1; cout <<"input the value of b"; cin >> a2>>b2; cout << "the length is "; len = sqrt((a1 - a2)*(a1-a2) + (b1-b2)*(b1-b2)); cout << len <<endl

普安县13693902266: 写一个C++程序来检验两个向量是否有相同的元素,如{1,4,9,16,9,7,4,9,11}和{11,11,7,9,14,1} -
咎彩加利: 直接比较的话复杂度太高了,借用一个set来比较就很方便了.//比较两个vector中是否存在相同的元素//复杂度为O(m+n) bool same_vec(const vector& a, const vector& b) { set m( a.begin(), a.end() ); vector<int>::iterator it = b.begin(); for(; it!=b.end(); it++) if( m.find( *it )!=m.end() ){ return true; } return false; }

普安县13693902266: C++中的向量怎么插入一个元素~!语句是什么!! -
咎彩加利: vectorva;va.erase(va.begin()+i-1);

普安县13693902266: 关于C++中的二维向量 -
咎彩加利: 二维向量只是等于两个一位数组. 二维数组a[N,M]是一个N*M的表.等于N个一维数组. 当N = 2时.表示二维向量. 如二维数组 : int a[100][100]. 二维向量 : int a[2][100]. 由于二维向量被二维数组包含,所以二维向量也是像二维数组那样是用下...

普安县13693902266: c++的二维向量的用法 -
咎彩加利: 封装一个类,里面包含二维向量的值,比如{123.45,123.44},就用两个float类型存起来 然后在类里面写几个函数,以此提供接口来进行运算,可以尝试重载运算符来让你的程序看起来更加可爱一点

普安县13693902266: 用C++语言编写一个交换两个字符型变量内容的函数.具体要求见问题补充. -
咎彩加利: #include <iostream.h> void Swap(char& x, char& y){ char t; t=x; x=y; y=t; } void main(){ char c1,c2; c1='A'; c2='B'; cout <<c1 <<"," <<c2 <<endl; Swap(c1,c2); cout <<c1 <<"," <<c2 <<endl; }

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网