当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 3 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : who can help me.
帖子发表于 : 2007-11-04 14:52 

注册: 2007-11-01 9:04
帖子: 8
送出感谢: 0 次
接收感谢: 0 次
I design a complex class to solve a dif, but have many error .who can help me?
#include <math.h>
#include <iostream>
#define N 16
#define PI 3.1415926


class complex
{
public:
double real;
double imag;
public:
complex(double r=0,double i=0)
{
real=r;
imag=i;
}

complex operator+(complex &a)
{
complex result;
result.real=a.real+real;
result.imag=a.imag+imag;
return result;
}

complex operator-(complex &a)
{
complex result;
result.real=real-a.real;
result.imag=imag-a.imag;
return result;
}

complex operator*(complex &a)
{
complex result;
result.real=a.real*real-a.imag*imag;
result.imag=a.real*imag+a.imag*real;
return result;
}

complex operator/(complex &a)
{
complex result;
result.real=(real*a.real+imag*a.imag)/(real*real+imag*imag);
result.imag=(real*a.imag-a.real*imag)/(real*real+imag*imag);
return result;
}

void display()
{
if(real!=0)
std::cout<<real;
if(imag>0)
std::cout<<"+"<<imag<<"i";
if(imag<0)
std::cout<<imag<<"i";
std::cout<<std::endl;
}
};

complex w(int a,int n)
{
complex result;
result.real=cos(2*PI/n*a);
result.imag=-sin(2*PI/n*a);
if(fabs(result.real)<0.00001)
result.real=0;
if(fabs(result.imag)<0.00001)
result.imag=0;
return result;
}

void swap(complex *t1,complex *t2,int n)
{
complex temp;
for(int i=0;i<n;i++)
{
temp=t1[i];
t1[i]=t2[i];
t2[i]=temp;
}
}

void dft(complex *p1,complex *p2,int n)
{
for(int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
p2[i]=p2[i]+p1[j]*w(j*i,n);
}
}

void dif(complex *p1,complex *p2,int n)
{
int i,j,k p,s;

for(p=2;p<n;p*=2)
{
for(j=0,k=1;j<p;k*=2,j+=k)
{
s=n/p;
for(i=0;i<s;i++)
{
p2[i+j]=p1[i+j]+p1[i+j+p];
p2[i+j+p]=p1[i+j]-p1[i+j+p]*w(i,s*2);
}
}
swap(p1,p2,n);
}
dft(p2.p1,n);
for(i=0;i<n;i++)
p1[i].display();
}

int main()
{
complex temp1[N],temp2[N];
int i;
int x[N]={1,1,2,2,3,3,4,4,1,1,2,2,0,0,0,0};

for(i=0;i<N;i++)
{
temp1[i].real=x[i];
temp1[i].imag=0;
}
complex *p1,*p2;
p1=temp1;
p2=temp2;

dif(p1,p2,N);

return 0;
}

ERROR:
main.cc: In function ‘void dft(complex*, complex*, int)’:
/home/linux/Projects/foobar-cpp/src/main.cc:114: error: no match for ‘operator*’ in ‘*(((complex*)(((unsigned int)j) * 16u)) + p1) * w((j * i), n)’
/home/linux/Projects/foobar-cpp/src/main.cc:58: note: candidates are: complex complex::operator*(complex&)
main.cc: In function ‘void dif(complex*, complex*, int)’:
/home/linux/Projects/foobar-cpp/src/main.cc:120: error: expected initializer before ‘p’
/home/linux/Projects/foobar-cpp/src/main.cc:122: error: ‘p’ was not declared in this scope
/home/linux/Projects/foobar-cpp/src/main.cc:124: error: ‘k’ was not declared in this scope
/home/linux/Projects/foobar-cpp/src/main.cc:126: error: ‘s’ was not declared in this scope
/home/linux/Projects/foobar-cpp/src/main.cc:135: error: request for member ‘p1’ in ‘p2’, which is of non-class type ‘complex*’
make[2]: *** [main.o] Error 1
make[2]: Leaving directory `/home/linux/Projects/foobar-cpp/src'
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
make[1]: Leaving directory `/home/linux/Projects/foobar-cpp'
Completed... unsuccessful


页首
 用户资料  
 
2 楼 
 文章标题 :
帖子发表于 : 2007-11-04 15:12 

注册: 2007-11-01 9:04
帖子: 8
送出感谢: 0 次
接收感谢: 0 次
the question is work out , i want to ask the another question.
how to setup the chinese input?


页首
 用户资料  
 
3 楼 
 文章标题 :
帖子发表于 : 2007-11-04 16:50 

注册: 2006-12-02 8:58
帖子: 125
送出感谢: 0 次
接收感谢: 0 次
may be scope error ?
yes ,you know cout must write as std:cout
but,there is so much place that you must be careful !

if this program is work good at Windows or mac
i think if you change your c++ complie ,you can do it success to
last week, I do a project , if i use gcc *.cpp,there is so much error
but ,if i use g++ *.c ,It work!

setup chinese input ?
I suggest you can open http://wiki.ubuntu.org.cn 点击链接(你的版本)快速设置指南


_________________
http://www.ieager.com/
我的blog。linux学习


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 3 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译