码迷,mamicode.com
首页 > 其他好文 > 详细

概念学习(Concept Learning)

时间:2014-05-06 23:46:41      阅读:689      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   tar   color   

这是概念学习的一个简单示例的C++代码。

bubuko.com,布布扣
  1 #include <iostream>
  2 using namespace std;
  3 typedef enum Sky{Sunny,Rainy}Sky;
  4 typedef enum AirTemp{Warm,Cold,Cool}AirTemp;
  5 typedef enum Humidity{Normal,High}Humidity;
  6 typedef enum Wind{Strong}Wind;
  7 //typedef enum Water{Warm,Cold}Water;
  8 typedef enum Forecast{Same,Change}Forecast;
  9 typedef struct Sample
 10 {
 11  Sky sky;
 12  AirTemp airTemp;
 13  Humidity humidity;
 14  Wind wind;
 15  AirTemp water;
 16  Forecast forecast;
 17  bool EnjoySport;
 18 }Sample;
 19 typedef struct Record
 20 {
 21  Sample yangben;
 22  int    xiabiao[6];
 23 }Record;
 24 void InitSampleArray(Sample sap[4])
 25 {
 26  sap[0].sky = Sunny;
 27  sap[0].airTemp = Warm;
 28  sap[0].humidity = Normal;
 29  sap[0].wind = Strong;
 30  sap[0].water = Warm;
 31  sap[0].forecast = Same;
 32  sap[0].EnjoySport = true;
 33  sap[1].sky = Sunny;
 34  sap[1].airTemp = Warm;
 35  sap[1].humidity = High;
 36  sap[1].wind = Strong;
 37  sap[1].water = Warm;
 38  sap[1].forecast = Same;
 39  sap[1].EnjoySport = true;
 40  sap[2].sky = Rainy;
 41  sap[2].airTemp = Cold;
 42  sap[2].humidity = High;
 43  sap[2].wind = Strong;
 44  sap[2].water = Warm;
 45  sap[2].forecast = Change;
 46  sap[2].EnjoySport = false;
 47  sap[3].sky = Sunny;
 48  sap[3].airTemp = Warm;
 49  sap[3].humidity = High;
 50  sap[3].wind = Strong;
 51  sap[3].water = Cool;
 52  sap[3].forecast = Change;
 53  sap[3].EnjoySport = true;
 54 }
 55 void InitRecord(Sample& s,Record& r)
 56 {
 57  r.yangben.airTemp = s.airTemp;
 58  r.yangben.EnjoySport = s.EnjoySport;
 59  r.yangben.forecast = s.forecast;
 60  r.yangben.humidity = s.humidity;
 61  r.yangben.sky = s.sky;
 62  r.yangben.water = s.water;
 63  r.yangben.wind = s.wind;
 64  for(int i = 0;i < 6;i++)
 65   r.xiabiao[i] = 1;
 66  
 67 }
 68 void GenerateRule(Sample sap[],Record& record)
 69 {
 70  for(int i = 1;i < 4;i++)
 71  {
 72   if(sap[i].EnjoySport == true)
 73   {
 74    if(sap[i].airTemp != record.yangben.airTemp)
 75    {
 76     record.xiabiao[0] = 0;
 77    }
 78    if(sap[i].forecast != record.yangben.forecast)
 79    {
 80     record.xiabiao[1] = 0;
 81    }
 82    if(sap[i].humidity != record.yangben.humidity)
 83    {
 84     record.xiabiao[2] = 0;
 85    }
 86    if(sap[i].sky != record.yangben.sky)
 87    {
 88     record.xiabiao[3] = 0;
 89    }
 90    if(sap[i].water != record.yangben.water)
 91    {
 92     record.xiabiao[4] = 0;
 93    }
 94    if(sap[i].wind != record.yangben.wind)
 95    {
 96     record.xiabiao[5] = 0;
 97    }
 98   }
 99  }
100  for(int i = 0;i < 6;i++)
101  {
102   cout << record.xiabiao[i] << endl;
103  }
104 }
105 void Test(Sample& test,Record& record)
106 {
107  test.EnjoySport = true;
108  if(record.xiabiao[0] == 1)
109  {
110   if(record.yangben.airTemp != test.airTemp)
111   {
112    test.EnjoySport = false;
113   }
114  }
115  else if(record.xiabiao[1] == 1)
116  {
117   if(record.yangben.forecast != test.forecast)
118   {
119    test.EnjoySport = false;
120   }
121  }
122  else if(record.xiabiao[2] == 1)
123  {
124   if(record.yangben.humidity != test.humidity)
125   {
126    test.EnjoySport = false;
127   }
128  }
129  else if(record.xiabiao[3] == 1)
130  {
131   if(record.yangben.sky != test.sky)
132   {
133    test.EnjoySport = false;
134   }
135  }
136  else if(record.xiabiao[4] == 1)
137  {
138   if(record.yangben.water != test.water)
139   {
140    test.EnjoySport = false;
141   }
142  }
143  else if(record.xiabiao[5] == 1)
144  {
145   if(record.yangben.wind != test.wind)
146   {
147    test.EnjoySport = false;
148   }
149  }
150  
151  if(test.EnjoySport == true)
152  {
153   cout << "喜欢运动!" << endl;
154  }
155  else
156  {
157   cout << "不喜欢运动!" << endl;
158  }
159 }
160 int main()
161 {
162  Sample sap[4];
163  InitSampleArray(sap);
164  Record record;
165  InitRecord(sap[0],record);
166  GenerateRule(sap,record);
167  Sample test;
168  test.airTemp = Cool;
169  test.forecast = Change;
170  test.humidity = Normal;
171  test.sky = Rainy;
172  test.water = Cold;
173  test.wind = Strong;
174  Test(test,record);
175  getchar();
176 }
View Code

 

概念学习(Concept Learning),布布扣,bubuko.com

概念学习(Concept Learning)

标签:style   blog   class   code   tar   color   

原文地址:http://www.cnblogs.com/AmitX-moten/p/3712203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!