C++关于二维向量的乘法问题

gaoshou0804 2011-04-24 07:46:41
#include <iostream>
using namespace std;
class Vector2D
{
public:
int x1,x2,y1,y2;
void input1()
{
cout<<"Please input the x1 of the A(x1,x2) "<<endl;
cin>>x1;
cout<<"Please input the x2 of the A(x1,x2) "<<endl;
cin>>x2;

}
void input2()
{
cout<<"Please input the y1 of the B(y1,y2) "<<endl;
cin>>y1;
cout<<"Please input the y2 of the B(y1,y2) "<<endl;
cin>>y2;
}
int Multiply(int x1,int x2,int y1,int y2)
{
return x1*x2+y1*y2;
}
};

int main()
{ Vector2D v;
v.input1();
v.input2();
int Vector2D::Multiply(int x1,int x2,int y1,int y2);
}

让写一个类,来执行向量的乘法运算。。。请问为何没有输出。。应该怎么改啊。。。。。
...全文
238 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
newfarmerchi 2011-04-24
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
class Vector2D
{
public:
int x1,x2,y1,y2;
void input1()
{
cout<<"Please input the x1 of the A(x1,x2) "<<endl;
cin>>x1;
cout<<"Please input the x2 of the A(x1,x2) "<<endl;
cin>>x2;

}
void input2()
{
cout<<"Please input the y1 of the B(y1,y2) "<<endl;
cin>>y1;
cout<<"Please input the y2 of the B(y1,y2) "<<endl;
cin>>y2;
}
int Multiply()//<---------here
{
return x1*x2+y1*y2;
}
};

int main()
{ Vector2D v;
v.input1();
v.input2();
cout<<v.Multiply()<<endl;//<--------------here
}



淡蓝 2011-04-24
  • 打赏
  • 举报
回复
把类改一下
淡蓝 2011-04-24
  • 打赏
  • 举报
回复
class Vector2D
{
public:
int x1,x2,y1,y2;
void input1()
{
cout<<"Please input the x1 of the A(x1,x2) "<<endl;
cin>>x1;
cout<<"Please input the x2 of the A(x1,x2) "<<endl;
cin>>x2;

}
void input2()
{
cout<<"Please input the y1 of the B(y1,y2) "<<endl;
cin>>y1;
cout<<"Please input the y2 of the B(y1,y2) "<<endl;
cin>>y2;
}
int Multiply()
{
return x1*x2+y1*y2;
}
};

64,691

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧