第一次编程作业
2015-11-30 23:25
281 查看
程序还是有点小问题,并不会!
#include <iostream> #include <stdlib.h> #include <Eigen/Dense> #include <math.h> using namespace std; using Eigen::MatrixXd; MatrixXd select(char str[]) { MatrixXd b(1,2); int u; int i,j; char a[10]; for(i=0;i<=49&&str[i]!='(';i++); for(j=0;j<=49&&str[j]!=',';j++); for(u=0;u<=10&&i!=j-1;u++) { i++; a[u]=str[i]; } b(0,0)=atof(a); for(i=j;i<=49&&str[i]!=')';i++); for(u=0;u<=10&&j!=i-1;u++) { j++; a[u]=str[j]; } b(0,1)=atof(a); return b; } int main() { char Name[15]; int n; double avg,deg; float pi=3.14159265; char str1[20]; char str2[20]; char str3[20]; char str4[15]; char str5[15]; char str6[15]; MatrixXd rot(2,2); MatrixXd spot1(1,2); MatrixXd spot2(1,2); MatrixXd spot3(1,2); MatrixXd spot4(1,2); cout<<"please input "; cin>>Name; cin>>n; switch(n) { case 1: { cin>>str1; spot1=select(str1); } break; case 2: { cin>>str1; spot1=select(str1); cin>>str2; spot2=select(str2); } break; case 3: { cin>>str1; spot1=select(str1); cin>>str2; spot2=select(str2); cin>>str3; spot3=select(str3); } break; default:cout<<"output error"; } cout<<"please input method of operation"<<endl; cin>>str4; if(str4[0]=='m'&&str4[1]=='o'&&str4[2]=='v'&&str4[3]=='e'&&str4[4]==0) { cin>>str5; cin>>str6; spot4=select(str6); if(n==1) { spot1=spot1+spot4; cout<<"("<<spot1<<")"<<endl; } else if(n==2) { spot1=spot1+spot4; spot2=spot2+spot4; cout<<"("<<spot1<<")"<<"("<<spot2<<")"<<endl; } else { spot1=spot1+spot4; spot2=spot2+spot4; spot3=spot3+spot4; cout<<"("<<spot1<<")"<<"("<<spot2<<")"<<"("<<spot3<<")"<<endl; } } else if(str4[0]=='r'&&str4[1]=='o'&&str4[2]=='t'&&str4[3]=='a'&&str4[4]=='t'&&str4[5]=='e'&&str4[6]==0) { cin>>str5; cin>>avg; deg=avg/180*pi; rot(0,0)=cos(deg); rot(0,1)=sin(deg); rot(1,0)=-sin(deg); rot(1,1)=cos(deg); if(n==1) { spot1=spot1*rot; cout<<"("<<spot1<<")"<<endl; } else if(n==2) { spot1=spot1*rot; spot2=spot2*rot; cout<<"("<<spot1<<")"<<"("<<spot2<<")"<<endl; } else { spot1=spot1*rot; spot2=spot2*rot; spot3=spot3*rot; cout<<"("<<spot1<<")"<<"("<<spot2<<")"<<"("<<spot3<<")"<<endl; } } else { cout<<"output error"<<endl; } return 0; }
相关文章推荐
- java nio多线程引起的full gc问题
- 冒泡排序
- RxJava使用场景小结
- java设计模式之单例模式
- spring 依赖注入
- java设计模式之观察者模式
- java5线程并发库学习之Semaphore
- python核心编程-函数调用
- Java GC基本算法
- Maven 3.3.9 mvn -version Error:java.lang.UnsupportedClassVersionError
- 字符串函数汇总
- Matlab保存图像函数总结
- 关于java.lang.NoSuchMethodError的分析,产生的原因及处理方式
- 【iOS学习笔记】c语言问题
- 一种java拷贝属性的方法
- Java 7 Fork/Join 并行计算框架概览
- Java学习之路(一)了解Java
- Qt中MainWindow类实例
- ruby字符串学习笔记5
- STL运用的C++技术(2)——模板特化