Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <vector>
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6. using namespace std;
  7.  
  8. void perform(vector<double> weightVector) {
  9. vector<vector<double> > values;
  10. vector<double> tmp;
  11.  
  12. tmp.push_back(0.0);
  13. tmp.push_back(0.0);
  14. tmp.push_back(1.0);
  15. values.push_back(tmp);
  16. tmp.clear();
  17.  
  18. tmp.push_back(0.0);
  19. tmp.push_back(1.0);
  20. tmp.push_back(1.0);
  21. values.push_back(tmp);
  22. tmp.clear();
  23.  
  24. tmp.push_back(1.0);
  25. tmp.push_back(0.0);
  26. tmp.push_back(1.0);
  27. values.push_back(tmp);
  28. tmp.clear();
  29.  
  30. tmp.push_back(1.0);
  31. tmp.push_back(1.0);
  32. tmp.push_back(1.0);
  33. values.push_back(tmp);
  34. tmp.clear();
  35.  
  36. for (int i=0; i<4; i++) {
  37. printf("%f %f ", values[i][0], values[i][1]);
  38. if (weightVector[0] * values[i][0] + weightVector[1] * values[i][1] + weightVector[2] * values[i][2] >= 0.0) {
  39. printf("1\n");
  40. } else {
  41. printf("0\n");
  42. }
  43. }
  44.  
  45. }
  46.  
  47. void performNot(vector<double> weightVector) {
  48. vector<vector<double> > values;
  49. vector<double> tmp;
  50.  
  51. tmp.push_back(1.0);
  52. tmp.push_back(0.0);
  53. values.push_back(tmp);
  54. tmp.clear();
  55.  
  56. tmp.push_back(0.0);
  57. tmp.push_back(1.0);
  58. values.push_back(tmp);
  59. tmp.clear();
  60.  
  61.  
  62.  
  63. for (int i=0; i<2; i++) {
  64. printf("%f ", values[i][0]);
  65. if (weightVector[0] * values[i][0] + weightVector[1] * values[i][1] >= 0.0) {
  66. printf("1\n");
  67. } else {
  68. printf("0\n");
  69. }
  70. }
  71.  
  72. }
  73.  
  74. int main(int argc, char** argv) {
  75. vector<double> notVal;
  76. vector<double> andVal;
  77. vector<double> nandVal;
  78. vector<double> orVal;
  79.  
  80. notVal.push_back(-0.5);
  81. notVal.push_back(0.5);
  82.  
  83. andVal.push_back(0.25);
  84. andVal.push_back(0.25);
  85. andVal.push_back(-0.5);
  86.  
  87. nandVal.push_back(-0.33);
  88. nandVal.push_back(-0.33);
  89. nandVal.push_back(0.33);
  90.  
  91. orVal.push_back(0.33);
  92. orVal.push_back(0.33);
  93. orVal.push_back(-0.33);
  94.  
  95. printf("NOT\n\n");
  96. performNot(notVal);
  97.  
  98.  
  99.  
  100. printf("AND\n\n");
  101. perform(andVal);
  102.  
  103.  
  104. printf("NAND\n\n");
  105. perform(nandVal);
  106.  
  107.  
  108. printf("OR\n\n");
  109. perform(orVal);
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement