这个贴发在C版一天了还是无人问津,一阵郁闷!
如果大家赏脸的话,帮忙解答一下吧,也顺便去http://expert.csdn.net/Expert/topic/2111/2111282.xml?temp=.5758325
蹭分吧!唉!
/*
定积分求解。
程序如下。调试信息见最后注释。
1.调试信息中的“__cdecl”是什么意思?看不懂?
2.warning 中的'double' to 'float'是怎么回事?我没有把double转成float啊?!
3.程序还应该如何修改才能正常运行?我的程序错在什么地方?*/#include <stdio.h>
#include <math.h>float integral(float (*p),float a,float b,int n);
float fsin(float);/*声明fsin函数*/
float fcos(float);/*声明fcos函数*/
float fexp(float);/*声明fexp函数*/void main()
{
float a1,b1,a2,b2,a3,b3,c,(*p)(float);
int n=20;
printf("Input a1,b1:"); /*输入求 sin x 定积分的下限和上限*/
scanf("%f,%f",&a1,&b1);
printf("Input a2,b2:");/*输入求 cos x 定积分的下限和上限*/
scanf("%f,%f",&a2,&b2);
printf("Input a2,b2:");/*输入求exp(x)定积分的下限和上限*/
scanf("%f,%f",&a3,&b3);
p=fsin;
c=integral(p,a1,b1,n); /*求出sinx的定积分*/
printf("The integral of sin(x) is :%f\n",c);
p=fcos;
c=integral(p,a2,b2,n);/*求出cosx的定积分*/
printf("The integral of cos(x) is :%f\n",c);
p=fexp;
c=integral(p,a3,b3,n);/*求出exp(x)的定积分*/
printf("The integral of exp(x) is :%f\n",c);
}float integral(float (*p)(float),float a,float b,int n)/*用矩形法求定积分的通用函数*/
{ int i;
float x,h,s;
h=(b-a)/n;
x=a;
s=0;
for(i=1;i<=n;i++)
{ x=x+h;
s=s+(*p)(x)*h;
}
return s;
}float fsin(float x)
{ return sin(x);
}float fcos(float x)
{ return cos(x);
}float fexp(float x)
{ return exp(x);
}/*===========================*/
/*
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(30) : error C2664: 'integral' : cannot convert parameter 1 from 'float (__cdecl *)(float)' to 'float *'
There is no context in which this conversion is possible
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(33) : error C2664: 'integral' : cannot convert parameter 1 from 'float (__cdecl *)(float)' to 'float *'
There is no context in which this conversion is possible
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(36) : error C2664: 'integral' : cannot convert parameter 1 from 'float (__cdecl *)(float)' to 'float *'
There is no context in which this conversion is possible
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(54) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(58) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(62) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
Error executing cl.exe.test.obj - 3 error(s), 3 warning(s)
*/
如果大家赏脸的话,帮忙解答一下吧,也顺便去http://expert.csdn.net/Expert/topic/2111/2111282.xml?temp=.5758325
蹭分吧!唉!
/*
定积分求解。
程序如下。调试信息见最后注释。
1.调试信息中的“__cdecl”是什么意思?看不懂?
2.warning 中的'double' to 'float'是怎么回事?我没有把double转成float啊?!
3.程序还应该如何修改才能正常运行?我的程序错在什么地方?*/#include <stdio.h>
#include <math.h>float integral(float (*p),float a,float b,int n);
float fsin(float);/*声明fsin函数*/
float fcos(float);/*声明fcos函数*/
float fexp(float);/*声明fexp函数*/void main()
{
float a1,b1,a2,b2,a3,b3,c,(*p)(float);
int n=20;
printf("Input a1,b1:"); /*输入求 sin x 定积分的下限和上限*/
scanf("%f,%f",&a1,&b1);
printf("Input a2,b2:");/*输入求 cos x 定积分的下限和上限*/
scanf("%f,%f",&a2,&b2);
printf("Input a2,b2:");/*输入求exp(x)定积分的下限和上限*/
scanf("%f,%f",&a3,&b3);
p=fsin;
c=integral(p,a1,b1,n); /*求出sinx的定积分*/
printf("The integral of sin(x) is :%f\n",c);
p=fcos;
c=integral(p,a2,b2,n);/*求出cosx的定积分*/
printf("The integral of cos(x) is :%f\n",c);
p=fexp;
c=integral(p,a3,b3,n);/*求出exp(x)的定积分*/
printf("The integral of exp(x) is :%f\n",c);
}float integral(float (*p)(float),float a,float b,int n)/*用矩形法求定积分的通用函数*/
{ int i;
float x,h,s;
h=(b-a)/n;
x=a;
s=0;
for(i=1;i<=n;i++)
{ x=x+h;
s=s+(*p)(x)*h;
}
return s;
}float fsin(float x)
{ return sin(x);
}float fcos(float x)
{ return cos(x);
}float fexp(float x)
{ return exp(x);
}/*===========================*/
/*
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(30) : error C2664: 'integral' : cannot convert parameter 1 from 'float (__cdecl *)(float)' to 'float *'
There is no context in which this conversion is possible
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(33) : error C2664: 'integral' : cannot convert parameter 1 from 'float (__cdecl *)(float)' to 'float *'
There is no context in which this conversion is possible
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(36) : error C2664: 'integral' : cannot convert parameter 1 from 'float (__cdecl *)(float)' to 'float *'
There is no context in which this conversion is possible
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(54) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(58) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
D:\Documents and Settings\Administrator\My Documents\test\test\test.cpp(62) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
Error executing cl.exe.test.obj - 3 error(s), 3 warning(s)
*/
解决方案 »
- 关于学习方向的困惑
- 请问在没有安装vs2008的windows上运行vs2008做的程序需要什么文件?
- 请教关于MPEG4 hint track的问题, 180分!!!。
- **** 如何用VC(最好用API),实现类似于 outlook express 打开邮件,同一界面上不同语言、字符集的显示问题!****
- 求水晶报表免费的下载地址~~~发言有分!!!
- 请教如何让长文本折行?
- 怎样实现在工具栏上加入LOGO动画?100分大放送!!
- 【求助】关于MFC硬件编程 unhandled exception 问题
- DXDRAW中的透明BLIT操作,需要的步骤!送分题,100分!
- MFC中使用OpenGL深度测试后图像无法显示
- 哪位大虾有提取bmp图象骨架线的代码借我一观
- 保存bmp文件的时候,如何让保存对话框默认为.bmp??
float integral(float (*p)(float),float a,float b,int n);float fsin(float);/*声明fsin函数*/
float fcos(float);/*声明fcos函数*/
float fexp(float);/*声明fexp函数*/
实际上是float integral(float (*p)(),float a,float b,int n);的错误。因为float (*p)实际上是一个float指针不是函数指针,float (*p)()才是函数指针。但是也要改成
float integral(float (*p)(float),float a,float b,int n)
这是因为 C 与 C++ 在解释函数声明中的空白括号方面存在着根本的不同。C 中的函数声明方式如下: int (*funcptr)();
它声明一个接受未知数目的参数的函数。在 C++ 中,这一声明却表示一个不接受任何参数的函数。换言之,该语句在 C++ 中等同于: int (*funcptr)(void);
2、要把
return sin(x);改成return sinf(x);return cos(x);改成return cosf(x);
return exp(x);改成return expf(x);
我看不懂那个意思啊
点搜索啊
1.Argument-passing <-->order Right to left 2.Stack-maintenance responsibility <-->Calling function pops the arguments from the stack 3.Name-decoration convention <-->Underscore character (_) is prefixed to names 4.Case-translation convention <-->No case translation performed Note For related information, see Decorated Names.
Place the __cdecl modifier before a variable or a function name. Because the C naming and calling conventions are the default, the only time you need to use __cdecl is when you have specified the /Gz (stdcall) or /Gr (fastcall) compiler option. The /Gd compiler option forces the __cdecl calling convention.Example
In the following example, the compiler is instructed to use C naming and calling conventions for the system function:// Example of the __cdecl keyword on function
_CRTIMP int __cdecl system(const char *);
// Example of the __cdecl keyword on function pointer
typedef BOOL (__cdecl *funcname_ptr)(void * arg1, const char * arg2, DWORD flags, ...);
END Microsoft SpecificSee Also
Argument Passing and Naming Conventions | C++ Keywords