大家帮我看看为什么这个程序编译不出来呢?

jojogh 2008-08-28 08:06:21
小弟是个刚学C++的新手,现编了如下程序,用VC++编译的时候出现了如下提示,大家能帮我看看错在哪里么,谢谢:
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(5) : error C2146: syntax error : missing ';' before identifier 'Option_Price'
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(5) : error C2501: 'Class' : missing storage-class or type specifiers
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(5) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

2008_08_27.obj - 3 error(s), 0 warning(s)

#include<iostream.h>
#include<math.h>
#include<iomanip>
using namespace std;
Class Option_Price {
double Spot_Price, Strike_Price, Inerest_Rate, Vol, Time;
public:
double CND(double x);
double CallOption(double S, double X, double r, double sigma, double t);
};
//------------------------------------------------------------------------------------------------------
double Option_Price::CND(double x){
const double b1 = 0.319381530;
const double b2 = -0.356563782;
const double b3 = 1.781477937;
const double b4 = -1.821255978;
const double b5 = 1.330274429;
const double p = 0.2316419;
const double c = 0.39894228;
double prob;
if(x >= 0.0)
{
double t = 1.0 / ( 1.0 + p * x );
prob=(1.0 - c * exp( -x * x / 2.0 ) * t *
( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 ))<<endl;
}
else
{
prob=double t = 1.0 / ( 1.0 - p * x );
( c * exp( -x * x / 2.0 ) * t *
( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 ))<<endl;
}
return prob;

};
//------------------------------------------------------------------------------------------------------

double Option_Price::CallOption(){
Spot_Price=S;
Strike_Price=X;
Inerest_Rate=r;
Vol=sigma;
Time=t;
double d1=(log(S/X)+r*t)/(sigma*sqrt(t))+0.5*sigma*sqrt(t);
double d2=d1-(sigma*sqrt(t));
double c=S*Option_Price::CND(d1)-X*exp(-r*t)*Option_Price::CND(d2);
return c;
}

double main(){
S=100;
X=90;
r=0.05;
sigma=0.3;
t=5;
OptionPrice Call;
cout<<Call.Call_Option(S,X,r,sigma,t)<<endl;
return 0;
}
...全文
179 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jojogh 2008-08-29
  • 打赏
  • 举报
回复
好了,谢谢您!
雪鹰翔天 2008-08-28
  • 打赏
  • 举报
回复
上面回答完了
我就是来看看的...
太乙 2008-08-28
  • 打赏
  • 举报
回复
好了么?
K行天下 2008-08-28
  • 打赏
  • 举报
回复

#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
class Option_Price
{
double Spot_Price, Strike_Price, Inerest_Rate, Vol, Time;
public:
double CND(double x);
double CallOption(double S, double X, double r, double sigma, double t);
};
//------------------------------------------------------------------------------------------------------
double Option_Price::CND(double x)
{
const double b1 = 0.319381530;
const double b2 = -0.356563782;
const double b3 = 1.781477937;
const double b4 = -1.821255978;
const double b5 = 1.330274429;
const double p = 0.2316419;
const double c = 0.39894228;
double prob;

if(x >= 0.0)
{
double t = 1.0 / ( 1.0 + p * x );
prob=(1.0 - c * exp( -x * x / 2.0 ) * t *( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )) ;
}
else
{
double prob= 1.0 / ( 1.0 - p * x );
//( c * exp( -x * x / 2.0 ) * t *( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )) <<endl;
}

return prob;

};
//------------------------------------------------------------------------------------------------------

double Option_Price::CallOption(double S, double X, double r, double sigma, double t)
{
Spot_Price=S;
Strike_Price=X;
Inerest_Rate=r;
Vol=sigma;
Time=t;
double d1=(log(S/X)+r*t)/(sigma*sqrt(t))+0.5*sigma*sqrt(t);
double d2=d1-(sigma*sqrt(t));
double c=S*Option_Price::CND(d1)-X*exp(-r*t)*Option_Price::CND(d2);
return c;
}

int main()
{
int S=100;
int X=90;
double r=0.05;
double sigma=0.3;
int t=5;
Option_Price Call;
cout <<Call.CallOption(S,X,r,sigma,t) <<endl;
return 0;
}

jojogh 2008-08-28
  • 打赏
  • 举报
回复
是能编译了,但是结果好像不太对,我再看看!
wangdeqie 2008-08-28
  • 打赏
  • 举报
回复

#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
class Option_Price
{
double Spot_Price, Strike_Price, Inerest_Rate, Vol, Time;
public:
double CND(double x);
double CallOption(double S, double X, double r, double sigma, double t);
};
//------------------------------------------------------------------------------------------------------
double Option_Price::CND(double x)
{
const double b1 = 0.319381530;
const double b2 = -0.356563782;
const double b3 = 1.781477937;
const double b4 = -1.821255978;
const double b5 = 1.330274429;
const double p = 0.2316419;
const double c = 0.39894228;
double prob;

if(x >= 0.0)
{
double t = 1.0 / ( 1.0 + p * x );
//prob=(1.0 - c * exp( -x * x / 2.0 ) * t *( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )) <<endl;
}
else
{
double prob= 1.0 / ( 1.0 - p * x );
//( c * exp( -x * x / 2.0 ) * t *( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )) <<endl;
}

return prob;

};
//------------------------------------------------------------------------------------------------------

double Option_Price::CallOption(double S, double X, double r, double sigma, double t)
{
Spot_Price=S;
Strike_Price=X;
Inerest_Rate=r;
Vol=sigma;
Time=t;
double d1=(log(S/X)+r*t)/(sigma*sqrt(t))+0.5*sigma*sqrt(t);
double d2=d1-(sigma*sqrt(t));
double c=S*Option_Price::CND(d1)-X*exp(-r*t)*Option_Price::CND(d2);
return c;
}

int main()
{
int S=100;
int X=90;
double r=0.05;
double sigma=0.3;
int t=5;
Option_Price Call;
cout <<Call.CallOption(S,X,r,sigma,t) <<endl;
return 0;
}
jojogh 2008-08-28
  • 打赏
  • 举报
回复
编译以后出现15个错误:
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(25) : error C2563: mismatch in formal parameter list
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(25) : error C2568: '<<' : unable to resolve function overload
could be 'class ostream &__cdecl endl(class ostream &)'
c:\program files\microsoft visual studio\vc98\include\ostream.h(144) : see declaration of 'endl'
or 'class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &__cdecl std::endl(class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &)'
c:\program files\microsoft visual studio\vc98\include\ostream(377) : see declaration of 'endl'
or 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)'
c:\program files\microsoft visual studio\vc98\include\ostream(372) : see declaration of 'endl'
or 'class std::basic_ostream<_E,_Tr> &__cdecl std::endl(class std::basic_ostream<_E,_Tr> &)'
c:\program files\microsoft visual studio\vc98\include\ostream(367) : see declaration of 'endl'
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(29) : error C2062: type 'double' unexpected
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(30) : error C2065: 't' : undeclared identifier
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(31) : error C2563: mismatch in formal parameter list
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(31) : error C2568: '<<' : unable to resolve function overload
could be 'class ostream &__cdecl endl(class ostream &)'
c:\program files\microsoft visual studio\vc98\include\ostream.h(144) : see declaration of 'endl'
or 'class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &__cdecl std::endl(class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &)'
c:\program files\microsoft visual studio\vc98\include\ostream(377) : see declaration of 'endl'
or 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)'
c:\program files\microsoft visual studio\vc98\include\ostream(372) : see declaration of 'endl'
or 'class std::basic_ostream<_E,_Tr> &__cdecl std::endl(class std::basic_ostream<_E,_Tr> &)'
c:\program files\microsoft visual studio\vc98\include\ostream(367) : see declaration of 'endl'
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(38) : error C2511: 'CallOption' : overloaded member function 'double (void)' not found in 'Option_Price'
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(5) : see declaration of 'Option_Price'
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(51) : error C2065: 'S' : undeclared identifier
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(52) : error C2065: 'X' : undeclared identifier
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(53) : error C2065: 'r' : undeclared identifier
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(54) : error C2065: 'sigma' : undeclared identifier
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(56) : error C2065: 'OptionPrice' : undeclared identifier
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(56) : error C2146: syntax error : missing ';' before identifier 'Call'
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(56) : error C2065: 'Call' : undeclared identifier
E:\Documents\ROCK\2008_08_27\2008_08_27.cpp(57) : error C2228: left of '.Call_Option' must have class/struct/union type
Error executing cl.exe.

2008_08_27.obj - 15 error(s), 0 warning(s)
jojogh 2008-08-28
  • 打赏
  • 举报
回复
汗!我再看看!
weiyijiji 2008-08-28
  • 打赏
  • 举报
回复
class的c是小写

33,320

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧