Code for the Homework1 改进
#include <iostream>
#include <vector>
#include "shape.h"
//using namespace std;
//using namespace Eigen; 在shape.h中
const double PI=3.141592653;
vector<SHAPE*> sv;
vector<SHAPE*>::iterator itr;
POINT p;
LINE l;
TRIANGLE t;
void Shape_Save(void);
void Shape_Handle(void);
int main()
{
int flag;
)
{
cout << "存图形请输入0,操作图形请输入1" << endl;
cin >> flag;
switch (flag)
{
:Shape_Save();break;
:Shape_Handle(); break;
default:cout << "输入错误!" << endl; break;
}
}
;
}
void Shape_Save()
{
string name;
int num;
cout << "请输入图形名称 点数 坐标" << endl;
cin >> name;
cin >> num;
switch (num)
{
:
{
p.name=name;
p.get_cin_point();
sv.push_back(&p);
break;
}
:
{
l.name=name;
l.get_cin_line();
sv.push_back(&l);
break;
}
:
{
t.name=name;
t.get_cin_triangle();
sv.push_back(&t);
break;
}
default: {cout << "点数输入错误" << endl; break; }
}
}
void Shape_Handle(void)
{
string cmd,name1;
char a, b, c;
Vector2d vec;
double x,y,angle;
cout << "请输入操作指令" << endl;
cin >> cmd;
cin>> name1;
if (cmd == "move")
{
cin >> a >> x >> b >> y >> c;
vec[]=x;vec[]=y;
// for(int i=0;i<sv.size();i++)
// {
// if(name1 == sv[i]->name)
// {
// cout<<"i="<<i<<endl;
// sv[i]->move(vec);
// cout << sv[i]->name<<"平移后为:";
// sv[i]->display();
// }
// }
for (itr = sv.begin(); itr != sv.end(); itr++) //迭代器方式
{
if(name1== (*itr)->name)
{
(*itr)->move(vec);
cout << (*itr)->name<<"平移后为:";
(*itr)->display();
}
}
}
else if (cmd == "rotate")
{
cin >> angle;
// for(int i=0;i<sv.size();i++)
// {
// if(name1 == sv[i]->name)
// {
// sv[i]->rotate(angle);
// cout << sv[i]->name<<"旋转后为:";
// sv[i]->display();
// }
// }
for (itr = sv.begin(); itr != sv.end(); itr++) //迭代器方式
{
if(name1== (*itr)->name)
{
(*itr)->rotate(angle);
cout << (*itr)->name<<"旋转后为:";
(*itr)->display();
}
}
}
else cout << "comand is error!" << endl;
}
main.cpp
#include <Eigen/Dense>
#include <iostream>
#include <vector>
using namespace Eigen;
using namespace std;
extern const double PI;
class SHAPE
{
public:
string name;
;
// {
// cout<<1;
// return;
// };
;
// {
// cout<<1;
// return;
// }
;
// {
// cout<<1;
// return;
// }
};
class POINT:public SHAPE
{
public:
double x, y;
POINT(){
};
POINT(string nam,double xx,double yy){
name=nam;
x=xx;
y=yy;
}
POINT(const POINT &p){
name=p.name;
x=p.x;
y=p.y;
}
void copyto(POINT &p);
void get_cin_point(void);
void display();
void rotate(double &angle);
void move(Vector2d &vec);
};
class LINE:public SHAPE
{
public:
POINT p_start,p_end;
LINE(){
}
LINE(string nam,POINT s,POINT e)
{
name=nam;
s.copyto(p_start);
e.copyto(p_end);
}
void get_cin_line(void);
void display();
void rotate(double &angle);
void move(Vector2d &vec);
};
class TRIANGLE:public SHAPE
{
public:
POINT p1,p2, p3;
TRIANGLE(){
}
TRIANGLE(string nam,POINT pp1,POINT pp2,POINT pp3)
{
name=nam;
pp1.copyto(p1);
pp2.copyto(p2);
pp3.copyto(p3);
}
void get_cin_triangle(void);
void display();
void rotate(double &angle);
void move(Vector2d &vec);
};
shape.h
#include "shape.h"
/*****POINT类成员函数的实现****/
void POINT::copyto(POINT &p){
p.name=name;
p.x=x;
p.y=y;
}
void POINT::get_cin_point(void){
char a, b, c;
cin >> a >> x >> b >> y >> c ;
}
void POINT::display() {
cout << "(" << this->x << "," << this->y << ")" << endl;
}
void POINT::rotate(double &angle){ //逆时针为正
double x, y,ang;
x = this->x;
y = this->y;
ang = angle*PI/ ;
this->x = x*cos(ang) - y*sin(ang);
this->y = x*sin(ang) + y*cos(ang);
}
void POINT::move(Vector2d &vec){
];
];
}
/*****LINE类成员函数的实现****/
void LINE::get_cin_line(void){
char a, b, c;
cin >> a >>p_start.x>> b >> p_start.y >> c >> a >>p_end.x>> b >> p_end.y >> c;
}
void LINE::display(){
cout<<"起点";
p_start.display();
cout<<"终点";
p_end.display();
}
void LINE::rotate(double &angle){
p_start.rotate(angle);
p_end.rotate(angle);
}
void LINE::move(Vector2d &vec){
p_start.move(vec);
p_end.move(vec);
}
/*****TRIANGLE类成员函数的实现****/
void TRIANGLE::get_cin_triangle(void){
char a, b, c;
cin >> a >>p1.x>> b >> p1.y >> c >> a >>p2.x>> b >> p2.y >> c>> a >>p3.x>> b >> p3.y >> c;
}
void TRIANGLE::display() {
cout<<"顶点1";
p1.display();
cout<<"顶点2";
p2.display();
cout<<"顶点3";
p3.display();
}
void TRIANGLE::rotate(double &angle){
p1.rotate(angle);
p2.rotate(angle);
p3.rotate(angle);
}
void TRIANGLE::move(Vector2d &vec){
p1.move(vec);
p2.move(vec);
p3.move(vec);
}
shape.cpp
运行结果:


Code for the Homework1 改进的更多相关文章
- Code alignment 代码对齐改进(VS2017)
In mathematics you always keep your equals lined up directly underneath the one above. It keeps it c ...
- Code for the Homework2 改进
1. 实现了到指定点各个关节的转角计算(多解性),并且所求解满足各个关节的最大角和最小角的限制条件. 2. 对方向向量进行了单位化,保证任意大小的向量都行 #include<iostream&g ...
- Code for the Homework1
作业要求: http://www.cnblogs.com/bingc/p/4919692.html 代码(未使用Eigen): #include <iostream> #include & ...
- PHP5.4最新特性
PHP5.4最新特性 官网:ChangeLog-5.php#5.4.0 原文Oracle:LAMP 体系有了新的竞争,但此版本中的特性使 PHP 再次挑战极限. 稍微做了修改.: 概述总结:1. ...
- 《精通python网络爬虫》笔记
<精通python网络爬虫>韦玮 著 目录结构 第一章 什么是网络爬虫 第二章 爬虫技能概览 第三章 爬虫实现原理与实现技术 第四章 Urllib库与URLError异常处理 第五章 正则 ...
- iOS开发 - 开发版+企业版无线发布一键打包
背景:项目进入快速迭代期,需要快速地交付出AdHoc版本和企业无线发布版本.每次打包都要来回切换bundle identifier和code signing,浪费很多时间. 示例项目名称名称为Test ...
- 3D-camera结构光原理
3D-camera结构光原理 目前主流的深度探测技术是结构光,TOF,和双目.具体的百度就有很详细的信息. 而结构光也有双目结构光和散斑结构光等,没错,Iphone X 的3D深度相机就用 散斑结构光 ...
- 算法所产生的性能改进已经超过了硬件所带来的性能提升 The future is algorithms, not code
w 大数据的发展,伴随的将是软件工程师的渐退,算法工程师的崛起 http://mp.weixin.qq.com/s/XTz2HnzwlgTD3g5zU2u5Tg
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
随机推荐
- 关于Java中的构造方法和set方法()给属性赋值
对于一个类中的成员变量(属性),属性如果都设置成了private类型,那么对外给属性设置了get和set方法 , 那么外部程序中给这些属性设置值,有两种方式. 第一种就是通过set()方法. 第二种就 ...
- 【补】【FZU月赛】【20150515】【待续】
A FZU-2054 水题,比较A,B双方的最大值即可. B FZU-2055 string,截取‘.’之前和之后然后和给出的文件夹名和拓展名比较就好了啊,不明白为什么那么多人错. 代码: #incl ...
- Spring 循环引用(singleton与prototype初始化的区别)
原文链接请参见:http://blog.csdn.net/u010723709/article/details/47185959
- 关于IE6的一些常见的CSS BUG处理
CSS BUG:样式在各浏览器中解析不一致的情况,或者说CSS样式在浏览器中不能正确显示的问题称为CSS BUG: CSS Hack:css hack是指一种兼容css 在不同浏览器中正确显示的技巧方 ...
- 微信小程序(原名微信应用号)开发工具0.9版安装教程
微信小程序全称微信公众平台·小程序,原名微信公众平台·应用号(简称微信应用号) 声明 微信小程序开发工具类似于一个轻量级的IDE集成开发环境,目前仅开放给了少部分受微信官方邀请的人士(据说仅200个名 ...
- HTML5和Web Apps框架和方法
单页: 1jQuery Mobile 该框架以其基于AJAX的导航系统和可使用主题的ThemeRoller设计而闻名.支持Android,ios,Windows Phone,webOs等.编程模式为C ...
- ActiveMQ(5.10.0) - Connection Configuration URI
An Apache ActiveMQ connection can be configured by explicitly setting properties on the ActiveMQConn ...
- HDOJ2015偶数求和
偶数求和 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 为EditText设置OnTouchListener事件监听
在项目中需要在EditText输入前,判断某个值是否已经有值,有才可以输入,为NULL值则提示不让输入,先填写指定的编辑框 自己试过监听获取焦点事件,来设置setFocusable(true)或者se ...
- 32位和64位Ghost版Win8.1系统大全下载最新版
Ghost版Win8.1系统企业版,下载完成后一定要使用校验工具验证GHO文件MD5值,如果不符请不要安装,不然安装失败后果自负.GHO文件路径一定不要带中文,否则无法安装.安装完成第一次进入桌面会黑 ...