作业要求: http://www.cnblogs.com/bingc/p/4919692.html

代码(未使用Eigen):

 #include <iostream>
 #include <Eigen/Dense>
 using namespace Eigen;
 using Eigen::MatrixXd;
 using namespace std;
 class POINT
 {
 public:
     string name;
     double x, y;

 };
 class LINE
 {
 public:
     string name;
     POINT p_start,p_end;
 };
 class TRIANGLE
 {
 public:
     string name;
     POINT p1,p2, p3;
 };
 void rotate(POINT *pt, double angle);
 int main()
 {    string name,cmd,name1;
     int num;
     , l = , t = ;
     ;
     POINT point[maxnum];
     LINE line[maxnum];
     TRIANGLE triangle[maxnum];
     int flag;
     char a, b, c;
     double x, y, angle;
     )
     {
         cout << "存点、线、三角形,请输入0,操作点、线、三角形请输入1" << endl;
         cin >> flag;
         switch (flag)
         {
         :{
             cout << "请输入图形名称 点数 坐标" << endl;
             cin >> name;
             cin >> num;
             switch (num)
             {
             :
             {
                 if (p >= maxnum) { cout << "您的点的个数已达上限,不能再存!" << endl; break; }
                 point[p].name = name;
                 cin >> a >> point[p].x >> b >> point[p].y >> c;
                 p++;
                 break;
             }
             :
             {
                 if (l >= maxnum) { cout << "您的线的个数已达上限,不能再存!" << endl; break; }
                 line[l].name = name;
                 cin >> a >> line[l].p_start.x >> b >> line[l].p_start.y >> c >> a >> line[l].p_end.x >> b >> line[l].p_end.y >> c;
                 l++;
                 break;
             }
             :
             {
                 if (t >= maxnum) { cout << "您的三角形的个数已达上限,不能再存!" << endl; break; }
                 triangle[t].name = name;
                 cin >> a >> triangle[t].p1.x >> b >> triangle[t].p1.y >> c >> a >> triangle[t].p2.x >> b >> triangle[t].p2.y >> c >> a >> triangle[t].p3.x >> b >> triangle[t].p3.y >> c;
                 t++;
                 break;
             }
             default: {cout << "点数输入错误" << endl; break; }
             }
             break;
         }
         :{
             cout << "请输入操作指令" << endl;
             cin >> cmd;
             cin>> name1;
             if (cmd == "move")
             {
                 cin >> a >> x >> b >> y >> c;
                 ; i < p; i++)
                 {
                     if (name1 == point[i].name)
                     {
                         point[i].x += x;
                         point[i].y += y;
                         cout << "平移后的点为" << "(" << point[i].x << "," << point[i].y << ")" << endl;
                     }
                 }
                 ; i < l; i++)
                 {
                     if (name1 == line[i].name)
                     {
                         line[i].p_start.x += x;
                         line[i].p_start.y += y;
                         line[i].p_end.x += x;
                         line[i].p_end.y += y;
                         cout << "平移后的线段端点为" << "(" << line[i].p_start.x << "," << line[i].p_start.y << ")" << "、(" << line[i].p_end.x << "," << line[i].p_end.y << ")" << endl;
                     }
                 }
                 ; i < t; i++)
                 {
                     if (name1 == triangle[i].name)
                     {
                         triangle[i].p1.x += x;
                         triangle[i].p1.y += y;
                         triangle[i].p2.x += x;
                         triangle[i].p2.y += y;
                         triangle[i].p3.x += x;
                         triangle[i].p3.y += y;
                         cout << "平移后的三角形顶点为为" << "(" << triangle[i].p1.x << "," << triangle[i].p1.y << ")" << "、(" << triangle[i].p2.x << "," << triangle[i].p2.y << ")" << "、(" << triangle[i].p3.x << "," << triangle[i].p3.y << ")" << endl;
                     }
                 }
             }
             else if (cmd == "rotate")
             {
                 cin >> angle;
                 ; i < p; i++)
                 {
                     if (name1 == point[i].name)
                     {
                         rotate(&point[i], angle);
                         cout << "旋转后的点为" << "(" << point[i].x << "," << point[i].y << ")" << endl;
                     }
                 }
                 ; i < l; i++)
                 {
                     if (name1 == line[i].name)
                     {
                         rotate(&line[i].p_start, angle);
                         rotate(&line[i].p_end, angle);
                         cout << "旋转后的直线端点为" << "(" << line[i].p_start.x << "," << line[i].p_start.y << ")" << "、(" << line[i].p_end.x << "," << line[i].p_end.y << ")" << endl;
                     }
                 }
                 ; i < t; i++)
                 {
                     if (name1 == triangle[i].name)
                     {
                         rotate(&triangle[i].p1, angle);
                         rotate(&triangle[i].p2, angle);
                         rotate(&triangle[i].p3, angle);
                         cout << "旋转后的三角形顶点为为" << "(" << triangle[i].p1.x << "," << triangle[i].p1.y << ")" << "、(" << triangle[i].p2.x << "," << triangle[i].p2.y << ")" << "、(" << triangle[i].p3.x << "," << triangle[i].p3.y << ")" << endl;
                     }
                 }
             }
             else cout << "comand is error!" << endl;
             break;
         }
         default:{cout << "输入错误!" << endl; break; }

         }
     }

     ;
 }

 void rotate(POINT *pt, double angle)  //逆时针为正
 {
     double x, y,ang;
     x = pt->x;
     y = pt->y;
     ang = angle*;
     pt->x = x*cos(ang) - y*sin(ang);
     pt->y = x*sin(ang) + y*cos(ang);
 }

运行结果:

Code for the Homework1的更多相关文章

  1. Code for the Homework1 改进

    #include <iostream> #include <vector> #include "shape.h" //using namespace std ...

  2. python code 1_username registration & login

    This tiny program consists of 2 parts - registration and login. In the part of registration, the key ...

  3. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  4. 我们是怎么做Code Review的

    前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...

  5. Code Review 程序员的寄望与哀伤

    一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...

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

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

  7. 在Visual Studio Code中配置GO开发环境

    一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...

  8. 代码的坏味道(14)——重复代码(Duplicate Code)

    坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...

  9. http status code

    属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...

随机推荐

  1. [未完成][Mooc]关于IO总结

    整个课程的大纲:1.编码问题.2.File类的使用3.RandomAccessFile的使用4.字节流的使用.5.字符流的使用.6.对象的序列化和反序列化. 视频1:文件的编码Eclipse的一大特点 ...

  2. centos 安装 acrobat Reader之后

    IV: 为Firefox等浏览器安装Acrobat Reader插件:sudo /usr/local/Adobe/Acrobat7.0/Browser/install_browser_plugin按照 ...

  3. HttpClient(4.3.5) - Exception Handling

    HttpClient can throw two types of exceptions: java.io.IOException in case of an I/O failure such as ...

  4. AppScan安全问题解决方案

    一. 环境准备 测试通常给的是PDF文档,动辄几百页,看起来很费劲,看文档的时间可能比解决问题的时间还长...所以作为需要解决问题的我们来说,最好安装AppScan,请测试人员提供类型为AppScan ...

  5. Asp.net MVC 4 Html帮助类

    Html帮助类 used to render (modify and output) HTML form elements 用来渲染HTML表单元素(修改和输出) Html.ActionLink 输出 ...

  6. C# winform 选择项 省市连动

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. 非Page类使用session(Httpcontext.session和page.session区别)

    ASP.NET中Session高级使用技巧 在开发Aspx .NET软件时,有时需要把常用的东西封装到一个非PAGE类中,文章介绍在非Page类中使用Session的方法. 一.PAGE参数法: 1. ...

  8. c#基础学习汇总----------继承

    封装,继承,多态.这是面向对象的思想,也可以说是最基本的东西.说到继承,直接的说他就是面向对象中类与类之间的一种关系.通过继承,使得子类具有父类公有的受保护访问权限的属性和方法,同时子类可以通过加入新 ...

  9. Linux 锁

    问题: 1.假如对某个文件加了锁/lock,但是程序退出时没有关闭锁,如果想在另外一个程序中用这个文件,如何办? 2.

  10. HTML5之 WebWorkers

    为了进行后台计算提供的完全隔离计算方式 不可访问 DOM APIs 不可访问 window object 不可访问 document object 强隔离保证并行计算结果无误(无锁机制) ---- 启 ...