diff options
Diffstat (limited to 'oop2w6/main.cpp')
-rw-r--r-- | oop2w6/main.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/oop2w6/main.cpp b/oop2w6/main.cpp new file mode 100644 index 0000000..1bfb20e --- /dev/null +++ b/oop2w6/main.cpp @@ -0,0 +1,40 @@ +#include <iostream> + +#include "Circuit.h" +#include "Resistor.h" +#include "Capacitor.h" +#include "Inductor.h" + +int main() { + Circuit circuit; + // ShowVisitor visitor; + circuit.add(new Resistor(50,0.05)); + circuit.add(new Capacitor(5.0e-6,false)); + circuit.add(new Inductor(1.0e-6,true)); + + Resistor* resistor; + Capacitor* capacitor; + Inductor* inductor; + + for ( IComponent* component : circuit ) { + if ( (resistor=dynamic_cast<Resistor*>(component)) != nullptr ) { + std::cout << "resistor" << std::endl; + std::cout << " value " << resistor ->getValue() << std::endl; + std::cout << " tolerance " << resistor ->getTolerance() << std::endl; + } + if ( (capacitor=dynamic_cast<Capacitor*>(component)) != nullptr ) { + std::cout << "capacitor" << std::endl; + std::cout << " value " << capacitor->getValue() << std::endl; + std::cout << " electrolitic " <<(capacitor->isElectrolitic()?"yes":"no")<<std::endl; + } + if ( (inductor=dynamic_cast<Inductor*>(component)) != nullptr ) { + std::cout << "inductor" << std::endl; + std::cout << " value " << inductor->getValue() << std::endl; + std::cout << " saturable " << (inductor->isSaturable()?"yes":"no") << + std::endl; + } + } + // for (IComponent* component : circuit) + // component->accept( visitor ); + return 0; +} |