Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- using namespace std;
- void perform(vector<double> weightVector) {
- vector<vector<double> > values;
- vector<double> tmp;
- tmp.push_back(0.0);
- tmp.push_back(0.0);
- tmp.push_back(1.0);
- values.push_back(tmp);
- tmp.clear();
- tmp.push_back(0.0);
- tmp.push_back(1.0);
- tmp.push_back(1.0);
- values.push_back(tmp);
- tmp.clear();
- tmp.push_back(1.0);
- tmp.push_back(0.0);
- tmp.push_back(1.0);
- values.push_back(tmp);
- tmp.clear();
- tmp.push_back(1.0);
- tmp.push_back(1.0);
- tmp.push_back(1.0);
- values.push_back(tmp);
- tmp.clear();
- for (int i=0; i<4; i++) {
- printf("%f %f ", values[i][0], values[i][1]);
- if (weightVector[0] * values[i][0] + weightVector[1] * values[i][1] + weightVector[2] * values[i][2] >= 0.0) {
- printf("1\n");
- } else {
- printf("0\n");
- }
- }
- }
- void performNot(vector<double> weightVector) {
- vector<vector<double> > values;
- vector<double> tmp;
- tmp.push_back(1.0);
- tmp.push_back(0.0);
- values.push_back(tmp);
- tmp.clear();
- tmp.push_back(0.0);
- tmp.push_back(1.0);
- values.push_back(tmp);
- tmp.clear();
- for (int i=0; i<2; i++) {
- printf("%f ", values[i][0]);
- if (weightVector[0] * values[i][0] + weightVector[1] * values[i][1] >= 0.0) {
- printf("1\n");
- } else {
- printf("0\n");
- }
- }
- }
- int main(int argc, char** argv) {
- vector<double> notVal;
- vector<double> andVal;
- vector<double> nandVal;
- vector<double> orVal;
- notVal.push_back(-0.5);
- notVal.push_back(0.5);
- andVal.push_back(0.25);
- andVal.push_back(0.25);
- andVal.push_back(-0.5);
- nandVal.push_back(-0.33);
- nandVal.push_back(-0.33);
- nandVal.push_back(0.33);
- orVal.push_back(0.33);
- orVal.push_back(0.33);
- orVal.push_back(-0.33);
- printf("NOT\n\n");
- performNot(notVal);
- printf("AND\n\n");
- perform(andVal);
- printf("NAND\n\n");
- perform(nandVal);
- printf("OR\n\n");
- perform(orVal);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement