ch 4 - functions, pass by value, scope, prototypes, header,...

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

View Full Document Right Arrow Icon
functions, pass by value, scope, prototypes, header, body struct VoltageSource – create variables of type voltage source { double volts; double amps; double watts; double rating_watts; double avg_watts; }; struct Resistor { double volts; double amps; double watts; double ohms; double lower_ohms; double upper_ohms; double min_volts; int low_voltage_event; } VoltageSource sour; sour.volts = 1000.0; (. – used to access different variables of voltage source type) sour.avg_watts = 0; Resistor r; LoadResistor load;
Background image of page 1

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

View Full DocumentRight Arrow Icon
r.ohms = 5.0; load.lower_ohms = 200.0; load.upper_ohms = 500.0; load.min_volts = 998; load.low_voltage_event = 0; double diff = load.upper_ohms – load.lower_ohms; int seed = 100000, samples = 100000; srand (seed ); int counter = 0; while ( ++counter < samples) { load.ohms = load.lower_ohms + diff *( (double)rand()/RAND_MAX (gives number betwn 0 and 1)); sour.amps = r.amps = load.amps = sour.volts / (r.ohms + load.ohms); sour.avg_watts += sour.volts *sour.amps; load.volts = load.ohms * load.amps; if(load.volts < load.min_volts) { ++load.low_voltage_event;
Background image of page 2
double x = y * sqrt(9.0); } } cout << (sour.avg_watts /= samples); cout << load.low_voltage_event; output sour.avg = 3003.46 output low_voltage_event = 0 initialize voltage source, resistors r1 and r2, and load resistor can create header file which can be called by #include. const string lines = “\n\n” spaces = “ “; struct VoltageSource { string name; double volts; double rating_watts; double avg_watts; } int main { VoltageSource vs = init( “vs”, 100.0, 1000.0) function, passes the value of name to vs, 100 to
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.

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

Page1 / 8

ch 4 - functions, pass by value, scope, prototypes, header,...

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