Cpp2_f08 - CGS-2425 C+ EXAM 2, TEST FORM CODE...

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

View Full Document Right Arrow Icon
CGS-2425 C++ EXAM 2, TEST FORM CODE "A", SPECIAL CODE "28", FALL 2008 This exam is OPEN BOOK, OPEN NOTES, CLOSED NEIGHBOR. Cheaters will receive a ZERO on the exam. Assume iostream.h and math.h have been included prior to any partial C++ code. The next five questions refer to the Circuit class defined below: T const int PARALLEL=0; const int SERIES =1; c class Circuit { private: double voltage; double res1; double res2; int type; public: Circuit(); // constructor 1 Circuit(double v, double r1, double r2, int t); // constructor 2 double getVoltage(void); // get the voltage void setVoltage(double v); // set a new voltage void setResistance(double r1, double r2, int t); // set the resistances and // the type of the circuit double findCurrent(void); // calculate the current // in the circuit double getTotalResistance(void); // calculate the total // resistance of circuit }; } Circuit::Circuit() { voltage=res1=res2=0; type = PARALLEL; } Circuit::Circuit(double v, double r1, double r2, int t){ voltage = v; res1 = r1; res2 = r2; type = t; } double Circuit::getVoltage(void) {return voltage;} d void Circuit::setVoltage(double v) {voltage = v;} v void Circuit::setResistance(double r1, double r2, int t){ res1 = r1; res2 = r2; type = t; } double Circuit::findCurrent(void) { if (getTotalResistance()==0) {
Background image of page 1

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

View Full DocumentRight Arrow Icon
return 0; } else { return voltage / getTotalResistance(); } } double Circuit::getTotalResistance(void){ if (type == SERIES) { return (res1+res2); } else if (type == PARALLEL) { return (res1*res2)/(res1 + res2); } else { return 0; } } 1. Consider the following statement: Circuit c(5.8,280,370,1); cout<<c.getTotalResistance()<<' '<<c.getVoltage(); What is the output? A. 650 5.8 B. 159 5.8 C. 5.8 650 D. 5.8 159 E. 65.0 5.8 2. Consider the following program segment Circuit c1; Circuit c2(1200, 2, 2, 1); cout << c1.getVoltage() << ','; cout << c2.getVoltage() << ','; c1.setResistance(2,2,0); cout << c1.findCurrent() << ','; cout << c2.findCurrent(); What is the output? A. 0,1200,0,1200 B. 0,0,0,0 C. 0,1200,0,300 D. 1200,1200,0,300 E. None of above 3. Consider the following statement: Circuit c1(2400, 4, 4, 0); Circuit c2(1200, 2, 2, 1);
Background image of page 2
c2.setVoltage(c1.getVoltage()); cout << c1.getVoltage() << ','; cout << c2.getVoltage() << endl; What is the output? A. 1200,1200 B. 2400,1200 C. 1200,2400 D. 2400,2400 E. None of above 4. Consider the following program segment Circuit c(1200, 2, 2, 1); c.setResistance(5,5,0); cout << c.findCurrent() << endl; What is the output? A. 120 B. 300 C. 1200 D. 480 E. None of above 5. Consider the following program segment const int SAFE=38; Circuit c(160, 2, 2, 1); while (c.findCurrent() > SAFE) { c.setVoltage(c.getVoltage()-5); } cout << "The new voltage: " << c.getVoltage() << endl; What is the output? A. The new voltage: 145
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

Cpp2_f08 - CGS-2425 C+ EXAM 2, TEST FORM CODE...

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

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