Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THE FOLLOWING CODE BELOW IS IN RUBY: class Circuit # constructor method def init

ID: 3683260 • Letter: T

Question

 THE FOLLOWING CODE BELOW IS IN RUBY:  class Circuit    # constructor method    def initialize(in1, in2)       @in1, @in2 = in1, in2    end end  class AndGate < Circuit        def cir_func()       (@in1 && @in2)    end end  class OrGate < Circuit        def cir_func()       (@in1 || @in2)    end end  class NotGate < Circuit    def initialize(in1)       @in1 = in1    end       def cir_func()       (not @in1)    end end  class Mux_2to1 < Circuit      def initialize(in1, in2, ctr1)         @in1_ = in1         @in2_ = in2         @ctr1_ = ctr1     end     def cir_func()       inv_ctr = NotGate.new(@ctr1_).cir_func()       a0 = AndGate.new(@in1_, inv_ctr).cir_func()       a1 = AndGate.new(@in2_, @ctr1_).cir_func()       o0 = OrGate.new(a0, a1)       return o0.cir_func()     end end   #---------------------------------------------------------------  #use the Mux_2to1, implement a 4 to 1 multiplexer class Mux_4to1   def Boolean(string)   return true if string== true || string =~ (/(true|1)$/i)   return false if string== false || string.nil? || string =~ (/(false|0)$/i)   raise ArgumentError.new("invalid value for Boolean: "#{string}"") end   puts "Please enter the first input: " input1 = gets()  puts "Please enter the second input: " input2 = gets()  puts "Please enter the third input: " input3 = gets()  puts "Please enter the fourth input: " input4 = gets()  puts "Please enter the control signal 0: " ctrsig0 = gets()  puts "Please enter the control signal 1: " ctrsig1 = gets()  #--------------------------------------------------------------- # class demo  # woodyMux = Mux_2to1.new(Boolean(input1), Boolean(input2), Boolean(ctrsig)) # # outputofwoodyMux = woodyMux.cir_func() # # puts "the result of the woodyMux is : #{outputofwoodyMux}"     #---------------------------------------------------------------   ## give 4 inputs to your mux_4to1, and 2 control signal also # Please enter the first input: # 0 # Please enter the second input: # 1 # Please enter the third input: # 0 # Please enter the fourth input: # 1 # Please enter the control signal 0: # 0 # Please enter the control signal 1: # 1 # the result of the woodyMux is : true ## Please note in the ctr signal 1 is going to be used as the control signal of two 2to1mux, ctr signal 0 is going to be used as the control signal for only 1 2to1mux  

Explanation / Answer

class Circuit # constructor method def initialize(in1, in2) @in1, @in2 = in1, in2 end end class AndGate