Chapter 1, Page 6 - Random1.h

This forum is to discuss the book "C++ design patterns and derivatives pricing."

Chapter 1, Page 6 - Random1.h

Postby quantfinance » Mon Jan 17, 2011 6:59 pm

I am a beginner and using Code::Blocks to compile the code in this book. My first issue in Chapter 1 is that I am receiving an error because of Random1.h - 'No such file or directory'.
I am confused how to change my settings to include this header file as you discuss on page 6?

Do I need to put the code in Listing 1.2 (Random1.h) and Listing 1.3(Random1.cpp) in different files, or do they just go at the bottom of the code in Listing 1.1?

Thanks for your help.
quantfinance
 
Posts: 22
Joined: Sun Nov 14, 2010 2:44 pm

Re: Chapter 1, Page 6 - Random1.h

Postby mj » Mon Jan 17, 2011 10:58 pm

you should not merge files.

You need to create a project and put all the relevant cpp files in it.

You also need to figure out how to specify include directories using code::blocks. It is not one of my standard applications so i don't know how to do it.
mj
Site Admin
 
Posts: 1337
Joined: Fri Jul 27, 2007 7:21 am

Re: Chapter 1, Page 6 - Random1.h

Postby quantfinance » Mon Jan 17, 2011 11:52 pm

Thank you so much for your help.

So Listing 1.2 and 1.3 should both be seperate .cpp files?

Do you know what type of project I need to create - there are 20+ categories such as (ARM, AVR, Direct/X, GTK+, Matlab, Code::Blocks Plugin, SDL, etc. etc.)

What compiler do you reccomend as I am fine with switching from Code::Blocks?

Thank you.
quantfinance
 
Posts: 22
Joined: Sun Nov 14, 2010 2:44 pm

Re: Chapter 1, Page 6 - Random1.h

Postby mj » Tue Jan 18, 2011 12:02 am

each main program file has a list of required files. Your project should contain these.

The usual solution is to use Visual Studio 9 or 10 with a console application.

The express versions are free for everyone. The professional versions are free for students via the Dreamspark program.
mj
Site Admin
 
Posts: 1337
Joined: Fri Jul 27, 2007 7:21 am

Re: Chapter 1, Page 6 - Random1.h

Postby quantfinance » Fri Jan 21, 2011 11:55 pm

Thank you for your help. I am now on VS 2010, however, there are some changes to the settings from previous VS versions and you can no longer change the Include Directory in the Tools - Options.
http://blogs.msdn.com/b/vsproject/archive/2009/07/07/vc-directories.aspx

So to change the directory, I went to the Property Mgr, and selected the properties. Under Config Properties I selected VC++ Directories and went to Edit the 'Include Directories'. However, what path do I edit this to? In the book it says C/include? I am not sure what that means. I tried a couple different paths and none of them worked.

Your help would be GREATLY appreciated.
Thanks.
quantfinance
 
Posts: 22
Joined: Sun Nov 14, 2010 2:44 pm

Re: Chapter 1, Page 6 - Random1.h

Postby mj » Sat Jan 22, 2011 6:28 am

just put the complete name of the directory which has the include files in it.
mj
Site Admin
 
Posts: 1337
Joined: Fri Jul 27, 2007 7:21 am

Re: Chapter 1, Page 6 - Random1.h

Postby quantfinance » Sat Jan 22, 2011 2:07 pm

I am sorry for my beginner questions but I am so confused and have been trying everything to get this to work.
These are the errors I am getting:
1> SimpleMCMain1.cpp
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\monte carlo - joshi book p. 3\monte carlo - joshi book p. 3\simplemcmain1.cpp(3): fatal error C1083: Cannot open include file: 'Random1.h': No such file or directory
1> Random1.cpp
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\monte carlo - joshi book p. 3\monte carlo - joshi book p. 3\random1.cpp(1): fatal error C1083: Cannot open include file: 'Random1.h': No such file or directory

I have tried to change the Include directory. I changed it to:
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Monte Carlo - Joshi Book P.3\Monte Carlo - Joshi Book P.3\Debug

I also tried changing it to:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl

I also tried using both of them at the same time, however neither of these methods worked. Please advise on what NAME of the directory I should be using as I am very confused?

When I changed <Random1.h> to "Random1.h" , I was able to build the solution successfully so I know the code is correct. However, I would like to solve correctly with <Random1.h> as you have intended.

Thank you so much for your time and help.
quantfinance
 
Posts: 22
Joined: Sun Nov 14, 2010 2:44 pm

Re: Chapter 1, Page 6 - Random1.h

Postby mj » Sat Jan 22, 2011 8:55 pm

you have to use the complete name of the folder that has random1.h in it.
mj
Site Admin
 
Posts: 1337
Joined: Fri Jul 27, 2007 7:21 am

Re: Chapter 1, Page 6 - Random1.h

Postby miao » Wed Aug 07, 2013 8:02 am

Hi,

I am new to C++ but have knowledge of Matlab and R as well as mathematical finance. I wonder how to run the first program in the book. I tried to follow the posts in this section. I use Visual Studio 2012 on Win 7.

First of all, I open a new project by FILE --> New Project --> Visual C++ Win 32 console application. The file name provided is "ConsoleApplication3". It comes with two header files stdafx.h and targetver.h and one source file stdafx.cpp. Deleting them seems to incur some problems, so I add the files back to the project after deletion. (Should I delete them?)

Then I add Random1.h to the list of header file list, and Random1.cpp and SimpleMCMain1.cpp to the source file list. Now I have three header files and three source files.

Then I add an "include directory" by
Debug --> ConsoleApplication3 Properties --> Configuration Property --> VC++ directory --> include directory --> add the directory "C:\Users\[my user name]\Documents\Visual Studio 2012\Projects\ConsoleApplication3\ConsoleApplication3"

Then I BUILD --> BUILD SOLUTION (F7), but some errors emerge

Error 1 error C1083: Cannot open precompiled header file: 'Debug\ConsoleApplication3.pch': No such file or directory c:\users\miao\documents\visual studio 2012\projects\consoleapplication3\consoleapplication3\stdafx.cpp 5 1 ConsoleApplication3

Error 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? c:\users\miao\documents\visual studio 2012\projects\consoleapplication3\consoleapplication3\simplemcmain1.cpp 102 1 ConsoleApplication3

Error 3 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? c:\users\miao\documents\visual studio 2012\projects\consoleapplication3\consoleapplication3\random1.cpp 71 1 ConsoleApplication3

It seems to mean that I should '#include "stdafx.h" in the cpp programs. Even if I include the line in the two cpp programs provided by Dr Joshi, there are still errors. Again I BUILD --> BUILD SOLUTION (F7),

Error 1 error C1083: Cannot open precompiled header file: 'Debug\ConsoleApplication3.pch': No such file or directory c:\users\miao\documents\visual studio 2012\projects\consoleapplication3\consoleapplication3\stdafx.cpp 5 1 ConsoleApplication3

Error 2 error C1083: Cannot open precompiled header file: 'Debug\ConsoleApplication3.pch': No such file or directory c:\users\miao\documents\visual studio 2012\projects\consoleapplication3\consoleapplication3\simplemcmain1.cpp 11 1 ConsoleApplication3

Error 3 error C1083: Cannot open precompiled header file: 'Debug\ConsoleApplication3.pch': No such file or directory c:\users\miao\documents\visual studio 2012\projects\consoleapplication3\consoleapplication3\random1.cpp 11 1 ConsoleApplication3

Could someone help me how to make the programs work in Visual Studio 2012?

Thanks!

Miao
miao
 
Posts: 2
Joined: Wed Aug 07, 2013 7:32 am

Re: Chapter 1, Page 6 - Random1.h

Postby mj » Wed Aug 07, 2013 8:47 am

when you create a new project, make sure to click on application settings and untick "precompiled headers"
also delete any includes of stdafx.h
mj
Site Admin
 
Posts: 1337
Joined: Fri Jul 27, 2007 7:21 am

Re: Chapter 1, Page 6 - Random1.h

Postby miao » Thu Aug 08, 2013 5:40 am

Dear Dr Joshi,

Thank you very much. My program runs successfully.

1. Do the presence of the two lines
Code: Select all
    double tmp;
    cin >> tmp;

after the option price is printed is just to hold the DOS screen, letting the user clearly see the results? Does it work similarly to the line

Code: Select all
system(“PAUSE”);


?

Another issue is the layout of the output presented.
2. Is it possible to present the output in a duplicable way, e.g., in the console window? Texts in DOS could not be copied.
3. Could Visual Studio or any other C++ platform present all the numerical variables computed in the program, as Matlab does?
Thanks!

Miao
miao
 
Posts: 2
Joined: Wed Aug 07, 2013 7:32 am

Re: Chapter 1, Page 6 - Random1.h

Postby mj » Mon Aug 12, 2013 3:55 am

it is simply to pause, it is more portable than SYSTEM

If you want nicer output I'd suggest using xlw to interface with EXCEL. This is discussed towards the end of the second edition.
mj
Site Admin
 
Posts: 1337
Joined: Fri Jul 27, 2007 7:21 am


Return to C++ design patterns and derivatives pricing

Who is online

Users browsing this forum: No registered users and 0 guests