#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. hdu 4571 floyd+动态规划

    思路: 我们先求一遍floyd,将各点的最短距离求出,然后将点按si的升序排序.dp[i][k]表示第i个点在第j时间所获得的最大效益,那么 dp[i][k]=max(dp[ i ][ k ]  , ...

  2. Xcode编译时出现cannot run using the selected device提示

    很多文章说这个管用: 1) Project->Info->Deployment Target->iOS Deployment Target更改为<=设备的版本号; 2) Tar ...

  3. HTML5 图片上传预览

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8& ...

  4. mdeditor

    *在线地址:* http://ghosertblog.github.io/mdeditor/ # Markdown 语法简明手册 ### 1. 使用 * 和 ** 表示斜体和粗体 示例: 这是 *斜体 ...

  5. html5之meta标签viewport应用

    在html5移动页面中,viewport定义必不可少. 首先了解下关于viewport的概念: 先了解移动设备的屏幕尺寸和设备尺寸: iPhone3 设备尺寸 320*480 ; 屏幕尺寸  320* ...

  6. iPad accessory communication through UART

    We manufacture a new accessory for iPad/iPhone which should transfer commands to the iPad. We like t ...

  7. UML——类和对象

  8. 转:SqlServer2008误操作数据(delete或者update)后恢复数据

    Sqlserver2008误操作数据(delete或者update)后恢复数据(转) 实际工作中,有时会直接在数据库中操作数据,比如对数据进行delete或者update操作,当进行这些操作的时候,如 ...

  9. Android之帧动画2

    创建自定义对话框: // 对话框构建器 Builder builder = new AlertDialog.Builder(this); // 创建出一个空的对话框 final AlertDialog ...

  10. Java垃圾回收介绍(译)

    在Java中,对象内存空间的分配与回收是由JVM中的垃圾回收进程自动完成的.与C语言不同的是,在Java中开发者不需要专门为垃圾回收写代码.这是使Java流行的众多特征之一,也帮助了程序员写出了更好的 ...