#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. Windows 7 IE11 F12 不能正常使用

    打开任意网站,按下F12,或者右键鼠标,按L键.出现上面的图的情况!解决办法如下:需要安装下面的补丁(KB3008923) 32位系统:http://www.microsoft.com/en-us/d ...

  2. backboneJs 导图

  3. WebStorm 8.0安装LESS编译环境的教程

    WebStorm是一个非常棒的Web前端开发编辑器,被程序猿们成为“最智能的JavaScript IDE”.对HTML5.Bootstrap框架.Node.js等都有完美支持.目前最新版本为WebSt ...

  4. Jersey(1.19.1) - WebApplicationException and Mapping Exceptions to Responses

    Previous sections have shown how to return HTTP responses and it is possible to return HTTP errors u ...

  5. C#编写windows服务程序

    Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Window ...

  6. Javascript之换肤(未完待续)

    这个项目我还没有完全写出来,先记录至此.感觉是方法不对,背景图片的切换方法有Problem.如若有一大神发现了我的文章,还望指导,吾将感激不尽.日后代码还会再钻研再改改. <head> & ...

  7. 第三篇、image 设置圆角的几种方式

    第一种: 就拿view来举例 view.layer.masksToBounds=YES; //设置为yes,就可以使用圆角 view.layer.cornerRadius= ; //设置它的圆角大小 ...

  8. 值类型与引用类型(特殊的string) Typeof和GetType() 静态和非静态使用 参数传递 相关知识

    学习大神博客链接: http://www.cnblogs.com/zhili/category/421637.html 一 值类型与引用类型 需要注意的string 是特殊类型的引用类型. 使用方法: ...

  9. bzoj3389:[Usaco2004 Dec]Cleaning Shifts安排值班

    思路:可以贪心,也可以最短路. 贪心写法:因为在保证合法的前提下,我们选择的区间一定要右端点尽量靠后才行,于是我们每次就选择一个合法的并且右端点最靠后的区间就好了(如果没有合法的输出-1即可).时间复 ...

  10. Linux 小记录

    <1>bzero 原型:extern void bzero(void *s, int n);用法:#include <string.h> 功能:置字节字符串s的前n个字节为零. ...