67% found this document useful (6 votes)
6K views23 pages

Kirchoff Law in C++ Program

This document describes a C++ program developed by an electrical engineering student to analyze resistive circuits. The program uses functions to calculate values for series and parallel circuits, including total resistance, current, voltage, power, and voltage/current dividers. It contains flowcharts and code showing the main menu, calculation processes, and testing of the program on sample circuits. The program demonstrates the student's ability to apply circuit analysis concepts and use programming structures like selection, repetition, and functions to solve circuit problems.

Uploaded by

Ismail Ibrahim
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
67% found this document useful (6 votes)
6K views23 pages

Kirchoff Law in C++ Program

This document describes a C++ program developed by an electrical engineering student to analyze resistive circuits. The program uses functions to calculate values for series and parallel circuits, including total resistance, current, voltage, power, and voltage/current dividers. It contains flowcharts and code showing the main menu, calculation processes, and testing of the program on sample circuits. The program demonstrates the student's ability to apply circuit analysis concepts and use programming structures like selection, repetition, and functions to solve circuit problems.

Uploaded by

Ismail Ibrahim
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

FINAL PROJECT BEC10102 2012/2013

1.0 INTRODUCTION

Nowadays C++ is useful and C++ is one of the most popular programming languages and is implemented on a wide variety of hardware and operating system platforms. C++ is an excellent language to start programming in a lot of applications that you use are probably written in c++ and once you learn some basic concepts, learning other languages, like java for example, will be much easier.

A computer program is a set of instructions that a programmer writes to tell a computer how to carry out a certain task. The instructions, however, must be in a language that the computer understands. Computers only understand binary language wish that composed of 1s and 0s. This is a low level language and very hard to program in. So humans invented higher level languages such as C++ or Pascal to make the job easier. As you will see, these languages are nearly like English but you dont have the freedom to write what you like there are still rules you have to follow. To convert a program in C++ to a binary or executable file that the computer can understand we use a compiler.

In this Project of BEC10102, all student electrical engineering should be involved themselves to design and developed using C++ program to completed the task or project are given by lecturer. My groups members able to solve the problem crating with the all knowledge what we learn, with used selection, if selection, if-else selection, and for looping in repetition structure, also function prototype, and function call.

2.0 REQUIREMENT SPECIFICATION


Based on the given taks Problem Crafting in Section A, the developed a C++ program able to solve problem of electric circuits by applying Ohms Law and other related theorems and formula : i. ii. To analyze the resistive circuits that are connected in series and parallel. To determine : Current in a series circuit. Voltage across each parallel branch. Total effect of voltage sources in series. Total effect of current sources in parallel. Total resistance. Power in a circuit. Voltage divider. Current divider.

1|Page

FINAL PROJECT BEC10102 2012/2013


3.0 ANALYSIS
Table 1 : Data Analysis

ITEM

DESCRIPTION
a = Option for the circuit type to calculate the total of resistance. The option as below: 1. Series 2. Parallel 3. Enter value of current & voltage. n = The number of the resistance that been entered. array[i] = Declaration for every value of resistance been entered. x = Option for user to choose 1=yes or 0=no to continue with current divider or voltage divider. V = The value of voltage that been entered.

INPUT DATA

I = The value of current that been entered. b = Option for the circuit type to calculate voltage divider or current divider. The option as below: 1. Series 2. Parallel. R = The total of resistance that been entered (RT). Ri = The value of resistance that been entered (Rn). Option = Option for the calculation type. The option as below: 1. Voltage 2. Current 3. Resistance 4. Power 5. Current Divider and Voltage Divider Calculation for the Voltage (option=1) V=I*R Calculation for the Current (option=2) I=V/R Calculation for the Total of Resistance (option=3) When a = 1 (series), the process is as below : resistance = resistance + array[i]

PROCESS
When a = 2 (parallel), the process is as below : denominator = denominator + 1/ array[i], resistance = 1 / denominator When a = 2 (parallel), the process is as below : R=V/I

2|Page

FINAL PROJECT BEC10102 2012/2013


*x is for the user to continue with current divider (parallel) or voltage divider (series) referring the circuit type option (a), when x = 1 (yes), the process is as below : Vi = (array[i] / resistance) * V or Ii = (resistance / array[i]) * I when x = 0 (no), the program will return to main menu. Calculation for the Power (option=4) P=I*V Calculation for the Current Divider and Voltage Divider (option=4) When b = 1 (series), the process is as below : Vi = (Ri / R) * V When b = 2 (parallel), the process is as below : Ii = (R / Ri) * I Return To Main Menu y=1 resistance = The total of resistance. Vi = The voltage drop (voltage divider) through resistance[i]. Ii = The current drop (voltage divider) through resistance[i]. R = The value of resistance. V = The value of voltage. I = The value of current. P = The value of power.

PROGRAM OUTPUT

3|Page

FINAL PROJECT BEC10102 2012/2013


4.0 DESIGN 4.1 Main Function

BEGIN Y=1 Input Option

Y Option = 1 = N Y Option = 2

EnterI and R

V = I*R

PrintV

Enter V and R

I = V/R

Print i

N Option = 3

Y Rtotal

N Option = 4

Enter I and V

P = I*V

Print P

N Y Option = 1 V I divider

N END

Figure 1 : The flowchart of Main Function

4|Page

FINAL PROJECT BEC10102 2012/2013


4.2 Total Of Resistance Function

Rtotal

i ++

Resistance = resistance + array[i]

Enter a

Y a=1 N Enter n Resistance = 0.00 i=1 Enter array [i]

aa
Y

a=2 N N Enter I and V i<=n Y Print Resistance e Enter x

R=V/I

Print R

N x=1

bb
Return Enter v Y

i ++ Y N Vi = (array[i]/resistance)V i<=n Print Vi


Figure 2 : The flowchart of Total of Resistance Function (1)

i=1

Array [i]

5|Page

FINAL PROJECT BEC10102 2012/2013


i ++

From aa

Denominator=denominator+ (1/array[i])

Enter n

i<=n

Resistance = 0.00 Denominator= 0.00

Print resistance

Array[i]

i =1

Enter x

From bb
x=1

Enter I Print Ii i=1 i ++ Array [i] Ii = (resistance/array[i])*I i<=n

Figure 3 : The flowchart of Total of Resistance Function (2)

6|Page

FINAL PROJECT BEC10102 2012/2013


4.3 Voltage Divider And Current Divider

V I divider

ENTER b

N b=1 Y Enter V, R and Ri Enter I, R and Ri Ii = (R/Ri) * I

Print Ii

Vi = (Ri/R) * V

Print Vi

Return

Figure 4 : The flowchart of Voltage Divider and Current Divider Function

7|Page

FINAL PROJECT BEC10102 2012/2013


5.0 THE SOURCE CODE USING C++

8|Page

FINAL PROJECT BEC10102 2012/2013

9|Page

FINAL PROJECT BEC10102 2012/2013

10 | P a g e

FINAL PROJECT BEC10102 2012/2013

11 | P a g e

FINAL PROJECT BEC10102 2012/2013

12 | P a g e

FINAL PROJECT BEC10102 2012/2013


6.0 TESTING AND VERIFICATION
1. The final result will come out as below when the program is executed.

Figure 5 : Main Menu

2. When user key in 1 is to calculate the voltage of resistor Current =40A Resistor = 8 ohm Voltage =40x8 =320V

Figure 6 : Voltage Calculation

13 | P a g e

FINAL PROJECT BEC10102 2012/2013


3. When user key in 2 is calculate the current of resistor Voltage = 68v Resistance =4 ohm Current = 68/4 = 17A

Figure 7 : Current Calculation

4. Next press 3, to calculate the resistance, having two choice which it circuit are connect in parallel or series.

Figure 8 : Resistance Calculation

14 | P a g e

FINAL PROJECT BEC10102 2012/2013


5. User key in 1 that mean resistor is series connection, shown as below. R1 = 10 ohm R2 = 10 ohm Total of resistors = 20 ohms Whether user want to continue calculate the current divider or not, the question still appear on the screen when resistor finish calculate Not continue calculate the current divider press 2 will return back the initially page.

Figure 9 : End of Resistance Calculation (series) .Press 1 is continue voltage divider, shown as below R1=(10*20v)/20 = 10v R2=(10*20v)/20 = 10v

Figure 10 : Continue to Voltage Divider

15 | P a g e

FINAL PROJECT BEC10102 2012/2013


6. User key in 2 resistors is connected with parallel shown as below. R1 = 15 ohm R2 = 15 ohm Total of resistors = 1/ (1/15 +1/15) = 7.5 ohms Not continue with current divider.

Figure 11 : End of Resistance Calculation (Parallel)

7. Next press 4 in the program able to calculate the power on the circuit. Power = cunrrent x voltage = 20x5 = 100w

Figure 12 : Power Calculation

16 | P a g e

FINAL PROJECT BEC10102 2012/2013


8. Key in 5 in the program is calculate voltage divider and current divider as below.

Figure 13 : Voltage Divider And Current Divider

Select 1 in series condition on the circuit . Voltage divider = 50x33 /66 = 25v

Figure 14 : Voltage Divider Calculation

Select 2 in parallel condition on the circuit. Current divider = (25/4 )x 68 = 212.5A

Figure 15 : Current Divider Calculation

17 | P a g e

FINAL PROJECT BEC10102 2012/2013


9. If the users do not want continue just key in 0. Then, the program will exit.

Figure 16 : Exit

18 | P a g e

FINAL PROJECT BEC10102 2012/2013


7.0 DISCUSSION
Every starting the program have define header file before the program written in these program for example using ( iostream) to insert input and output program, and then we will declare what we need to use for the input for example a to declare for the input in integer .

Header need to define what needed in the program Void declare Rtotal for voiding return

Declare each of the integer and double variables use in this program
After user will select what user want to calculate either circuit in the series or parallel, if the user select 2 this program will execute for parallel circuit calculation.

If users select 2 the program will calculate for parallel

If users select 1 the program will calculate for series

Then program will go to selection function that been made by using else, else if and if function for series circuit calculation, selection need to use in this program to select the process in the program build in. Selection function help the program to detect what the process will be execute for these case the user choose parallel circuit calculation in the one parallel circuit. The program will show the user to Enter number of resistors in the circuit: then the user decide the how many resistor that user need to calculate in these parallel circuit. If the user insert 2 resistor need to be calculate the process execute to calculate the resistor, here the function for is use for repetition in the calculation show that if input inserted is 2 the function will repeat until it fulfill requirement, after the requirement have been fulfill it will stop inserting the resistor value.

19 | P a g e

FINAL PROJECT BEC10102 2012/2013


When the user select for no 1 it calculate the series resistance in the circuit, the program was shown as below:

The user select no 1 for calculate series resistance Input for resistance

Repetition for resistance value

Formula to calculate the series resistance

Selection function for parallel cicuit

Repetition Function for the resistor value

Process of calculation or formula for parallel circuit

If the user want to continue to calculate current divider user need to select 1 to continue to the next process. In the process user will show Please enter the value of current: and decide value of current in the circuit. When the user select for no 3 it calculate the resistance (R) in circuit when the user insert the value for input V and I.
Input V and I V= voltage I=current

Formula to calculate the resistance in circuit 20 | P a g e

FINAL PROJECT BEC10102 2012/2013

Repetition Function

These will show the result of current drop through R

The selection for user choose

When the user select no 1 it calculate the voltage divider for series circuit.
User select 1 to calculate series voltage divider Formula to calculate voltage divider in circuit

The program run first

The selection to choose whether to calculate selection

To terminate the statement

The present for calculation

21 | P a g e

FINAL PROJECT BEC10102 2012/2013


To exit the program the user will need to insert 0 as the input to exit the program that have been executed, these process using switch and break function. If the function either other input or 0 were inserted It will end the program.

Enter 0 to exit the program or to end the program

default: other than input inserted the program will return to zero or program will ended To terminate the program and create new program to run

These is formula to calculate the resistance in the parallel circuit n=number of the resistor inside of the circuit and 1 is over 1/R1+1/R21/Rn, so these program use array to keep or hold the value of resistor.

22 | P a g e

FINAL PROJECT BEC10102 2012/2013


8.0 CONCLUSION
After all the steps taken, we have managed to create a program which solved our problems mentioned earlier. Thus this program conclusively is able to calculate the total resistance in series, parallel and parallel-series circuit. Plus, including the calculation of power, voltage divider and current divider in the circuit able functional in ours program. Since there is a rigorous and complicated method in calculating the total resistance in the circuit manually (by hand), thus we have successfully created a program which is able to assist the user to solve the problem more easily. This program allows the user to manipulate the type of circuit and the input needed in order to attain the correct solution in solving the total resistance in the circuit. In the request of the user, the program would also able to attain the voltage or current drop of each resistance in the circuit.

23 | P a g e

You might also like