Click here to Skip to main content
15,887,083 members
Home / Discussions / C#
   

C#

 
QuestionC#.NET write to registry at installation time Pin
D i x y6-Feb-08 17:16
D i x y6-Feb-08 17:16 
GeneralRe: C#.NET write to registry at installation time Pin
Richard Blythe6-Feb-08 17:38
Richard Blythe6-Feb-08 17:38 
GeneralRe: C#.NET write to registry at installation time Pin
N a v a n e e t h6-Feb-08 19:17
N a v a n e e t h6-Feb-08 19:17 
GeneralRe: C#.NET write to registry at installation time Pin
Nouman Bhatti6-Feb-08 21:03
Nouman Bhatti6-Feb-08 21:03 
QuestionRe: C#.NET write to registry at installation time Pin
jov7-Feb-08 16:38
jov7-Feb-08 16:38 
GeneralRe: C#.NET write to registry at installation time Pin
Nouman Bhatti7-Feb-08 21:19
Nouman Bhatti7-Feb-08 21:19 
GeneralRe: C#.NET write to registry at installation time Pin
Thomas Stockwell8-Feb-08 7:34
professionalThomas Stockwell8-Feb-08 7:34 
GeneralI need help with a progra. Pin
Alex5016-Feb-08 16:52
Alex5016-Feb-08 16:52 
Could someone help me out with this program?


Draw the circle on a sheet of paper. Remember how big the paper is (how high & how wide, which gives us the total area), and how big the circle is.

2. Randomly pick points on the paper (say, by throwing darts). For each point we randomly pick, we'll do the following:

a. If the point is inside (or on the line of) the circle, we'll increment our counter that keeps track of the number of points that landed inside the circle.

b. If the point isn't inside/on the circle, and you need to, and increment another counter to keep track of that.

c. Either way, increment your "How many times did I pick a point?" counter

d. Darts that fall outside the paper are ignored entirely.
Even better would be to find a way to make sure that your randomly selected points never end up outside the paper in the first place.

3. Once you're done throwing all the darts in step 2, figure out what percentage of the darts fell inside the circle.
As an example, let's say you threw 1,000 darts, 534 of them landed inside/on the boundary of the circle, and 466 landed outside the circle, but on the paper. Thus, 53.4% of the darts landed in the circle.

4. Figure out how big the sheet of paper is (what the total area is).
As a continuing example, let's say that the paper is 100 inches wide, and 200 inches tall, for a total area of (100x200=20,000)

5. Estimate that the area of the circle to be the size of the paper, multiplied by the percentage of points that were inside the circle.
As a continuing example, we'll estimate that the size of the circle is 53.4% of 20,000, or (20,000 * .534=) 10,680 square inches.

The downside is that this is computationally intensive (i.e., you can't really do this by hand). The upside is that this works for *ANY* shape, no matter how complicated. For this homework assignment, we'll stick with circles, and only circles.

Your task is to write a program that will demonstrate how accurate this method is, depending on how many points you randomly select. Basically, you're going to go through, and use the Monte Carlo method to estimate the area of the circle, then use the real formula to find the actual area, then compare the two. The 'error' here will be measured as the percentage difference between the estimated & real circle (so if the circle is 314 units in size, and the estimate is 0, then the error is -100%, meaning that we're 100% below the real size. If the estimate is 345.4 units, then the error is +10%, meaning that we're 10% over the actual size).

An example of the output is given below. Everything that's highlighted in gray is optional output – your program isn't required to produce this output, if you don’t want to. The rest of it is required output. Make the columns of the table line up as best you can.

In addition to accomplishing the above objective, you have two additional, technical goals:

1. Use functions and methods in order to modularize your code as much as possible. If you know how to, and want to create classes here, that would be great.

2. You want to minimize the amount of code you copy-and-paste, so use an array to store the number of points to randomly select each time, and iterate through that. In the below example, there's an array that holds 1, 10, 100, 500, 1000, 5000, 10000, 50000, 100000. The objective here is that by adding numbers to / removing numbers from this array, we can quickly & easily try different numbers of points. The program should run correctly for different numbers of points, even if the only thing changed between runs are the numbers in that array. Similarly, in order to make sure that you could test out many different sized circles (and on different sized sheets of paper), make sure to set up your code so that you can change the size of the paper by changing just one (or maybe two) variables (instead of simply writing in '100' everywhere for the size of the paper), and that you can change only a few variable(s) if you want to change the location or size(radius) of the circle.

Example Output

Welcome To The MonteCarlo Circle Area Estimator!!



Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 1 randomly selected points

% of Randomly Picked Points Inside The Circle: 0

Estimated Total Area Of the Circle: 0

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 314.159265358979, which is -100% of the real circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 10 randomly selected points

% of Randomly Picked Points Inside The Circle: 0

Estimated Total Area Of the Circle: 0

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 314.159265358979, which is -100% of the real circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 100 randomly selected points

% of Randomly Picked Points Inside The Circle: 0

Estimated Total Area Of the Circle: 0

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 314.159265358979, which is -100% of the real circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 500 randomly selected points

% of Randomly Picked Points Inside The Circle: 0.026

Estimated Total Area Of the Circle: 260

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 54.1592653589793, which is -17.2394295922144% of the rea

l circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 1000 randomly selected points

% of Randomly Picked Points Inside The Circle: 0.024

Estimated Total Area Of the Circle: 240

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 74.1592653589793, which is -23.6056273158902% of the rea

l circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 5000 randomly selected points

% of Randomly Picked Points Inside The Circle: 0.0262

Estimated Total Area Of the Circle: 262

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 52.1592653589793, which is -16.6028098198468% of the rea

l circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 10000 randomly selected points

% of Randomly Picked Points Inside The Circle: 0.0301

Estimated Total Area Of the Circle: 301

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 13.1592653589793, which is -4.18872425867901% of the rea

l circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 50000 randomly selected points

% of Randomly Picked Points Inside The Circle: 0.03042

Estimated Total Area Of the Circle: 304.2

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 9.95926535897934, which is -3.17013262289088% of the rea

l circle

************************************************************

Max X: 100

Max Y: 100

Total Area of Surrounding Space: 10000

Basing our estimate on 100000 randomly selected points

% of Randomly Picked Points Inside The Circle: 0.03225

Estimated Total Area Of the Circle: 322.5

Actual Total Area Of the Circle: 314.159265358979

The estimate was off by 8.34073464102067, which is 2.65493829427249% of the real

circle

************************************************************

Max X: 100

Max Y: 100

Radius of Circle: 10

Num Points Off by (%)

1 -100%

10 -100%

100 -100%

500 -17.2394295922144%

1000 -23.6056273158902%

5000 -16.6028098198468%

10000 -4.18872425867901%

50000 -3.17013262289088%

100000 2.65493829427249%
GeneralRe: I need help with a progra. Pin
Mark Churchill6-Feb-08 17:35
Mark Churchill6-Feb-08 17:35 
GeneralRe: I need help with a progra. Pin
N a v a n e e t h6-Feb-08 19:12
N a v a n e e t h6-Feb-08 19:12 
GeneralRe: I need help with a progra. Pin
Mark Churchill6-Feb-08 21:55
Mark Churchill6-Feb-08 21:55 
QuestionRaise VB6 event from C# dll [modified] Pin
MayyMagdy6-Feb-08 11:37
MayyMagdy6-Feb-08 11:37 
QuestionUsing underline in names Pin
Kaveh Shahbazian6-Feb-08 9:56
Kaveh Shahbazian6-Feb-08 9:56 
GeneralRe: Using underline in names Pin
Ed.Poore6-Feb-08 10:32
Ed.Poore6-Feb-08 10:32 
GeneralRe: Using underline in names Pin
Gareth H6-Feb-08 11:38
Gareth H6-Feb-08 11:38 
GeneralRe: Using underline in names Pin
Not Active6-Feb-08 14:41
mentorNot Active6-Feb-08 14:41 
GeneralRe: Using underline in names Pin
PIEBALDconsult6-Feb-08 13:11
mvePIEBALDconsult6-Feb-08 13:11 
GeneralRe: Using underline in names Pin
Kaveh Shahbazian6-Feb-08 23:16
Kaveh Shahbazian6-Feb-08 23:16 
GeneralReading Arabic text from text file Pin
Member 35841536-Feb-08 9:14
Member 35841536-Feb-08 9:14 
GeneralRe: Reading Arabic text from text file Pin
Not Active6-Feb-08 9:19
mentorNot Active6-Feb-08 9:19 
GeneralRe: Reading Arabic text from text file Pin
led mike6-Feb-08 9:21
led mike6-Feb-08 9:21 
GeneralRe: Reading Arabic text from text file Pin
Guffa6-Feb-08 13:55
Guffa6-Feb-08 13:55 
GeneralAccessing members of a class in an ArrayList Pin
hpjchobbes6-Feb-08 8:59
hpjchobbes6-Feb-08 8:59 
GeneralRe: Accessing members of a class in an ArrayList Pin
led mike6-Feb-08 9:15
led mike6-Feb-08 9:15 
GeneralRe: Accessing members of a class in an ArrayList Pin
Jimmanuel6-Feb-08 9:16
Jimmanuel6-Feb-08 9:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.