第一次软件练习
#include<iostream>
#include<stdlib.h>
#include<Eigen/Dense>
#include<math.h>
using namespace std;
using Eigen::MatrixXd;
MatrixXd exchange(char str[])
{MatrixXd p(1,2);
int i,j;
char a[10];
i=1;
j=0;
do{
a[j]=str[i];
i++;
j++;
}while(str[i]!=',');
p(0,0)=atof(a);
j=0;
i=i+1;
for(i<20&&str[i]!=')';i++;)
{a[j]=str[i];
j++;
}
p(0,1)=atof(a);
return p;
}
int main()
{
char name[10];
int n;
double deg;
const float Pi=3.1415927;
char str1[20];
char str2[20];
char str3[20];
char str4[20];
char str5[20];
char str6[20];
MatrixXd r(2,2);
MatrixXd p1(1,2);
MatrixXd p2(1,2);
MatrixXd p3(1,2);
MatrixXd p4(1,2);
cout<<"请输入类型";
cin>>name;
cin>>n;
switch(n)
{
case 1:
cin>>str1;
p1=exchange(str1);
break;
case 2:
cin>>str1;
p1=exchange(str1);
cin>>str2;
p2=exchange(str2);
break;
case 3:
cin>>str1;
p1=exchange(str1);
cin>>str2;
p2=exchange(str2);
cin>>str3;
p3=exchange(str3);
break;
default:cout<<"输入错误";
}
cout<<"请输入变换"<<endl;
cin>>str4;
if(str4[0]=='m'&&str4[1]=='o'&&str4[2]=='v'&&str4[3]=='e'&&str4[4]==0)
{
cin>>str5;
cin>>str6;
p4=exchange(str6);
if(n==1)
{
p1=p1+p4;
cout<<"("<<p1<<")"<<endl;
}
else if(n==2)
{
p1=p1+p4;
p2=p2+p4;
cout<<"("<<p1<<")"<<"("<<p2<<")"<<endl;
}
else
{
p1=p1+p4;
p2=p2+p4;
p3=p3+p4;
cout<<"("<<p1<<")"<<"("<<p2<<")"<<"("<<p3<<")"<<endl;
}
}
else if(str4[0]=='r'&&str4[1]=='0'&&str4[2]=='t'&&str4[3]=='a'&&str4[4]=='t'&&str4[5]=='e'&&str4[6]==0)
{
cin>>str5;
cin>>deg;
r(0,0)=cos(deg*Pi/180);
r(0,1)=sin(deg*Pi/180);
r(1,0)=-sin(deg*Pi/180);
r(1,1)=cos(deg*Pi/180);
if(n==1)
{
p1=p1*r;
cout<<"("<<p1<<")"<<endl;
}
else if(n==2)
{
p1=p1*r;
p2=p2*r;
cout<<"("<<p1<<")"<<"("<<p2<<")"<<endl;
}
else
{
p1=p1*r;
p2=p2*r;
p3=p3*r;
cout<<"("<<p1<<")"<<"("<<p2<<")"<<"("<<p3<<")"<<endl;
}
}
else
{cout<<"输出错误"<<endl;
}
return 0;
}
每次输入之后都是这个样子,然后把程序发给同学电脑上试一下,却又出现了另外的问题。推测可能是exchange函数出了问题,然而能力有限无法找出。