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

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;
}
...全文
177 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是小写
访问真八字排盘系统介绍: 1、八字排盘 八字排盘是将年月日时按照天干地支的形式进行排列,一个时间单位代表了一个柱。八字由年柱、月柱、日柱和时柱共四个柱组成,也被称为四柱八字。八字学中基于中国阴阳五行、天干地支与刑冲克害、以及民间盲派的神煞论等方式,进一步预测爱情顺遂、工作高低、姻缘好坏、财富高低、学业成就、身体健康等事的学问。 八字排盘由以下元素组合:年月日时四柱、大运干支、胎元 、流年干支、十神、地势、神煞等。生辰八字不只是把干支历计算出来,而还要遵守月令、节令的强弱,时辰的阴阳变化进行校正。排盘分析,就是根据出生者的性别、天干地支的阴阳五行关系、进一步推算出来的一套方法论,给预测者做人生吉凶的参考数据,在未来事业、财运、婚姻、家庭等问题时,能做出风险较低的决策。 八字排盘怎么看 八字排盘由年、月、日、时四柱组成,每柱包含一个天干和一个地支,共八个字。年柱代表出生的年份,月柱代表出生的月份,日柱代表出生的日期,时柱则代表出生的时辰。每个柱的干支组合都会对个人的命运产生影响。天干地支旁边标注的正财、偏财、偏印、正印、比肩、劫财、食神、伤官、正官、七杀等,称为十神。 2、八字排盘软件介绍 我们是腾讯云市场金牌合作伙伴,广州正规软件开发公司,开发的八字排盘系统数据最全面精准,我们八字排盘采用最精确的排盘程序,而且运用“真太阳时”,进行更精确的时间划分。大家都知道我们使用的北京时间,是统一规定的标准时间。而八字排盘需要相对于太阳方位的天文时间,即平太阳时。我们国家地大物博,北京时间19时,哈尔滨已经夜幕降临,而新疆却还是太阳高挂,这时哈尔滨的天文时间可能在20:00以后,而新疆的天文时间可能在16时以前。北京时间是东经120度经线的平太阳时,如果您出生地的经度与北京时间所处的经度差异较大,或者处于单数时间点的前后,比如6点差一刻,8点,10点15分等

33,321

社区成员

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

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