Question: need help with this python program NOTE: You are NOT permitted to use ANY global variables. The use of any global variables will result in

need help with this python program

NOTE: You are NOT permitted to use ANY global variables. The use of any global variables will result in a deduction of 20%.

NOTE: There is NO input or printing anywhere other than main! Significant points will be deducted if you violate this constraint!

The following UML diagrams specify three classes. The RC_Filter class has a composition relationship with the Resistor and Capacitor classes. Your job is to implement these three classes as specified below. None of these three classes do ANY input or printing operations. You can NOT add any other members to these three classes.

Resistor

- resistance: float

- tolerance: float

+ __init__(float, float) :

+ get_resistance( ) : float

+ set_resistance(float)

+ get_tolerance( ) : float

+ set_tolerance(float)

+ getMin( ) : float

+ getMax( ) : float

+ __repr__( ) : string

Capacitor

- capacitance: float

- tolerance: float

+ __init__(float, float):

+ get_ capacitance ( ) : float

+ set_ capacitance (float)

+ get_tolerance( ) : float

+ set_tolerance(float)

+ getMin( ) : float

+ getMax( ) : float

+ __repr__( ) : string

The __init__ methods of these two classes set the values of the resistance, capacitance, and tolerance according to the parameter values. The getMin methods return the value of the resistance or capacitance minus the tolerance amount. The tolerance is a percentage (ie. 5%), so the minimum is nominal * (1 tolerance/100). The getMax methods work like the getMin methods except they return the maximum resistance or capacitance which is nominal * (1 + tolerance/100). The __repr__ method returns a formatted string containing the resistance and the tolerance values.

Note: the resistance, capacitance, and tolerance must be setup as properties with methods to set and get the property values. The set methods should raise a ValueError exception if the argument value is <= 0.

RC_Filter

+ resistor: Resistor

+ capacitor: Capacitor

+ __init__(Resistor, Capacitor) :

+ getNominalCutoff( ) : float

+ getMinCutoff( ) : float

+ getMaxCutoff( ) : float

+ __repr__( ) : string

The RC_Filter class __init__ method has the following parameters: a Resistor object and a Capacitor object. These are stored as the member variables of the class. The getNominalCutoff method returns the filters cutoff frequency using the nominal resistance and capacitance values. The formula for calculating cutoff frequency is:

1 / (2 * pi * resistance * capacitance)

The getMinCutoff method returns the minimum cutoff frequency which is calculated using the maximum resistance and capacitance values. The getMaxCutoff method returns the maximum cutoff frequency which is calculated using the minimum resistance and capacitance values. The __repr__ method returns a string containing the resistance and capacitance information.

The main function will ask the user to enter values for resistance, tolerance, and capacitance, tolerance. It will create Resistor and Capacitor objects, and an RC_Filter object. It will call the methods on the filter object to verify that the methods of all three classes are working correctly.

The following is sample output from running the program.

Enter the resistance value: 1000

Enter the resistor tolerance: 10

Enter the capacitance value: .000001

Enter the capacitor tolerance: 10

Resistance: 1000.0 ohms

Tolerance: 10.0%

Capacitance: 0.000001 farads

Tolerance: 10.0%

Nominal Cutoff Frequency is 159.15 Hz

Minimum Cutoff Frequency is 131.53 Hz

Maximum Cutoff Frequency is 196.49 Hz

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!