HOW TO MAKE THIS console application in C#.NET or VB.NET

G

Guest

The objective:
Develop a program that can calculate the equivalent resistance for a network
of interconnected resistors.

The theory:
A ‘Resistor’ is an electrical device that resists current flowing through
it. It is indicated as below:

----/\/\/\/----

The ‘resistance’ is measured in Ohms.

Resistors can be connected together. A series connection is as below:

----/\/\/\/--------/\/\/\/----
A R1 B R2 C

The resistors R1 and R2 are in series because they are connected end to end
(at point B) and no other resistor is connected to point B.

The total resistance between points A and C is R = R1+R2
[Resistances in series are added together]. On the same lines…

----/\/\/\/--------/\/\/\/--------/\/\/\/----
A R1 B R2 C R3 D

The total resistance between A and D is R1+R2+R3

A Parallel connection is as below:

+----/\/\/\/----+
----+ R1 +-------
A +----/\/\/\/----+ B
R2

The resistors R1 and R2 are in parallel because both ends of the two
resistors are connected together.

The total resistance (R) between A and B is
1 1 1
--- = --- + ---
R R1 R2

If three resistors R1, R2, R2 are in parallel then …
1 1 1 1
--- = --- + --- + ---
R R1 R2 R3

More complex connections are possible …

+----/\/\/\/----+
----+ R1=10 ohms +-------/\/\/\/-------
A +----/\/\/\/----+ B R3=25 ohms C
R1=20 ohms

To find total resistance between A and C, first, net resistance between A
and B is

1 1 1
--- = --- + ---
R 10 20

Solving, R=6.667

Therefore net resistance = 6.667 + 25 = 31.667 Ohms

More complex examples are easily designed:

+----/\/\/\/----+
+ 25 ohms +
+----/\/\/\/----+ +----/\/\/\/----+
----+ 10 ohms +-------/\/\/\/-----+ 22 ohms +-----
A +----/\/\/\/----+ B 25 ohms C +----/\/\/\/----+ D
+ 20 ohms + 44 ohms +
+----/\/\/\/----+ +
+ 41 ohms +
+------------------------------/\/\/\/--------------+
25 ohms
This circuit is analysed as follows:
a. Find the equivalent resistance between A and B. [All resistances in
parallel].
b. Find the equivalent resistance between C and D. [All resistances in
parallel].
c. Find equivalent series resistance between AB, BC, CD. The equivalent
resistance between AB and CD are calculated above.
d. Find net resistance by the equivalent of the parallel resistances between
AB. One resistance was calculated in step (c). The other is the 25 Ohm
resistance in the problem.

Sometimes, resistances are neither in series nor in parallel. The resistors
are then either in delta or Wye (or star).


The first set of resistors (R1, R2, R3) is in a Wye(or star) configuration.
The next set (RA, RB, RC) is in a delta configuration. Assume that other
resistors are connected to points X,Y,Z.

You can transform resistances between X,Y,Z as follows:
[Convert Delta to Wye]
RB * RC
R1 = --------------
RA + RB + RC

RA * RC
R2 = --------------
RA + RB + RC

RA * RB
R3 = --------------
RA + RB + RC

[Convert Wye to Delta]

R2*R3
RA = ------- + R3 + R2
R1

R1*R3
RB = ------- + R1 + R3
R2

R1*R2
RC = ------- + R1 + R2
R3

Sometimes Delta  Wye conversion are essential…


Here, we cannot solve for resistance between A and D without Delta  Wye
transformation.

Points A, B,C form a delta, converting to Wye

Example for calculating the transformed resistances…
RXC = (12 * 6) / (12 + 6 + 18)
RXB = (18 * 6) / (12 + 6 + 18)
RAX = (12 * 18) / (12 + 6 + 18)

Now it is very easy to solve.
RXB + RBD = 3 + 9 = 12
RXC + RCD = 2 + 4 = 6
RXD = Parallel of 6 and 12 = 6 * 12 / (6 + 12) = 4
RAD = 6 + 4 = 10 Ohms

Your Program:
Your program must be a .NET Console (Command line) application. It must
accept one command line argument, which is the input file name. [The program
must not expect any user input.]

The input file indicates the resistors and the interconnections. Within the
file, a resistor is indicated by its end-points and value (in Ohms) separated
by commas. For ex.:
A,B,10
Indicates a resistor of 10 Ohms between points A and B.
The end-points between which the equivalent resistance must be calculated
are indicated by:
X,Y
[The resistance must be calculated between points X and Y]
The answer is indicated by a number.
An example input file:
A,B,10
B,C,10
C,D,10
A,D
30
This file indicates three resistors between AB, BC and CD respectively. And
you must calculate the total resistance AD. The answer is 30. [You can use
this to check your answer]

Some key points:
a. The point names can have between 1-5 characters (numbers allowed)
b. It is not necessary that the resistor point names be always in ascending
order. [The following is equivalent to the example given above]
X,J,10
P,J,10
P,Y,10
Y,X
30
So is
D,C,10
C,B,10
B,A,10
D,A
30
c. The answers must be calculated to at least 6 decimal places. [Use the
Decimal .NET data type for calculations.]. Your answer must match the
provided answer to at least 2 decimal places.

Bonus Points:
[The tasks in this section are optional.]
Some circuits may have redundant resistors. For example in
A,B,10
B,C,10
B,D,10
A,C
The resistor between BD is redundant (Its ‘hanging’. No current can flow
through it). So the system is as good as:
A,B,10
B,C,10
A,C

Similarly in
A,B,10
B,C,10
B,D,10
D,E,10
E,B,10
A,C
The resistors BD, DE and EB are redundant (They connect to the same point B,
so no current can flow). The system is as good as:
A,B,10
B,C,10
A,C

Your program could try to detect such resistors, eliminate them from the
circuit and proceed with the calculations (Or it could atleast indicate that
there is some funny business afoot and stop)

In case you have solved the main problem, do send in your entry and then
continue to work on the ‘Bonus’ task. You can send two entries. Completing
Bonus tasks entitles you to more points.

Instructions:
1. You can use any programming language [.NET languages preferred but not
required].
2. Use can use any other available software. For example you can use Office
automation and use some of EXCELs features to manipulate data. The only
restriction is that it must be a general-purpose software (like word, excel,
access, outlook etc.) and not software designed to solve problems of this
nature. Use your judgment on this.
3. If you are interfacing to other software (as in point 2 above), please
indicate the installation / configuration steps required.
--------------------------------------------------------------------------------
Check urs result with the follwing inputs

0-- X,Y,10
Y,X
10.000000
--------------
1-- A,B,10
B,A,10
A,B
5.000000
--------------
2-- D,N,10
N,S,10
N,S,10
S,A,10
D,A
25.000000
--------------
3-- J,B,10
B,X,10
X,E,10
E,Z,10
Z,P,10
J,P
50.000000
---------------

4-- A,B,100
A,B,100
B,A,100
A,B,100
B,A,100
A,B
20.000000
-------------------
5-- P,Z,50
Z,B,50
B,I,50
I,A,50
I,A,50
B,A,50
Z,A,50
P,A
80.769231
------------------
6-- Y,Z,50
Z,L,50
L,D,50
D,W,50
W,T,50
T,Q,50
Q,S,50
L,D,50
L,W,50
Z,T,50
Y,S,100
Y,S
65.048544
----------------
7-- S,H,500
H,A,100
S,A,200
S,E,500
H,E,100
E,A,200
S,A
122.869955
------------------
8-- A,B,500
B,F,100
A,F,200
A,C,50
B,D,75
E,F,100
C,D,20
E,D,100
E,C,300
A,F
80.601358
--------------------
9-- Z,X,500
X,C,100
Z,C,50
V,N,200
V,B,300
N,B,200
W,S,10
W,Q,20
Q,S,50
D,M,200
D,A,500
A,M,100
X,V,50
M,B,50
S,C,50
W,A,50
N,Q,100
Z,D
282.285584
------------------
10-- Q,W,500
W,R,500
W,E,500
Q,R
1000.000000
--------------------
11-- R,F,500
F,Q,500
F,V,500
V,T,500
T,F,500
R,Q
1000.000000
-------------------
12-- X,S,100
S,Z,100
S,A,500
S,G,500
S,B,500
X,Z
200.000000
 
B

Bob Powell [MVP]

You might wish to post a homework help request on RentACoder.com...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





deepak said:
The objective:
Develop a program that can calculate the equivalent resistance for a
network
of interconnected resistors.

The theory:
A 'Resistor' is an electrical device that resists current flowing through
it. It is indicated as below:

----/\/\/\/----

The 'resistance' is measured in Ohms.

Resistors can be connected together. A series connection is as below:

----/\/\/\/--------/\/\/\/----
A R1 B R2 C

The resistors R1 and R2 are in series because they are connected end to
end
(at point B) and no other resistor is connected to point B.

The total resistance between points A and C is R = R1+R2
[Resistances in series are added together]. On the same lines.

----/\/\/\/--------/\/\/\/--------/\/\/\/----
A R1 B R2 C R3 D

The total resistance between A and D is R1+R2+R3

A Parallel connection is as below:

+----/\/\/\/----+
----+ R1 +-------
A +----/\/\/\/----+ B
R2

The resistors R1 and R2 are in parallel because both ends of the two
resistors are connected together.

The total resistance (R) between A and B is
1 1 1
--- = --- + ---
R R1 R2

If three resistors R1, R2, R2 are in parallel then .
1 1 1 1
--- = --- + --- + ---
R R1 R2 R3

More complex connections are possible .

+----/\/\/\/----+
----+ R1=10 ohms +-------/\/\/\/-------
A +----/\/\/\/----+ B R3=25 ohms C
R1=20 ohms

To find total resistance between A and C, first, net resistance between A
and B is

1 1 1
--- = --- + ---
R 10 20

Solving, R=6.667

Therefore net resistance = 6.667 + 25 = 31.667 Ohms

More complex examples are easily designed:

+----/\/\/\/----+
+ 25 ohms +
+----/\/\/\/----+ +----/\/\/\/----+
----+ 10 ohms +-------/\/\/\/-----+ 22 ohms +-----
A +----/\/\/\/----+ B 25 ohms C +----/\/\/\/----+ D
+ 20 ohms + 44 ohms +
+----/\/\/\/----+ +
+ 41 ohms +
+------------------------------/\/\/\/--------------+
25 ohms
This circuit is analysed as follows:
a. Find the equivalent resistance between A and B. [All resistances in
parallel].
b. Find the equivalent resistance between C and D. [All resistances in
parallel].
c. Find equivalent series resistance between AB, BC, CD. The equivalent
resistance between AB and CD are calculated above.
d. Find net resistance by the equivalent of the parallel resistances
between
AB. One resistance was calculated in step (c). The other is the 25 Ohm
resistance in the problem.

Sometimes, resistances are neither in series nor in parallel. The
resistors
are then either in delta or Wye (or star).


The first set of resistors (R1, R2, R3) is in a Wye(or star)
configuration.
The next set (RA, RB, RC) is in a delta configuration. Assume that other
resistors are connected to points X,Y,Z.

You can transform resistances between X,Y,Z as follows:
[Convert Delta to Wye]
RB * RC
R1 = --------------
RA + RB + RC

RA * RC
R2 = --------------
RA + RB + RC

RA * RB
R3 = --------------
RA + RB + RC

[Convert Wye to Delta]

R2*R3
RA = ------- + R3 + R2
R1

R1*R3
RB = ------- + R1 + R3
R2

R1*R2
RC = ------- + R1 + R2
R3

Sometimes Delta ?? Wye conversion are essential.


Here, we cannot solve for resistance between A and D without Delta ?? Wye
transformation.

Points A, B,C form a delta, converting to Wye

Example for calculating the transformed resistances.
RXC = (12 * 6) / (12 + 6 + 18)
RXB = (18 * 6) / (12 + 6 + 18)
RAX = (12 * 18) / (12 + 6 + 18)

Now it is very easy to solve.
RXB + RBD = 3 + 9 = 12
RXC + RCD = 2 + 4 = 6
RXD = Parallel of 6 and 12 = 6 * 12 / (6 + 12) = 4
RAD = 6 + 4 = 10 Ohms

Your Program:
Your program must be a .NET Console (Command line) application. It must
accept one command line argument, which is the input file name. [The
program
must not expect any user input.]

The input file indicates the resistors and the interconnections. Within
the
file, a resistor is indicated by its end-points and value (in Ohms)
separated
by commas. For ex.:
A,B,10
Indicates a resistor of 10 Ohms between points A and B.
The end-points between which the equivalent resistance must be calculated
are indicated by:
X,Y
[The resistance must be calculated between points X and Y]
The answer is indicated by a number.
An example input file:
A,B,10
B,C,10
C,D,10
A,D
30
This file indicates three resistors between AB, BC and CD respectively.
And
you must calculate the total resistance AD. The answer is 30. [You can use
this to check your answer]

Some key points:
a. The point names can have between 1-5 characters (numbers allowed)
b. It is not necessary that the resistor point names be always in
ascending
order. [The following is equivalent to the example given above]
X,J,10
P,J,10
P,Y,10
Y,X
30
So is
D,C,10
C,B,10
B,A,10
D,A
30
c. The answers must be calculated to at least 6 decimal places. [Use the
Decimal .NET data type for calculations.]. Your answer must match the
provided answer to at least 2 decimal places.

Bonus Points:
[The tasks in this section are optional.]
Some circuits may have redundant resistors. For example in
A,B,10
B,C,10
B,D,10
A,C
The resistor between BD is redundant (Its 'hanging'. No current can flow
through it). So the system is as good as:
A,B,10
B,C,10
A,C

Similarly in
A,B,10
B,C,10
B,D,10
D,E,10
E,B,10
A,C
The resistors BD, DE and EB are redundant (They connect to the same point
B,
so no current can flow). The system is as good as:
A,B,10
B,C,10
A,C

Your program could try to detect such resistors, eliminate them from the
circuit and proceed with the calculations (Or it could atleast indicate
that
there is some funny business afoot and stop)

In case you have solved the main problem, do send in your entry and then
continue to work on the 'Bonus' task. You can send two entries. Completing
Bonus tasks entitles you to more points.

Instructions:
1. You can use any programming language [.NET languages preferred but not
required].
2. Use can use any other available software. For example you can use
Office
automation and use some of EXCELs features to manipulate data. The only
restriction is that it must be a general-purpose software (like word,
excel,
access, outlook etc.) and not software designed to solve problems of this
nature. Use your judgment on this.
3. If you are interfacing to other software (as in point 2 above), please
indicate the installation / configuration steps required.
--------------------------------------------------------------------------------
Check urs result with the follwing inputs

0-- X,Y,10
Y,X
10.000000
--------------
1-- A,B,10
B,A,10
A,B
5.000000
--------------
2-- D,N,10
N,S,10
N,S,10
S,A,10
D,A
25.000000
--------------
3-- J,B,10
B,X,10
X,E,10
E,Z,10
Z,P,10
J,P
50.000000
---------------

4-- A,B,100
A,B,100
B,A,100
A,B,100
B,A,100
A,B
20.000000
-------------------
5-- P,Z,50
Z,B,50
B,I,50
I,A,50
I,A,50
B,A,50
Z,A,50
P,A
80.769231
------------------
6-- Y,Z,50
Z,L,50
L,D,50
D,W,50
W,T,50
T,Q,50
Q,S,50
L,D,50
L,W,50
Z,T,50
Y,S,100
Y,S
65.048544
----------------
7-- S,H,500
H,A,100
S,A,200
S,E,500
H,E,100
E,A,200
S,A
122.869955
------------------
8-- A,B,500
B,F,100
A,F,200
A,C,50
B,D,75
E,F,100
C,D,20
E,D,100
E,C,300
A,F
80.601358
--------------------
9-- Z,X,500
X,C,100
Z,C,50
V,N,200
V,B,300
N,B,200
W,S,10
W,Q,20
Q,S,50
D,M,200
D,A,500
A,M,100
X,V,50
M,B,50
S,C,50
W,A,50
N,Q,100
Z,D
282.285584
------------------
10-- Q,W,500
W,R,500
W,E,500
Q,R
1000.000000
--------------------
11-- R,F,500
F,Q,500
F,V,500
V,T,500
T,F,500
R,Q
1000.000000
-------------------
12-- X,S,100
S,Z,100
S,A,500
S,G,500
S,B,500
X,Z
200.000000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top