{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ch 10 n 12

# ch 10 n 12 - ch 10 Circuit:Circuit num_of_resistors = 4 vs...

This preview shows pages 1–2. Sign up to view the full content.

ch. 10 Circuit::Circuit() { num_of_resistors = 4; vs = VoltageSource(“vs”, 100, 0); r[0] = Resistor (“r1”, 2, 35); r[1]= Resistor(“r2”, 4, LARGE_RATING_WATTS); r[2] = Resistor(“r3”, 3, LARGE_RATING_WATTS); r[3] = Resistor(“r4”, 6, LARGE_RATING_WATTS); rL = LoadResistor(“rL”, 10, 20, 77.5, LARGE_RATING_WATTS); } void Circuit::solveCircuit() { Resistor req(“req”, 0 , LARGE_RATING_WATTS); for ( int i = 0; i<num_of_resistors; i +=2) { req = req + (r[i] || r[i+1]); } vs.amps() = req.amps() = rL.amps() = vs.volts()/ } for (int i = 0, i < num_of_resistors; i += 2) { r[i].across_volts() = r[i+1].across_volts() = ((r[i] || r[i+1}).ohms() / req.ohms()) * req.across_volts(); r[i].volts() = r[i+1].volts() = vs.volts() – r[i].across_volts(); r[i].amps() = r[i].across_volts() / r[i].ohms(); r[i].watts(); r[i+1].amps() = r[i+1].across_volts() / r[i+1].ohms(); r[i+1].watts(); } vs.watts(); rL.watts(); } ckt.vs.print(); ckt.rL.print(); output - 26013 65.2538

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

View Full Document
Ch.12 solve a circuit with any number of resistors #include<iostream> #include<fstream> #include<string> #include<iomanip> struct Circuit { VoltageSource vs; Resistor *r; (r is no longer a resistor with *, represents resistor * - address of where a resistor lives, r is
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}