homework12 - ECE 1574 Homework Set #12 Problem Solving with...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 1574 Homework Set #12 Problem Solving with C++ Due date: Sunday evening, 4/18/10 by 11:55 p.m. This assignment is to be done individually Complete the lab exercise and answer questions 1, 2 and 3 during the lab session. Answer the other questions later. LAB EXERCISE When programming C++ classes, a common purpose of a *.h header file is to present an interface to a class—that is, to present a set of declarations which tell a user how to use the class but which do not burden the user with all the details of the class’ implementation, where the extra details are kept apart in a compilable *.cpp file. The header Resistor.h at the end of this document, which you can copy and paste into your compiler, presents an interface to a class which represents an electrical resistor. Your task in this lab exercise will be to complete the header, to implement a file Resistor.cpp to go with it, and finally to use the resultant Resistor class to perform some electrical calculations. The Resistor class represents more than merely a resistor’s resistance. It also represents in watts the resistor’s power rating, which is the maximum power the resistor can dissipate without melting (and perhaps without posing certain additional risks, such as lighting nearby materials aflame under test conditions). It further carries a safety factor, which represents the fraction of rated power the engineer is willing to risk in operation: the safety factor defaults to 1.0 (full power allowed, no margin for safety) but can be set to a smaller, safer number if desired.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Here is some code you can use in Resistor.cpp: Electronic::Resistor Electronic::parallel( const Resistor R1, const Resistor R2 ) { const double resist = 1.0 / ( 1.0/R1.resistance() + 1.0/R2.resistance() ); const double v1_max = std::sqrt( R1.power_rating() * R1.resistance() ); const double v2_max = std::sqrt( R2.power_rating() * R2.resistance() ); const double v_max = v1_max < v2_max ? v1_max : v2_max; const double p_max = (v_max*v_max) / resist; Resistor R( resist, p_max ); { // Set the safety factor. const double sf1 = R1.safety_factor(); const double sf2 = R2.safety_factor(); const double sf = sf1 < sf2 ? sf1 : sf2; R.set_safety_factor( sf ); } return R; } This code implements the function Electronic::parallel(), whose job it is to construct a single, equivalent resistor from the parallel combination of a pair of resistors. The function begins by calculating a parallel resistance (you already know how to do this). Continuing, the function determines the greatest voltage each of the pair of resistors can tolerate, judges that the resistor pair together can tolerate only the lesser of the two voltages, and—using this lesser voltage— calculates a power rating for the parallel combination. The function does some other things which you can tell by reading the code; then constructs a new, equivalent Resistor with the calculated parameters; and finally returns the equivalent resistor. It remains to you to implement
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/15/2011 for the course ECE 1574 taught by Professor Rpbroadwater during the Spring '08 term at Virginia Tech.

Page1 / 10

homework12 - ECE 1574 Homework Set #12 Problem Solving with...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online