Code for the Homework1 改进
#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 改进的更多相关文章
- Code alignment 代码对齐改进(VS2017)
In mathematics you always keep your equals lined up directly underneath the one above. It keeps it c ...
- Code for the Homework2 改进
1. 实现了到指定点各个关节的转角计算(多解性),并且所求解满足各个关节的最大角和最小角的限制条件. 2. 对方向向量进行了单位化,保证任意大小的向量都行 #include<iostream&g ...
- Code for the Homework1
作业要求: http://www.cnblogs.com/bingc/p/4919692.html 代码(未使用Eigen): #include <iostream> #include & ...
- PHP5.4最新特性
PHP5.4最新特性 官网:ChangeLog-5.php#5.4.0 原文Oracle:LAMP 体系有了新的竞争,但此版本中的特性使 PHP 再次挑战极限. 稍微做了修改.: 概述总结:1. ...
- 《精通python网络爬虫》笔记
<精通python网络爬虫>韦玮 著 目录结构 第一章 什么是网络爬虫 第二章 爬虫技能概览 第三章 爬虫实现原理与实现技术 第四章 Urllib库与URLError异常处理 第五章 正则 ...
- iOS开发 - 开发版+企业版无线发布一键打包
背景:项目进入快速迭代期,需要快速地交付出AdHoc版本和企业无线发布版本.每次打包都要来回切换bundle identifier和code signing,浪费很多时间. 示例项目名称名称为Test ...
- 3D-camera结构光原理
3D-camera结构光原理 目前主流的深度探测技术是结构光,TOF,和双目.具体的百度就有很详细的信息. 而结构光也有双目结构光和散斑结构光等,没错,Iphone X 的3D深度相机就用 散斑结构光 ...
- 算法所产生的性能改进已经超过了硬件所带来的性能提升 The future is algorithms, not code
w 大数据的发展,伴随的将是软件工程师的渐退,算法工程师的崛起 http://mp.weixin.qq.com/s/XTz2HnzwlgTD3g5zU2u5Tg
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
随机推荐
- [改善Java代码]优先使用整型池
建议28: 优先使用整型池 看如下代码: public class Client { public static void main(String[] args) { Scanner input = ...
- .NET学习笔记(1)— C#学习路线图
目录 一:引言 二:.NET技术体系 三:常用工具汇总 四:学习资源汇总 五:书籍推荐 六:关于阅读技术书籍的经验 七:总结 一:引言 因为工作调整,从PHP开发零基础转型到.NET开发,前期没有 ...
- 今天学习css一些动画效果
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...
- Redis 命令 - Sorted Sets
ZADD key score member [score member ...] Add one or more members to a sorted set, or update its scor ...
- 自定义实现简单的Android颜色选择器(附带源码)
在写Android App过程中需要一个简单的颜色选择器,Android自带的ColorPicker和网上的一些ColorPicker都太高端了,都实现了颜色渐变功能,我要的不需要那么复杂,只想提供几 ...
- Javascript之响应式相册
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- Java之绘制实例
前面已经介绍过绘制方法. 弧形的绘制: package com.caiduping; import java.awt.Graphics; import javax.swing.JFrame; impo ...
- php如何判断是否为json数据(格式)
首先要记住json_encode返回的是字符串, 而json_decode返回的是对象. 判断数据不是JSON格式: 代码如下 复制代码 function is_not_json($str){ ...
- JDBC(用Eclipse操作数据库Oracle)的基础操作集合
JDBC: JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编 ...
- 第五十九篇、OC录制小视频
用 AVCaptureSession + AVCaptureMovieFileOutput 来录制视频,并通过AVAssetExportSeeion 手段来压缩视频并转换为 MP4 格 AVFound ...