#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 改进的更多相关文章

  1. Code alignment 代码对齐改进(VS2017)

    In mathematics you always keep your equals lined up directly underneath the one above. It keeps it c ...

  2. Code for the Homework2 改进

    1. 实现了到指定点各个关节的转角计算(多解性),并且所求解满足各个关节的最大角和最小角的限制条件. 2. 对方向向量进行了单位化,保证任意大小的向量都行 #include<iostream&g ...

  3. Code for the Homework1

    作业要求: http://www.cnblogs.com/bingc/p/4919692.html 代码(未使用Eigen): #include <iostream> #include & ...

  4. PHP5.4最新特性

     PHP5.4最新特性   官网:ChangeLog-5.php#5.4.0 原文Oracle:LAMP 体系有了新的竞争,但此版本中的特性使 PHP 再次挑战极限. 稍微做了修改.: 概述总结:1. ...

  5. 《精通python网络爬虫》笔记

    <精通python网络爬虫>韦玮 著 目录结构 第一章 什么是网络爬虫 第二章 爬虫技能概览 第三章 爬虫实现原理与实现技术 第四章 Urllib库与URLError异常处理 第五章 正则 ...

  6. iOS开发 - 开发版+企业版无线发布一键打包

    背景:项目进入快速迭代期,需要快速地交付出AdHoc版本和企业无线发布版本.每次打包都要来回切换bundle identifier和code signing,浪费很多时间. 示例项目名称名称为Test ...

  7. 3D-camera结构光原理

    3D-camera结构光原理 目前主流的深度探测技术是结构光,TOF,和双目.具体的百度就有很详细的信息. 而结构光也有双目结构光和散斑结构光等,没错,Iphone X 的3D深度相机就用 散斑结构光 ...

  8. 算法所产生的性能改进已经超过了硬件所带来的性能提升 The future is algorithms, not code

    w 大数据的发展,伴随的将是软件工程师的渐退,算法工程师的崛起  http://mp.weixin.qq.com/s/XTz2HnzwlgTD3g5zU2u5Tg

  9. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

随机推荐

  1. Hive中自定义函数

    Hive的自定义的函数的步骤: 1°.自定义UDF extends org.apache.hadoop.hive.ql.exec.UDF 2°.需要实现evaluate函数,evaluate函数支持重 ...

  2. [ImportNew]Java中的Timer类和TimerTask类

    http://www.importnew.com/9978.html java.util.Timer是一个实用工具类,该类用来调度一个线程,使它可以在将来某一时刻执行. Java的Timer类可以调度 ...

  3. hdu 3743 树状数组

    思路:我们只需坚守一个原则,本来就在左边的坚决不把它换到右边.也就是相邻的两个数,左边小,右边大,那么就不调换.这样对每个数,只要统计左边比它大的数的个数.可以从后面开始用树状数组统计比它小的数的个数 ...

  4. 使用GBK编码请求访问nodejs程序报415错误:Error: unsupported charset at urlencodedParser ...

    最近遇到一个问题,第三方用户向我们提供给的回调地址发送请求时一直报415错误,结果发现他们使用的是GBK编码请求,而我们使用的node + express4 程序,不支持GBK编码请求. 问题出在下面 ...

  5. ENVI/IDL与ArcGIS集成开发的三种途径

    转载:本文来自ENVI5.0-IDL8.2系列产品白皮书_201303.PDF(Esri中国官网可下载)中P7-P10 ENVI 是一个非常开放的平台,提供一个健全的函数库,几乎涵盖ENVI 平台大部 ...

  6. DataTables手动带参数提交至服务器

    一:参数传递及接收 JavaScript: 黄背景部分为参数传递关键 <script type="text/javascript"> var table; var de ...

  7. 小议jQuery中的事件

    学了jQuery这么长时间,到这里真的有一种柳暗花明又一村的感觉,在这里先表达一下自己学这一章节的happy心情吧(在严厉的金工实习老师眼皮底下偷偷学习,当然还有各种nerves~). 1加载DOM ...

  8. POi写入大批量数据

    直接贴代码: package jp.co.misumi.mdm.batch.common.jobrunner; import java.io.File; import java.io.FileNotF ...

  9. Android经验之谈1

    豌豆荚等可能会导致手机网络出现问题,电话打不进来,所以需要及时卸载豌豆荚. 系统apk,不能通过在manifest.xml里面添加origin-package或者useid等来改变. 而是需要用and ...

  10. HTML JSOgN to string

    JSON.stringify(json).replace(',', ', ').replace('[', '').replace(']', '')