Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main:
- #include <cstdio>
- #include <cstdlib>
- #include <string.h>
- #include <cstring>
- #include "schnittstelle.h"
- #include "baustein.h"
- #include "oder2.h"
- #include "und2.h"
- #include "xor2.h"
- #include "halbaddierer.h"
- #include "Volladdierer.h"
- void test2(Baustein* b) {
- b->eingang[0]->setPegel(0);
- b->eingang[1]->setPegel(1);
- b->update;
- b->print;
- b->eingang[0]->setPegel(1);
- b->eingang[1]->setPegel(0);
- b->update;
- b->print;
- b->eingang[0]->setPegel(1);
- b->eingang[1]->setPegel(1);
- b->update;
- b->print;
- b->eingang[0]->setPegel(0);
- b->eingang[1]->setPegel(0);
- b->update;
- b->print;
- }
- int main() {
- Schnittstelle* e0 = new Schnittstelle;
- Schnittstelle* e1 = new Schnittstelle;
- Schnittstelle* e2 = new Schnittstelle;
- Schnittstelle* a0 = new Schnittstelle;
- Schnittstelle* a1 = new Schnittstelle;
- Baustein* test = new Und2(e0, e1, a0);
- test2(test);
- Halbaddierer* testHA = new Halbaddierer(e0, e1, a0, a1);
- test2(testHA);
- getchar();
- getchar();
- return 0;
- }
- Volladdierer:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include "schnittstelle.h"
- #include "oder2.h"
- #include "und2.h"
- #include "schaltung.h"
- #include "halbaddierer.h"
- class Volladdierer : public Schaltung {
- public:
- Volladdierer(Schnittstelle* e0, Schnittstelle* e1, Schnittstelle* e2, Schnittstelle* a0, Schnittstelle* a1) {
- addEingang(e0); //Funktion zum einfügen in einen eingangsvektor, warum??
- addEingang(e1);
- addEingang(e2);
- addAusgang(a0);
- addAusgang(a1);
- Schnittstelle* i0 = new Schnittstelle;
- Schnittstelle* i1 = new Schnittstelle;
- Schnittstelle* i2 = new Schnittstelle;
- intern.push_back(i0);
- intern.push_back(i1);
- intern.push_back(i2);
- Halbaddierer* HA0 = new Halbaddierer(e0, e1, i0, i1);
- Halbaddierer* HA1 = new Halbaddierer(i1, e2, i2, a0);
- Oder2* oder2 = new Oder2(i0, i2, a1);
- bausteine.push_back(HA0);
- bausteine.push_back(HA1);
- bausteine.push_back(oder2);
- name = "Volladdierer";
- }
- void update() {
- for (int x = 0; x < bausteine.size; x++) {
- bausteine[x]->update;
- }
- }
- };
- Halbaddierer:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #include "schnittstelle.h"
- #include "und2.h"
- #include "xor2.h"
- #include "schaltung.h"
- class Halbaddierer : public Schaltung {
- public:
- Halbaddierer(Schnittstelle* e0, Schnittstelle* e1, Schnittstelle* a0, Schnittstelle* a1) {
- addEingang(e0); //Funktion zum einfügen in einen eingangsvektor, warum??
- addEingang(e1);
- addAusgang(a0);
- addAusgang(a1);
- Xor2* xor2 = new Xor2(e0, e1, a0);
- bausteine.push_back(xor2);
- Und2* und2 = new Und2(e0, e1, a1);
- bausteine.push_back(und2);
- name = "Halbaddierer";
- }
- void update() {
- for (int x = 0; x < bausteine.size; x++) {
- bausteine[x]->update;
- }
- }
- };
- Schaltung:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <string.h>
- #include <cstring>
- #include "schnittstelle.h"
- #include "baustein.h"
- using namespace std;
- class Schaltung : public Baustein {
- protected:
- vector <Schnittstelle*> intern;
- vector <Baustein*> bausteine;
- };
- Baustein:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <vector>
- #include "schnittstelle.h"
- using namespace std;
- class Baustein {
- protected:
- string name;
- vector <Schnittstelle*> eingang;
- vector <Schnittstelle*> ausgang;
- public:
- void addEingang(Schnittstelle* schnittstelle) {
- eingang.push_back(schnittstelle);
- }
- void addAusgang(Schnittstelle* schnittstelle) {
- ausgang.push_back(schnittstelle);
- }
- virtual void print() {
- cout << "Baustein: " << name << endl;
- for (int i = 0; i < eingang.size(); i++) {
- cout << "Eingang " << i << ":" << "Pegel = " << eingang[i]->getPegel << endl;
- }
- for (int i = 0; i < ausgang.size(); i++) {
- cout << "Ausgang " << i << ":" << "Pegel = " << ausgang[i]->getPegel << endl;
- }
- }
- virtual void update() = 0;
- friend void test2(Baustein* b);
- };
- xor2:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #include "schnittstelle.h"
- #include "baustein.h"
- using namespace std;
- class Xor2 : public Baustein {
- public:
- Xor2(Schnittstelle* e0, Schnittstelle* e1, Schnittstelle* a0) {
- name = "Xor2";
- addEingang(e0);
- addEingang(e1);
- addAusgang(a0);
- }
- void update() {
- if (eingang[0]->getPegel == Schnittstelle::LOW && eingang[1]->getPegel == Schnittstelle::LOW || eingang[0]->getPegel== Schnittstelle::HIGH && eingang[1]->getPegel == Schnittstelle::HIGH) {
- ausgang[0]->setPegel(Schnittstelle::LOW);
- }
- else if (eingang[0]->getPegel == Schnittstelle::HIGH && eingang[1]->getPegel == Schnittstelle::LOW || eingang[0]->getPegel == Schnittstelle::LOW && eingang[1]->getPegel == Schnittstelle::HIGH) {
- ausgang[0]->setPegel(Schnittstelle::HIGH);
- }
- else if (eingang[0]->getPegel == Schnittstelle::UNDEFINED || eingang[1]->getPegel == Schnittstelle::UNDEFINED) {
- ausgang[0]->setPegel(Schnittstelle::UNDEFINED);
- }
- }
- };
- Und2:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #include "schnittstelle.h"
- #include "baustein.h"
- using namespace std;
- class Und2 : public Baustein {
- public:
- Und2(Schnittstelle* e0, Schnittstelle* e1, Schnittstelle* a0) {
- name = "Und2";
- addEingang(e0);
- addEingang(e1);
- addAusgang(a0);
- }
- void update() {
- if (eingang[0]->getPegel == Schnittstelle::LOW && eingang[1]->getPegel == Schnittstelle::LOW || eingang[0]->getPegel == Schnittstelle::HIGH && eingang[1]->getPegel == Schnittstelle::LOW || eingang[0]->getPegel == Schnittstelle::LOW && eingang[1]->getPegel == Schnittstelle::HIGH) {
- ausgang[0]->setPegel(Schnittstelle::LOW);
- }
- else if (eingang[0]->getPegel == Schnittstelle::HIGH && eingang[1]->getPegel == Schnittstelle::HIGH) {
- ausgang[0]->setPegel(Schnittstelle::HIGH);
- }
- else if (eingang[0]->getPegel == Schnittstelle::UNDEFINED || eingang[1]->getPegel == Schnittstelle::UNDEFINED) {
- ausgang[0]->setPegel(Schnittstelle::UNDEFINED);
- }
- }
- };
- Oder2:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #include "schnittstelle.h"
- #include "baustein.h"
- using namespace std;
- class Oder2: public Baustein {
- public:
- Oder2(Schnittstelle* e0, Schnittstelle* e1, Schnittstelle* a0) {
- name = "Oder2";
- addEingang(e0);
- addEingang(e1);
- addAusgang(a0);
- }
- void update() {
- if (eingang[0]->getPegel == Schnittstelle::LOW && eingang[1]->getPegel == Schnittstelle::LOW) {
- ausgang[0]->setPegel(Schnittstelle::LOW);
- }
- else if (eingang[0]->getPegel == Schnittstelle::HIGH && eingang[1]->getPegel == Schnittstelle::LOW || eingang[0]->getPegel == Schnittstelle::LOW && eingang[1]->getPegel == Schnittstelle::HIGH || eingang[0]->getPegel == Schnittstelle::HIGH && eingang[1]->getPegel == Schnittstelle::HIGH) {
- ausgang[0]->setPegel(Schnittstelle::HIGH);
- }
- else if (eingang[0]->getPegel == Schnittstelle::UNDEFINED || eingang[1]->getPegel == Schnittstelle::UNDEFINED) {
- ausgang[0]->setPegel(Schnittstelle::UNDEFINED);
- }
- }
- };
- Schnittstelle:
- #pragma once
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- class Schnittstelle {
- private:
- short pegel = 0;
- public:
- const static short HIGH = 1;
- const static short LOW = 0;
- const static short UNDEFINED = -1;
- short getPegel() {
- return pegel;
- }
- bool setPegel(short a) {
- if (a == HIGH || a == LOW) {
- pegel = a;
- return true;
- } else {
- a = UNDEFINED;
- return false;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement