EEU 101/2 Computer Programming Group Project Title: Total Resistance Calculation Group 4 Group members: ANG KOK WEI
108467
GOH CHIA YEE
108474
KOAY BOON AIK
108146
MOHAMAD SHAZELEE BIN SIMON
108153
NURUL WAHIEDA BINTI MUHAMAD BUSTAMAN
108488
TIONG KWONG YII
108170
School of Mechanical M echanical Engineering Date of submission: 31 March 2011
Lecturer: Associate Prof. Dr. Umi Kalthum Ngah
2
Acknowledgement
Here, we would like to acknowledge a few groups of supportive people, who became the foundation for our achievement in concluding this Group Project for the course EEU 101/2 Computer Programming.
At the outset, there would be no greater accomplishment without the guide and precious knowledge from our valued lecturer. Consequently, no one else is meant for this part of our acknowledgement but the person in mind, Associate Prof. Dr. Umi Kalthum Ngah.
Furthermore, we would like to announce o ur gratitude towards our mentor in the course EEU 101/2 for all the guidance g iven in learning the C++ programming prog ramming language.
To finish with, we would like to express our truthful appreciation towards those around us, especially those from the other groups, who had been there to assist us with regard to t heir priceless time and effort.
3
Table of Contents 1
Contents Acknowledgement
Page 2
2
Table of Contents
3
3
Abstract
4
4
Introduction
5
5
Minutes of Meetings
6-9
6
Problem Analysis 5.1 Problem Statement 5.2 Input and Output Analysis
10
7
Design Decomposition & Methodology
11-13
8
Coding and Debugging
14-26
9
Integration
27-45
10 Testing and Validation
46-59
11 Gantt Chart
60
12 Conclusion
61
13 Bibliography
62
4
Abstract Our
program is to enable the t he user to easily calculate the t he resistance of a resistor using a colour coded band and t he total resistance in a circuit of different type. In a series circuit, the current through each of the co mponents is the same. To find the total tot al resistance, add the resistancesR resistances Ri of each component and take the the sum.
In a parallel circuit, the voltage across acro ss each of the components is the same. To T o find the total resistance, add the reciprocals of the resistances Ri of each component and take the reciprocal of the sum.
. For series-parallel circuits, the total resistance is computed using series and parallel formula, where most circuit can be broken do wn to a simple parallel or series circuit.
Most resistors have three coloured bands close together at one end. The colour codes are as follows: Black Brown Red Orange Yellow Green Blue Violet Gray White
0 1 2 3 4 5 6 7 8 9
The integer codes of the bands are in the order of colour1, colour2 and colour3. The T he resistance in ohms is calculated using this formula: Resistance = (10 x colour1 + colour2) x
5
Introduction
Project Title: Total Resistance Calculation.
Project Objectives: 1) Calculate the resistance of o f resistor in a series, parallel para llel or parallel-series circuit. 2) Calculate the resistance of a resistor based on the colour coded band on o n a resistor.
Project Scope: 1) This program can calculate resistances of resistors. 2) The circuit taken into co nsideration nsideration include series, para llel and parallel-series circuit. 3) This programme can calculate resistances of resistors based on the colour bands of the resistors. 4) The circuit taken into co nsideration nsideration must only on ly consist of a power source, and resistors either in the connection connect ion of series or parallel or the combination of both. 5) The equivalent resistance is calculated without considering the effective range of resistance but only the average resistance va lue of the resistors in the circuit.
In this project, we tried to utilize as many co mmands as we are capable of to demonstrate our familiarity familiarity with w ith these commands besides showing variation. Among t he commands used are: for, if, if-else, switch, do-while, looping, function, pointer and arrays.
6
st
Minutes of 1 Meeting Summary Meeting Topic
Analysis of the program and design decomposition of the Program¶s Pro gram¶s problem
Date
26 January 2011
From
08:30 PM
To
10:00 PM
Location
Café Lembaran
Note Taker
Nurul Wahieda Muhamad Bustaman 108488
Duration
1.5 hr
th
Topic
1. Discussion on problem statement, input and o utput analysis. 2. Discussion on the flow chart for the decomposition d ecomposition of the problem Attendee List #
Name
Present
Absence Reason
1
NURUL WAHIEDA BT MUHAMAD BUSTAMAN 108488
Y
-
2
ANG K OK WEI 108467
Y
-
3
TIONG KWONG YII 108170
Y
-
4
MOHAMAD SHAZELEE BIN SIMON 108153
Y
-
5
K OAY BOON AIK 108146
Y
-
6
GOH CHIA YEE 108474
Y
-
Meeting Notes
1 2
The problem statement, input and output analysis are done. The design composition of the whole program is done.
Action Items For Next Meeting #
Task
Person Responsible
1
Come up with ideas for the C++ codes of each part of the program.
All
7
Minutes of 2
nd
Meeting
Summary Meeting Topic Date Location
Coding and debugging. th
28 February 2011 Café Lembaran
From
08:30 PM
To
10:00 PM
Note Taker
Nurul Wahieda Muhamad Bustaman 108488
Duration
1.5 hr
Topic
1. Writing codes for each part of o f the program. Attendee List #
Name
Present
Absence Reason
1
NURUL WAHIEDA BT MUHAMAD BUSTAMAN 108488
Y
-
2
ANG K OK WEI 108467
Y
-
3
TIONG KWONG YII 108170
Y
-
4
MOHAMAD SHAZELEE BIN SIMON 108153
Y
-
5
K OAY BOON AIK 108146
Y
-
6
GOH CHIA YEE 108474
Y
-
Meeting Notes
1
Each member are assigned to write write the parts of the program.
Action Items For Next Meeting #
Task
Person Responsible
1
Write code for for each part of the program which is is to be be integrated integrated in the next meeting.
All
8
Minutes of 3
rd
Meeting
Summary Meeting Topic
Testing, validation and integration
Date
16th March 2011
From
08:30 PM
To
10:00 PM
Location
Café Lembaran
Note Taker
Nurul Wahieda Muhamad Bustaman 108488
Duration
1.5 hr
Topic
1. Each code for every part of the program is debugged to check error. Each one is then compiled and run. 2. The integrated code is debugged, compiled and run. Attendee List #
Name
Present
Absence Reason
1
NURUL WAHIEDA BT MUHAMAD BUSTAMAN 108488
Y
-
2
ANG K OK WEI 108467
Y
-
3
TIONG KWONG YII 108170
Y
-
4
MOHAMAD SHAZELEE BIN SIMON 108153
Y
-
5
K OAY BOON AIK 108146
Y
-
6
GOH CHIA YEE 108474
Y
-
Meeting Notes
1
The errors which occurred in in compiling the integrated integrated codes codes while while debugging have have been been solved.
Action Items For Next Meeting #
Task
Person Responsible
1
Complete parts of the project¶s paperwork which which has been assigned to each team members.
All
9
th
Minutes of 4 Meeting Summary Meeting Topic
Presentation preparation
Date
28th March 2011
From
08:30 PM
To
10:00 PM
Location
Café Lembaran
Note Taker
Nurul Wahieda Muhamad Bustaman 108488
Duration
1.5 hr
Topic
1. Rechecking program¶s code. 2. Preparing for the presentation of the t he program. Attendee List #
Name
Present
Absence Reason
1
NURUL WAHIEDA BT MUHAMAD BUSTAMAN 108488
Y
-
2
ANG K OK WEI 108467
Y
-
3
TIONG KWONG YII 108170
Y
-
4
MOHAMAD SHAZELEE BIN SIMON 108153
Y
-
5
K OAY BOON AIK 108146
Y
-
6
GOH CHIA YEE 108474
Y
-
Meeting Notes
1
The codes, paperwork and the forecasted fl flow ow of our presentation presentation are done.
Action Items #
Task
Person Responsible
1
Prepare for the presentation of the program.
All
10
Problem Analysis Problem Statement Amongst the common type of o f combination of the electric circuit encompasses parallel, series, and a combination of both. Due to the rigorous and complicated method in calculating the total tot al resistance in the circuit manually (by hand), t hus we intend to create a program which assist the user to solve the problem more easily.
This program will then allow 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 t he program would also be able to attain the resistance of a resistor using the colour coded cod ed band calculation.
Input and Output Analysis Input data:
Type of resistance calculation ca lculation (parallel, series, series-parallel and colour coded band), number of resistors in the circuit, the value (in ohm unit) of each of the resistors, the code for the colour coded band.
Output
data:
Total resistance in the circuit or of o f the resistor.
11
Design Decomposition Total Resistance Calculation
Parallel circuit
ParallelSeries circuit
Disclaimer
Series circuit
Coloured Bands f Re i t r
Number of
Number of lines
resistor
between node x and node y
Number of lines having more Value of each
The Programmers
than one resistor
Codes of each c l ur
First colour¶s code
resistor (ohm)
Number of resistor in each
Second colour¶s code
Total resistance ohm
Value of resistors (ohm) of each
Third colour¶s code
12
Start
Display the main display menu.
Output six choices for the user to choose from. Ask the user for what type of calculation required.
Input: circuit
Start for loop for main display menu circuit == 1 circuit==3 and circuit ==2
Display "Enter Total
Display colour-code
Number of Parallel
table and Enter three
Resistor:"
resistor code.
Input: number
input get a, b, c
Display "Enter Value of
d=((10*a + b))*(pow(10.0,c))
Parallel Resistor #"
input=R
(a)
Display d
(b)
(c)
(d)
13
R_equiv = (R_equiv * R )
Get no_of_line,
/ ( R_equiv + R )
no_of_line_more than1r,
Display R_equiv
in ut =a =a
sum[a] = sum[a] + series_line_resistance sum_1r = sum_1r + 1/parallel_line_resistance sumslfinal=1/sumsl finalsum1=1/sumslfinal+1/ totalsum finalsum2=1/finalsum1
Display " finalsum2
Display disclamer Display names of programmers
quote
14
Coding and Debugging
This is known as a co mment. The comment is placed first as to specify what the code is for. In this case, the comment shown refers to t he codes of our total resistance calculation program.
The list above is for the headers used in our program. The following table will elaborate o n its term of usage. Header
Definition
Declares objects that control reading from and writing to the standard streams. This is needed to perform input and output in our program.
A header for basic mathematical operations since our program requires mathematical calculations to be done.
Provides facilities facilities to manipulate output formatting, such as the base used when formatting integers and the precision of o f floating point values. An example of its usage is in the calculat ion of the resistance for the colour coded band resistor in our program.
15
The header of the general purpose standard library library of C programming language which includes functions involving invo lving memory allocation, process control, conversions and others.
This header defines defines a very large number of Windows specific functions that can be used in C ++ programming language. Specifically Spec ifically,, in our program, it is intended for the colour output o utput of texts shown on the command co mmand prompt.
Basically, this tells the compiler to use the std na mespace.
16
Then we declare all the functions which are used in our program, including the coloured text output.
Next is the code for the int main( ), where this is the vital and centra l part of our program. This main user interface function, will allow the user to navigate through to the other parts of the program. Which is why we have chosen to use the switch o perator in the int main( ) function as to make an easy-to-use main display menu for the user.
17
18
19
Further elaboration on each part o f the int main( ) code has been embedded e mbedded in the code itself, itself, where they are stated after each µ\\¶ symbol. This is done to make it easily understanda ble for programmers other than our group members. After the definition for the int main( ) function, we then define the other function starting off with the centerwelcometext( ) function. This function uses po inter operator for the text output on the main display menu, where they are aligned to the center of the screen.
20
Next is the definition for the parallel circuit function. This parallel( ) function will be called when the user keys in the number µ1¶ from the main display menu. S ince this will initiate the case µ1¶ for the switch operator in the int main( ) function earlier. The elaboration are in the code, stated after the t he µ//¶ symbol.
Afterward is the definition for the series circuit function. This series( ) function will be called when the user key in the number µ2¶ from the main display menu. S ince this will initiate the case µ2¶ for the switch operator in the int main( ) function earlier. The elaboration are in the code, stated after the t he µ//¶ symbol.
21
Further on, the ps( ) function will w ill be called when the user type in the number µ3¶ in the main display menu. This will then initiate the case µ3¶ for the switch operator in the int main( ) function earlier. The elaboration are in the code, stated after the µ//¶ symbol. The ps( ) function is to ca lculate the total resistance in the parallel-series circuit. circuit. Though in ps() function itself includes two more function. The first one, DisplayMenu (), is to ask the user either to continue or abort the program before going on further. The second one , Functionc(), is then the part asking the user for inputs regarding the information on the parallel-series circuit. circuit. The gathered input is then calculated and presented as the final output, which is the total resistance.
22
23
24
Then, for case µ4¶ in the int main( ) function switch operator, the coded( co ded( )function is called.
This is to inform the user of the code co de for each colour band on o n a resistor.
25
26
The program will then ask the user for inputs. There is then another two switch switch operators o perators in order to find b and c, which have the same format as the switch stated before. Then when t he program have attained the value for µa¶, µb¶ and µc¶, it will then compute co mpute the answer forµd¶, which is the resistance of the resistor.
Furthermore, the next function, group ( ) will be called through case µ5¶ from the switch operator in the int main ( ) function. This function is to include each o f our team member name and matrics number. Lastly, the dis ( ) function simply contains conta ins a disclaimer¶s quote if there happens to be a misuse of or a contradiction with the answer g iven by the program.
27
Integration // GR OUP 4 C++ PR OJECT Total Resistance Calculation.cpp : main project file. #include #include #include #include #include //for //for colouring background and text
using namespace std; void centerwelcomeText(char* centerwelcomeText(char* s); //declare functions void parallel(); void series(); void coded(); void DisplayMenu(); float FunctionC(); float ps (); void group(); void dis(); //Colouring the text and background later enum colour { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELL OW, WHITE };
struct setcolour { colour _c; HANDLE HANDLE _console_handle;
28
setcolour(colour setcolour(colour c, HANDLE HANDLE console_handle) : _c(c), _console_handle(0) { _console_handle = console_handle; }};
basic_ostream basic_ostream &operator<<(basic_ostream &operator<<(basic_ostream &s, const setcolour setcolour &ref) {SetConsoleTextAttribute( {SetConsoleTextAttribute(ref._console ref._console_handle, _handle, ref._c); return s; }
//function's definition for the main output on the screen: stores all other function to be called when prompt by the user int main() {//defining variables needed in this function char circuit; int number = 0; int i = 0; double R_equiv =0.0; double R = 0.0;
//defining to colour the text HANDLE h Out; hOut = GetStdHandle(STD_ OUTPUT_HANDLE); //the operator to let the user repeat placing in inputs as required for(;;) {//do-while loop for the main output to project on the screen do {cout << "\n"; centerwelcomeText("WELCOME USER!!");//calls the funtion centerwelcomeText(char* centerwelcomeText(char* s) centerwelcomeText("GR OUP 1 C++ PR OJECT 2011!!"); cout << "\n"; HANDLE chandle = GetStdHandle(STD_ OUTPUT_HANDLE);//simple banner : coloured
29
cout <"; cin >> circuit; // the value k eyed in will determine the case sequence executed in the switch operator below } while(circuit < '1' || circuit > '6' && circuit != 'q') ;// the do-while loop will repeat its execution as long as the user key in numbers between 1 till 6 //the user is given the choice to exit the program by keying in 'q' if(circuit == 'q') break; cout << "\n\n"; switch (circuit) {// the value of 'circuit' by user determines the case sequence executed case '1': parallel();//calls parallel();//calls the parallel() funtion for execution cout << "\n"; cout << "\n";
30
system("pause");//enable system("pause");//enable the user to ponder on th e answer given by the program before th e screen is cleared of previous output system("CLS");//clear system("CLS");//clear the previous data on the screen system( "color 0c" );//return the normal background colour break; case '2': series() ;//calls the parallel() funtion for execution cout << "\n"; cout << "\n"; system("pause");//enable system("pause");//enable the user to ponder on th e answer given by the program before th e screen is cleared of previous output system("CLS");//clear system("CLS");//clear the previous data on the screen system( "color 0c" );//return the normal background colour break; case '3': ps ();//calls the parallel-series funtion, ps() for execution cout << "\n"; cout << "\n"; getchar();//enable getchar();//enable the user to ponder on the an swer given by the program before the screen is cleared of previous output system("CLS");//clear system("CLS");//clear the previous data on the screen system( "color 0c" );//return the normal background colour break; case '4': coded();//calls the parallel() funtion for execution cout << "\n"; cout << "\n";
31
system("pause");//enable system("pause");//enable the user to ponder on th e answer given by the program before th e screen is cleared of previous output system("CLS");//clear system("CLS");//clear the previous data on the screen system( "color 0c" );//return the normal background colour break; case '5': group();//calls the parallel() funtion for execution cout << "\n"; cout << "\n"; system("pause");//enable system("pause");//enable the user to ponder on th e answer given by the program before th e screen is cleared of previous output system("CLS");//clear system("CLS");//clear the previous data on the screen system( "color 0c" );//return the normal background colour break; case '6': dis();//calls the parallel() funtion for execution cout << "\n"; cout << "\n"; system("pause");//enable system("pause");//enable the user to ponder on th e answer given by the program before th e screen is cleared of previous output system("CLS");//clear system("CLS");//clear the previous data on the screen system( "color 0c" );//return the normal background colour break; }} return 0; } //Function's definition definition to align a lign center screen of welcoming text void centerwelcomeText(char* centerwelcomeText(char* s) { //defining variables needed in this function int l=strlen(s);
32
int pos=(int)((80-l)/2); pos=(int)((80-l)/2); for(int i=0;i
//The function's definition to calculate the total parallel resistance in the circuit void parallel(){//defini parallel(){//defining ng variables needed in this function int number = 0; double R_equiv =0.0; double R = 0.0; //defining to colour the text HANDLE h Out;
hOut = GetStdHandle(STD_ OUTPUT_HANDLE); HANDLE chandle = GetStdHandle(STD_ OUTPUT_HANDLE); cout <> number)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"\nPlease enter enter the correct value: "; } //the input by user is used to initialise the 'for' operator afterward afterward
33
//Using 'for' operator to calculate as man y input according to the user's wish without any restriction or hassle for (int count =1; count <=number; ++count) { cout << "Enter Value of Parallel Resistor #" << count << ":"; while (!(cin >> R)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"\nPlease enter the correct value of resistance: ";} if (count ==1) R_equiv =R; else R_equiv = (R_equiv * R ) / ( R_equiv + R ) ; //formula to calculate total resistance in parallel circuit} cout.setf(ios::fixed);//a cout.setf(ios::fixed);//a format option that displays floating point numbers in normal notation - n o trailing zeroes and no scientific notation. cout.precision(4);//a cout.precision(4);//a manipulator that sets the total number of digits to be displayed when floating point numbers are output. cout << "\n"; SetConsoleTextAttribute(hOut, BACKGR OUND_BLUE| BACKGR OUND_INTENSITY);//highlighting the background of the answer to blue with intensity cout << " The Equivalent Resistance Resistance is : " << R_equiv << " Ohms\n\n\n"<< flush;//generates the equivalent resistance on the screen} //The function's definition to calculate the total series resistance in the circuit void series(){//defining series(){//defining variables n eeded in this function int number = 0; double R_equiv=0.0;
34
double R = 0.0; //defining to colour the text HANDLE h Out; hOut = GetStdHandle(STD_ OUTPUT_HANDLE); HANDLE chandle = GetStdHandle(STD_ OUTPUT_HANDLE); cout <> number)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"\nPlease enter enter the correct value: "; }//the input by user is used to initialise the 'for' operator afterward //Using 'for' operator to calculate as many in put according to the user's wish without any restriction or hassle for (int count =1; count <=number; ++count) { cout << "Enter value of series resistor #" << count << ":"; while (!(cin >> R)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"Please enter the correct value of resistance: ";} if (count ==1) R_equiv =R; else R_equiv = R_equiv + R;//formula R;//formula to calculate total resistance in series circuit}
35
cout.setf(ios::fixed);//a cout.setf(ios::fixed);//a format option that displays floating point numbers in normal notation - n o trailing zeroes and no scientific notation. cout.precision(4);//a cout.precision(4);//a manipulator that sets the total number of digits to be displayed when floating point numbers are output. cout << "\n"; SetConsoleTextAttribute(h Out, BACKGR OUND_GREEN| BACKGR OUND_INTENSITY);//highlighting the background of the answer to green with intensity cout << " The Equivalent Resistance Resistance is : " << R_equiv << " Ohms\n\n\n" << endl;//generates the equivalent resistance on the screen} //The function's definition to calculate the resistance of the parallel-series parallel-series circuit float ps (){ char choice; char command; HANDLE h Out; hOut = GetStdHandle(STD_ OUTPUT_HANDLE); HANDLE chandle = GetStdHandle(STD_ OUTPUT_HANDLE); cout <>choice;//function cin>>choice;//function call if ((choice=='C')||(choice=='c')) ((choice=='C')||(choice=='c')) FunctionC();
//function //function call
else return 0; }} void DisplayMenu DisplayMenu ()
//function of DisplayMenu DisplayMenu
{cout<<" Enter c to continue or any key to quit"<
36
float FunctionC Function C ()
//function of FunctionC Functi onC
{int a,b,c; int no_of_line; int n o_of_line_morethan1r; o_of_line_morethan1r; int no_of_resistor_i n o_of_resistor_insl; nsl; float series_line_resistance; series_line_resistance; int no_of_line_contain1r; float parallel_line_resistance; parallel_line_resistance; float sum[no_of_line_morethan1r] sum[no_of_line_morethan1r] , sumsl , totalsum , sum_1r ,sumslfinal ,finalsum1 , finalsum2; cout<<"\n"; cout<<"3. Circuit C : Combination of Series and Parallel:\n"; Parallel:\n"; cout<<"
Node X
\n";
cout<<" .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@********** ******@@@@@@@@. \n"; cout<<" |
|
|
|
| \n";
cout<<" |
---
---
---
--- \n";
cout<<" |
|R|
|R|
|R|
| R |\n";
cout<<" |
| 11|
| 21|
| 31|
| N1|\n";
cout<<" |
---
---
---
--- \n";
cout<<" |
|
|
cout<<" |
---
---
---
--- \n";
cout<<" |
|R|
|R|
|R|
| R |\n";
|
| 22|
| \n";
cout<<" V
| 12|
| 32|
cout<<" |
---
---
cout<<" |
|
|
cout<<" |
*
*
*
| \n";
cout<<" |
*
*
*
| \n";
cout<<" |
---
---
---
--- \n";
--|
| N2|\n"; --- \n"; | \n";
37
cout<<" |
|R|
|R|
|R|
cout<<" |
| 1n|
| 2n|
| 3n|
| Nn|\n";
cout<<" |
---
---
---
--- \n";
cout<<" |
|
|
|
| R |\n";
| \n";
cout<<" .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@********** ******@@@@@@@@. \n"; cout<<"
Node Y
\n";
cout<<"======================== cout<<"==================================== ========================= =========================== ========================== ============ ====\n"; cout<<"Explaination:\n"; cout<<"\n"; cout<<"Rab: a=number of line .\n"; cout<<"
b=number of resistor.\n"; resistor.\n";
cout<<"Example: R12 means 2nd resistor in line 1.\n"; cout<<"------------------------cout<<"---------------------------------------------------------------------------------------------------------------------------------\n"; \n"; cout<<"\n"; cout<<"How many lines are connected between Node X and Node Y ?\n"; while (!(cin>>no_of_line)){ (!(cin>>no_of_line)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"Please enter the correct value for the number of lin es : "; } cout<<"How many lines which has more than 1 resistor are connected to it ?\n"; while(!(cin>>no_of_line_morethan1r)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"Please enter the correct value for the number of lin es : "; } if (no_of_line_morethan1r!=0) (no_of_line_morethan1r!=0) {cout<<"\n";
38
cout<<"Lets call the line which contain more than 1 resistor as 'series_line'.\n"; for(a=0;a>no_of_resistor_insl)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"Please enter the correct value for the number of resistor : ";} //get value from user cout<<"Please enter the value of resistance of resistor in series_line series_line "<<(a+1)<<": (in ohms)\n"; sum[a]=0; for(b=0;b>series_line_resistance)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"Please enter the correct value of resistance : "; } if(series_line_resistance<0) {cout<<"Error. Negative Negative resistance does not exist.\n"; cout<<"Please correct value of R "<<(a+1)<<(b+1)<<" :"; //ask user to reenter the value of resistance cin>> series_line_resistance; } sum[a] = sum[a] + series_line_resistan series_lin e_resistance ce ; }
//calculation //calculat ion
cout<<"The equivalent resistance of series_line "<<(a+1)<<" is "<
}
else {cout<<"Invalid data! Please press reenter the number of line which contain more than 1 resistor.\n"; system("CLS"); } no_of_line_contain1r=no_of_line-no_of_line_mo no_of_line_contain1r= no_of_line-no_of_line_morethan1r; rethan1r; cout<<"\n"; cout<<"------------------------cout<<"----------------------------------------------------------------------------------------------------------------------------------\n"; -\n";
39
cout<<"Your circuit has "<
//get value from user
sum_1r=0; for(c=0;c>parallel_line_ while(!(cin>>parallel_line_resistance)){ resistance)){ cin.clear(); cin.ignore(1000,'\n'); cout<<"Please enter the correct value of resistance : "; } if(parallel_line_resistance<0) {cout<<"Error. {cout<<"Error. Negative resistance does n ot exist.\n"; cout<<"Please correct the value of Resistor "<<(c+1)<<" :";//ask user to reenter the value of r esistance cin>>parallel_line_resistance cin>>parallel_line_resistance;; } sum_1r = sum_1r + 1/parallel_line_resistance; 1/parallel_line_resistance; } totalsum = 1/sum_1r; } sumsl=0;
//calculation
for(a=0;a
40
void coded() {char cd1,cd2,cd3; double a,b,c,d; HANDLE h Out; hOut = GetStdHandle(STD_ OUTPUT_HANDLE); HANDLE chandle = GetStdHandle(STD_ OUTPUT_HANDLE); cout < B |"< N |"<
Red"< >
R |"< O |"< Y |"< G |"< <"> E |"< V |"<
41
cout < W |"< A |"<>"; cout <> "; cout << "\n"; //look for cd1 switch(cd1){ case'B':case'b': a=0; break; case'N': case'n': a=1; break; case'R': case'r': a=2; break; case'O': case'o':a=3; break; case'Y': case'y':a=4; break; case'G': case'g':a=5; break; case'E': case'e': a=6;
42
break; case'V': case'v':a=7; break; case'A': case'a':a=8; break; case'W':case'w': a=9; break; } cout << " #2 >> "; cin>>cd2; cout << "\n"; //look for cd2 switch(cd2){ switch(cd2){ case'B':case'b': b=0; break; case'N': case'n':b=1; break; case'R':case'r': b=2; break; case'O': case'o':b=3; break; case'Y':case'y': case'Y':case'y': b=4; break; case'G':case'g': b=5; break; case'E':case'e': b=6; break; case'V': case'v':b=7; break; case'A': case'a': b=8;
43
break; case'W': case'w':b=9; break; } cout << " #3 >> "; cin>>cd3; cout << "\n"; //look for cd3 switch(cd3){ case'B':case'b': c=0; break; case'N': case'n':c=1; break; case'R':case'r': c=2; break; case'O': case'o':c=3; break; case'Y':case'y': case'Y':case'y': c=4; break; case'G':case'g': c=5; break; case'E': case'e':c=6; break; case'V': case'v':c=7; break; case'A': case'a':c=8; break; case'W': case'w':c=9; break; }
44
d = ((10*a + b))*(pow(10.0,c)); cout << "The resistance is "<
45
hOut = GetStdHandle(STD_ OUTPUT_HANDLE); HANDLE chandle = GetStdHandle(STD_ OUTPUT_HANDLE); cout <
46
Testing and Validation y
The Parallel Circuit
When the user keys in 1
47
The user will then be asked to t o key in the number of o f parallel resistor As an example, the tot al number of parallel resistor is 10.
Press enter,
48
The program will asked the user to key in all the va lue of parallel resistor For example,
R1=2, R2=1.5, R3=1, R4=3, R5=1.4, R6=2, R7=2.2, R8=3, R9=1, R10=1.1
Hence, the effective resistance in 10 para llel resistors is 0.1721 ohms.
49
If the user want to continue just press pr ess any key and it will return to t he original pages.
If the users do not want continue just key in q. then the t he program will exit.
50
y
The Series Circuit
1. First, compile the program in order to convert the language into the machine code. Click Program > Compile. 2. If there is no error, then proceed pro ceed to running the program. 3. After compiling the program, the status is ³SUCCESS ´ without any error. This, however, does not mean that the program is correct because the t he equivalent resistance calculated by this program might be wrong as the program might have been written inappropriately. 4. Click Debug > Run to... to run the program. 5. To verify the correctness of the program, pro gram, we will test the program with a simple series circuits.
R5
R4
50
75
R3
105
R1
R2
79
68
Circuit 1
51
6. Next, we will calculate the equivalent resistance of the circuit. The equivalent equ ivalent resistance of cir cu cuit 1 calculated (by calculator) using the formulas below is 377ohm . Series:
R eq eq= R 1+R 2+R 3+........+R n
7. The equivalent resistance calculated by our program is 377ohm. Hence, the program is correct. Fig ure below verifies that our program can calculate the equ ivalent resistance of cir cu cuit 1 correctly.
52
y
The Parallel-Series Circuit
For an example of the ³Parallel-series ³Para llel-series circuit´, circuit´, a circuit consisting of 6 resistor connected in parallel-series circuit circuit which are R1 (10 ohms) , R2 (5 o hms), R3 (2 ohms), R4 (2 ohms), R5 (100 ohms) and R6(30 ohms). o hms).
The resistors are arranged as in the circuit above.
Via calculator, the equivalent resistance is calculated using the formulas:
Series:
R eq eq= R 1+R 2+R 3+........+R n
Parallel:
1/R eq eq=1/R 1+1/R 2+1/R 3+..........1/R n
53
54
Comparing the answer from the calculator which is 1.685393258 ohms and the answer obtained from the program above, it is verified verified that t hat they are similar to it. Hence, in can be proven that the program is valid and a nd is able to calculate calcu late the parallel-series circuit circuit (Series circuit in parallel)
55
Explanation
1. In order to determine the equivalent resistance of a circuit, the type of the circui c ircuitt must be identified. (Series, parallel para llel or parallel-series circuit) 2. The calculation of resistance are done do ne with a f or loop or loop and equation Series: R eq eq= R 1+R 2+R 3+........+R n Parallel: 1/R eq eq=1/R 1+1/R 2+1/R 3+..........1/R n 3. Figure below shows the explanation of the program to calculate the equivalent resistance of the circuit above. 4. First, enter the number of line conta ining the resistors, as asked by the program. Hence, there would be five lines in the c ircuit.
5 lines containing resistor
56
5. Since all of these five lines each co ntaining resistors, are considered parallel to each other, the equivalent resistance of the whole who le circuit will definitely be the sum of o f resistance using formula:
Parallel:
1/Req=1/R1+1/R2+1/R3+..........1/Rn
6. Yet, in each of the para llel-circuit llel-circuit lines, there would wo uld be other resistance connected to it as shown in the diagram above abo ve which a resistor is connected in series to R4.
R3 & R4 connected in series
7. Hence, we can determine the number of lines which contains more than one resistor in each parallel line.
57
Only 1 line which contain more than 1 resistor
8. Hence, to get the t he accurate equivalent resistance, the sum of the resistor (R3 & R4) should be obtained in order o rder to calculate the total sum of resistance in the c ircuit ircuit using the formulas: eries: Req= R1+R2+R3+........+Rn S eries:
Combining R3 & R4 to obtain a sum of resistance in the line
58
9. Hence, the circuit would contain conta in only of resistor connected in parallel. Therefore, t he equivalent resistance of the circuit can now be calaculated using the formula: Parallel:
1/Req=1/R1+1/R2+1/R3+..........1/Rn
Rs = R3 + R4
Finally, the equivalent resistance calculated by o ur program is 1.68539 ohms o hms as shown in the console window below:
59
y
The Coloured Bands of Resistor 1. First of all, we can give the t he single-character code for the coloured bands t hat marks a resistor and compute it into resistance.
Colour Number Black Brown Red Orange Yellow
0 1 2 3 4
Code B N R O
Y
Colour Number Green Blue Violet Gray White
5 6 7 8 9
Code G E V A W
2. Next, we can calculate the equivalent resistance by giving the codes. The equivalent resistance of the codes (R OY) if calculated (by calculator) by using t he formula below is 230000ohm . y
R(Red) is the colour 1 with number of 2
y
O(Orange)
y
Y(Yellow) is the colour 3 with number o f 4
is the colour 2 with number of 3
Equivalent resistance= (10×colour 1+colour 2) × 3. The equivalent resistance which has been calculated by our program is 23000ohm . Hence, our program is correct. Figure below below verifies that our program can calculate the equivalent resistance with this method correctly.
60
Gantt chart
No. 1 2 3 4 5 6 7
Activity Analysis of the program Decomposition of the poblem Coding And Debugging Integration Testing And Validation Program Completed Presentation
1
2
3
4
5
6
7
Week 8 9
10
11
12
13
14
61
Conclusion After all the steps taken, we have managed to create a program pro gram 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 for the resistance o f a resistor according to the colour coded co ded band on a unit of o f resistor.
Since there is a rigorous and co mplicated 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 o f circuit and the input needed in order to attain the correct solution in solving the tot al resistance in the circuit. In the request o f the user, the program would also be able t o attain the resistance of a resistor using the co lour coded band calculation.
62
Bibliography
C++ Lang uage T utorial February torial February 29 2000.
C++ Ref Ref erence April 2002. < http://www.cppreference.com/wiki/start>
C Programming and C++ Programming August Programming August 2005. < http://www.cprogramming.com/>