YTU 2611: A代码完善--向量的运算
2611: A代码完善--向量的运算
时间限制: 1 Sec 内存限制: 128 MB
提交: 256 解决: 168
题目描述
注:本题只需要提交填写部分的代码,请按照C++方式提交。
对于二维空间中的向量,实现向量的减法和取负运算。如向量A(x1,y1)和B(x2,y2),
则 A-B 定义为 (x1-x2,y1-y2) , -A 定义为 (-x1,-y1) 。
#include <stdio.h>
#include <iostream>
using namespace std;
class Vector
{
private :
int x,y;
public:
void setValue(int x,int y)
{
this->x=x;
this->y=y;
}
void output()
{
cout<<"x="<<x<<",y="<<y<<endl;
}
Vector operator-();
friend Vector operator- (Vector &v1,Vector &v2);
};
int main()
{
Vector A,B,C;
int x,y;
cin>>x>>y;
A.setValue(x,y);
cin>>x>>y;
B.setValue(x,y);
C = A - B;
C.output();
C = -C;
C.output();
return 0;
}
/*
请在该部分补充缺少的代码
*/
输入
两个向量
输出
向量减法和向量取负运算后的结果
样例输入
10 20 15 25
样例输出
x=-5,y=-5
x=5,y=5
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include <stdio.h>
#include <iostream>
using namespace std;
class Vector
{
private :
int x,y;
public:
void setValue(int x,int y)
{
this->x=x;
this->y=y;
}
void output()
{
cout<<"x="<<x<<",y="<<y<<endl;
}
Vector operator-();
friend Vector operator- (Vector &v1,Vector &v2);
};
int main()
{
Vector A,B,C;
int x,y;
cin>>x>>y;
A.setValue(x,y);
cin>>x>>y;
B.setValue(x,y);
C = A - B;
C.output();
C = -C;
C.output();
return 0;
}
Vector Vector::operator-()
{
Vector a;
x=-x;
y=-y;
a.x=x,a.y=y;
return a;
}
Vector operator- (Vector &v1,Vector &v2)
{
Vector a;
a.x=v1.x-v2.x;
a.y=v1.y-v2.y;
return a;
}
#include <iostream>
using namespace std;
class Vector
{
private :
int x,y;
public:
void setValue(int x,int y)
{
this->x=x;
this->y=y;
}
void output()
{
cout<<"x="<<x<<",y="<<y<<endl;
}
Vector operator-();
friend Vector operator- (Vector &v1,Vector &v2);
};
int main()
{
Vector A,B,C;
int x,y;
cin>>x>>y;
A.setValue(x,y);
cin>>x>>y;
B.setValue(x,y);
C = A - B;
C.output();
C = -C;
C.output();
return 0;
}
Vector Vector::operator-()
{
Vector a;
x=-x;
y=-y;
a.x=x,a.y=y;
return a;
}
Vector operator- (Vector &v1,Vector &v2)
{
Vector a;
a.x=v1.x-v2.x;
a.y=v1.y-v2.y;
return a;
}
YTU 2611: A代码完善--向量的运算的更多相关文章
- YTU 2616: A代码完善--简易二元运算
2616: A代码完善--简易二元运算 时间限制: 1 Sec 内存限制: 128 MB 提交: 280 解决: 187 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 编写二 ...
- YTU 2614: A代码完善--系统日期
2614: A代码完善--系统日期 时间限制: 1 Sec 内存限制: 128 MB 提交: 216 解决: 113 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 已知某操作 ...
- YTU 2945: 编程:五元向量的运算
2945: 编程:五元向量的运算 时间限制: 1 Sec 内存限制: 128 MB 提交: 151 解决: 85 题目描述 用习惯了的运算符操作新定义的类对象,这是OO方法给我们带来的便利.下面要 ...
- R语言入门:向量的运算
向量之间的加减乘除运算: > x <- 1 > x [1] 1 2 3 4 5 6 7 8 9 10 > x=x+1 > x [1] 2 3 4 5 6 7 8 9 10 ...
- cmdb客户端代码完善2
目录: 1.面试提问 2.完善采集端代码 3.唯一标识的问题 4.API的验证 1.面试会问到的问题: # 1. 为啥要做CMDB?# - 实现运维自动化, 而CMDB是实现运维自动化的基石# - 之 ...
- YTU 2607: A代码填空题--更换火车头
2607: A代码填空题--更换火车头 时间限制: 1 Sec 内存限制: 128 MB 提交: 91 解决: 73 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 假设火车有 ...
- YTU 2953: A代码填充--学画画
2953: A代码填充--学画画 时间限制: 1 Sec 内存限制: 128 MB 提交: 62 解决: 52 题目描述 最近小平迷上了画画,经过琨姐的指导,他学会了RGB色彩的混合方法.对于两种 ...
- YTU 2952: A代码填充--谁挡住了我
2952: A代码填充--谁挡住了我 时间限制: 1 Sec 内存限制: 128 MB 提交: 135 解决: 38 题目描述 n个人前后站成一列,对于队列中的任意一个人,如果排在他前面的人的身高 ...
- 第2节 storm实时看板案例:12、实时看板综合案例代码完善;13、今日课程总结
详见代码 将任务提交到集群上面去运行 apache-storm-1.1.1/bin/storm jar cn.itcast.storm.kafkaAndStorm.KafkTopology kafka ...
随机推荐
- Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树
题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...
- maven ArtifactTransferException: Failure to transfer
我在使用Myeclipse碰见这个错误,我没有用伺服,直接连接到maven中心. ArtifactTransferException: Failure to transfer org.apache.h ...
- OpenSSL 1.0.0生成p12、jks、crt等格式证书的命令个过程(转)
OpenSSL 1.0.0生成p12.jks.crt等格式证书的命令个过程 此生成的证书可用于浏览器.java.tomcat.c++等.在此备忘! 1.创建根证私钥命令:openssl g ...
- lua与 object-C 通信
IOS中如何调用LUA,以及LUA如何调用IOS中的功能 下面将讲解一下如何在iOS里调用Lua函数,以及Lua函数如何调用iOS本地函数. 转载请注明出处.原文出处 http://www.cnblo ...
- Swift-5-流程控制
// Playground - noun: a place where people can play import UIKit // For-In 循环 // 1 遍历数字区间 ... { prin ...
- 响应式嵌入 iframe Pym.js
Pym.js 可以让你在嵌入 iframe 的时候可自动的对 iframe 的大小进行调整以适应父一层容器,并且可以避免跨域问题. 支持浏览器: Internet Explorer 9, 10 (Wi ...
- 已有a,b两个链表,每个链表中的结点包括学号、成绩。要求把两个链表合并,按学号升序排列
1.我的思路先将b链表连接在a链表的后面,这个很容易实现,将a链表最后的结点中的p.next改为指向b链表的头结点即可. 再将这个新链表用选择排序即可. 代码如下: #include<stdio ...
- sao/jsp
sao/i18n/message/ Messages-Client.xml Messages-Server.xml sao/wsdl Verification.wsdl IProcessS ...
- Tomcat server分端口部署web项目
<?xml version='1.0' encoding='utf-8'?> <Server port="8006" shutdown="SHUTDOW ...
- BZOJ2199: [Usaco2011 Jan]奶牛议会
趁此机会学了一下2-SAT. 以前的2-SAT都是用并查集写的,只能应用于极小的一部分情况,这次学了一正式的2-SAT,是用一张有向图来表示其依赖关系. 2-SAT的介绍参见刘汝佳<训练指南&g ...