Professional Documents
Culture Documents
Bước 4: Nhập tên project và chọn trình biên dịch Linux GCC/MinGW GCC
1
Bước 5: Project test_gate được tạo
Bước 8: Nhập vào nội dung của chương trình (tập tin test_gate.cpp)
2
Bước 9: Biên dịch project (Build Project)
Bước 10: Kiểm tra kết quả biên dịch thành công (không có báo lỗi, error)
Bước 11: Tiến hành thực thi chương trình chế độ Debug As →Local C/C++ Apllication
3
Bước 12: Thực thi chương trình (Resume, Step Over, Step Into)
Bước 13: Quan sát kết quả (giá trị các biến, Variables) sau từng bước thực thi từng lệnh, kết quả cuối
cùng của chương trình. Có thể thực hiện lại chương trính nhiều lần để hiểu rõ nội dung, cách thực thi
của chương trình.
4
Chương trình (tập tin test_gate.cpp)
#include <iostream>
#include <string>
using namespace std;
class LogicGate {
public:
LogicGate(string n){
label = n;
}
string getLabel(){
return label;
}
bool getOutput(){
output = performGateLogic();
return output;
}
virtual bool performGateLogic(){
cout << "ERROR! performGateLogic BASE" << endl;
return false;
}
5
pinA = source;
this->pinATaken = true;
}
else if (pinBTaken == false) {
pinB = source;
this->pinBTaken = true;
}
}
private:
bool pinA, pinATaken, pinB, pinBTaken;
};
6
public:
OrGate(string n) : BinaryGate(n) {};
class Connector{
public:
Connector(LogicGate *fgate, LogicGate *tgate) {
fromgate = fgate;
togate = tgate;
tgate->setNextPin(fromgate->getOutput());
}
LogicGate *getFrom() {
return fromgate;
}
LogicGate *getTo() {
return togate;
}
private:
LogicGate *fromgate, *togate;
};
int main() {
char stopme;
//Setting labels
AndGate gand1(" AND1 ");
AndGate gand2(" AND2 ");
OrGate gor3(" OR ");
NotGate gnot4(" NOT ");
7
// The inputs can be changed here!
gand1.setNextPin(0);
gand1.setNextPin(0);
gand2.setNextPin(0);
gand2.setNextPin(0);
//making comnnections
Connector c1(&gand1, &gor3);
Connector c2(&gand2, &gor3);
Connector c3(&gor3, &gnot4);