Code for the Homework1

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

代码(未使用Eigen):

  1 #include <iostream>
  2 #include <Eigen/Dense>
  3 using namespace Eigen;
  4 using Eigen::MatrixXd;
  5 using namespace std;
  6 class POINT
  7 {
  8 public:
  9     string name;
 10     double x, y;
 11
 12 };
 13 class LINE
 14 {
 15 public:
 16     string name;
 17     POINT p_start,p_end;
 18 };
 19 class TRIANGLE
 20 {
 21 public:
 22     string name;
 23     POINT p1,p2, p3;
 24 };
 25 void rotate(POINT *pt, double angle);
 26 int main()
 27 {    string name,cmd,name1;
 28     int num;
 29     int p = 0, l = 0, t = 0;
 30     const int maxnum = 10;
 31     POINT point[maxnum];
 32     LINE line[maxnum];
 33     TRIANGLE triangle[maxnum];
 34     int flag;
 35     char a, b, c;
 36     double x, y, angle;
 37     while (1)
 38     {
 39         cout << "存点、线、三角形,请输入0,操作点、线、三角形请输入1" << endl;
 40         cin >> flag;
 41         switch (flag)
 42         {
 43         case 0:{
 44             cout << "请输入图形名称 点数 坐标" << endl;
 45             cin >> name;
 46             cin >> num;
 47             switch (num)
 48             {
 49             case 1:
 50             {
 51                 if (p >= maxnum) { cout << "您的点的个数已达上限,不能再存!" << endl; break; }
 52                 point[p].name = name;
 53                 cin >> a >> point[p].x >> b >> point[p].y >> c;
 54                 p++;
 55                 break;
 56             }
 57             case 2:
 58             {
 59                 if (l >= maxnum) { cout << "您的线的个数已达上限,不能再存!" << endl; break; }
 60                 line[l].name = name;
 61                 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;
 62                 l++;
 63                 break;
 64             }
 65             case 3:
 66             {
 67                 if (t >= maxnum) { cout << "您的三角形的个数已达上限,不能再存!" << endl; break; }
 68                 triangle[t].name = name;
 69                 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;
 70                 t++;
 71                 break;
 72             }
 73             default: {cout << "点数输入错误" << endl; break; }
 74             }
 75             break;
 76         }
 77         case 1:{
 78             cout << "请输入操作指令" << endl;
 79             cin >> cmd;
 80             cin>> name1;
 81             if (cmd == "move")
 82             {
 83                 cin >> a >> x >> b >> y >> c;
 84                 for (int i = 0; i < p; i++)
 85                 {
 86                     if (name1 == point[i].name)
 87                     {
 88                         point[i].x += x;
 89                         point[i].y += y;
 90                         cout << "平移后的点为" << "(" << point[i].x << "," << point[i].y << ")" << endl;
 91                     }
 92                 }
 93                 for (int i = 0; i < l; i++)
 94                 {
 95                     if (name1 == line[i].name)
 96                     {
 97                         line[i].p_start.x += x;
 98                         line[i].p_start.y += y;
 99                         line[i].p_end.x += x;
100                         line[i].p_end.y += y;
101                         cout << "平移后的线段端点为" << "(" << line[i].p_start.x << "," << line[i].p_start.y << ")" << "、(" << line[i].p_end.x << "," << line[i].p_end.y << ")" << endl;
102                     }
103                 }
104                 for (int i = 0; i < t; i++)
105                 {
106                     if (name1 == triangle[i].name)
107                     {
108                         triangle[i].p1.x += x;
109                         triangle[i].p1.y += y;
110                         triangle[i].p2.x += x;
111                         triangle[i].p2.y += y;
112                         triangle[i].p3.x += x;
113                         triangle[i].p3.y += y;
114                         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;
115                     }
116                 }
117             }
118             else if (cmd == "rotate")
119             {
120                 cin >> angle;
121                 for (int i = 0; i < p; i++)
122                 {
123                     if (name1 == point[i].name)
124                     {
125                         rotate(&point[i], angle);
126                         cout << "旋转后的点为" << "(" << point[i].x << "," << point[i].y << ")" << endl;
127                     }
128                 }
129                 for (int i = 0; i < l; i++)
130                 {
131                     if (name1 == line[i].name)
132                     {
133                         rotate(&line[i].p_start, angle);
134                         rotate(&line[i].p_end, angle);
135                         cout << "旋转后的直线端点为" << "(" << line[i].p_start.x << "," << line[i].p_start.y << ")" << "、(" << line[i].p_end.x << "," << line[i].p_end.y << ")" << endl;
136                     }
137                 }
138                 for (int i = 0; i < t; i++)
139                 {
140                     if (name1 == triangle[i].name)
141                     {
142                         rotate(&triangle[i].p1, angle);
143                         rotate(&triangle[i].p2, angle);
144                         rotate(&triangle[i].p3, angle);
145                         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;
146                     }
147                 }
148             }
149             else cout << "comand is error!" << endl;
150             break;
151         }
152         default:{cout << "输入错误!" << endl; break; }
153
154         }
155     }
156
157     return 0;
158 }
159
160 void rotate(POINT *pt, double angle)  //逆时针为正
161 {
162     double x, y,ang;
163     x = pt->x;
164     y = pt->y;
165     ang = angle*3.1415926 / 180;
166     pt->x = x*cos(ang) - y*sin(ang);
167     pt->y = x*sin(ang) + y*cos(ang);
168 }

运行结果:

时间: 2024-10-12 16:50:11

Code for the Homework1的相关文章

Code for the Homework1 改进

1 #include <iostream> 2 #include <vector> 3 #include "shape.h" 4 //using namespace std; 5 //using namespace Eigen; 在shape.h中 6 const double PI=3.141592653; 7 vector<SHAPE*> sv; 8 vector<SHAPE*>::iterator itr; 9 POINT p; 1

python code 1_username registration &amp; login

This tiny program consists of 2 parts - registration and login. In the part of registration, the key point is to create a folder to store user's information.  And the part that cost my most time is how to name a file automatically with variety's name

从微信官方获取微信公众号名片:http://open.weixin.qq.com/qr/code/?username=haihongruanjian

从微信官方获取微信公众号名片:http://open.weixin.qq.com/qr/code/?username=haihongruanjian 个人的号,不知道怎么获取.

微信 {&quot;errcode&quot;:40029,&quot;errmsg&quot;:&quot;invalid code, hints: [ req_id: Cf.y.a0389s108 ]&quot;}

{"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"} 问题:微信网页授权后,获取到 openid 了,一刷新又没了 微信网页授权获取到的 code 只能使用一次(5分钟内有效),使用一次后,马上失效. 页面授权跳转成功,根据 code 也换取到 openid 了. 此时刷新页面,并不会再次进行授权,而是直接刷新了一下上一次授权跳转后的链接,带的还是

在linux系统中安装VSCode(Visual Studio Code)

1.从官网下载压缩包(话说下载下来解压就直接可以运行了咧,都不需要make) 访问Visual Studio Code官网 https://code.visualstudio.com/docs?dv=linux64 我是64位的: wget https://az764295.vo.msecnd.net/stable/7ba55c5860b152d999dda59393ca3ebeb1b5c85f/code-stable-code_1.7.2-1479766213_amd64.tar.gz 2.解

set up trace code tool

這以 GNU GLOBAL 6.5.6 為示範 1: install GNU GLOBAL https://www.gnu.org/software/global/download.html sudo ./configure; 若有以下 error,請看更下方的 Q5 說明. configure: checking "location of ncurses.h file"... configure: error: curses library is required but not f

Ubuntu16.04下安装VS Code

在Ubuntu下面安装Visual Studio Code sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make sudo apt-get update sudo apt-get install ubuntu-make umake web visual-studio-code 终于又看见亲切的大麻花了

CSDN code使用教程之git用法详解

首先需要下载GIT客户端,http://git-scm.com/downloads...   然后再code.csdn.net上面创建一个项目,如果 你的项目已经存在,那么请建立项目的时候不要选择自动生成readme文件.填写项目名称,去掉下面的勾勾,然后点击创建就OK了. 下面的就是配置本地客户端了,确认你在CSDN id,获取的方式是在登录后,进入passport.csdn.net,在"个人帐号"的最下端查看用户名:也就是你的昵称,我的就是Linux_Google 然后在命令行中输

.NET跨平台之mac 下vs code 多层架构编程

合肥程序员群:49313181.    合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入,申请备注填写姓名+技术+工作年限) Q  Q:408365330     E-Mail:[email protected] 概述: 为了研究跨平台.NET 开发,我打算利用.NET core 编写一个跨平台的cms,这个CMS我也秉着开源的原则放到github上面,为.NET 开源社区做点小小的贡献吧.如果有兴趣的可以联系我一起为.NET开源和跨平台做点小小的贡献吧.EgojitCMS传送