在已經獲得的決策樹上面重新生成數據
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string>
using namespace std;
class Date{
private:
//string num;//學號
string a;//成績
string w;//外語水平
string s;//社會經驗
string k;//科研能力
string j;//就業單位
int count=0;
int random_size=0;
public:
void run(int datenum=500)
{
FILE *fp=NULL;
fp=fopen("song.txt","w");
if(fp==NULL)
{
cout<<"打開失敗"<<endl;
return;
}
cout<<"文件打開成功"<<endl;
for(int i=0;i<datenum;i++)
{
this->setDate();
cout<<"當前寫入記錄: "<<i+1<<endl;
fprintf(fp,"%d\t %s\t %s\t %s\t %s\t %s\t\n",i+1,
a.c_str(),w.c_str(),s.c_str(),k.c_str(),j.c_str());
}
}
int random(int start,int end)
{
//10,15
int c=0;
//srand((unsigned)time(NULL));
//do{
c=rand()%(end-start+1)+start;
//}while(random_size=c);
this->random_size=c;
return c;
}
void test_random()
{
for(int i=0;i<20;i++)
{
cout<<random(1,20)<<" ";
}
}
void setJ()
{
if(this->s=="多")//社會實踐
{
if(this->w=="優秀")//外語水平
{
if(this->k=="良")
{
this->j=="B1";
}
}
else
{
if(this->a=="優")
{
if(this->k=="良")
{
this->j="A1";
}
}
else
{
if(this->k=="良")
{
if(this->random(1,2)==1)
{
this->j="A2";
}
else
{
this->j="C1";
}
}
}
}
}
else if(this->s=="少")
{
if(this->a=="優"&&this->k=="良"&&this->w=="一般")
{
this->j="A1";
}
else if(this->a=="良"&&this->w=="優"&&this->k=="良")
{
this->j="B1";
}
}
else
{
if(this->a=="優"&&this->k=="優"&&this->w=="一般")
{
this->j="A1";
}
else
{
if(this->a=="中"&&this->k=="良"&&this->w=="一般")
{
if(this->random(1,2)==1)
{
this->j="A1";
}
else
{
this->j="A2";
}
}
}
}
}
void setDate()
{
int ret_a;
ret_a=this->random(1,20);
if(ret_a>10)
{
this->a="良";
}
else if(ret_a>4)
{
this->a="優";
}
else
{
this->a="中";
}
ret_a=this->random(1,20);
if(ret_a>16)
{
this->w="優";
}
else
{
this->w="一般";
}
ret_a=this->random(1,20);
if(ret_a>14)
{
this->s="多";
}
else if(ret_a>5)
{
this->s="少";
}
else
{
this->s="無";
}
ret_a=this->random(1,20);
if(ret_a>4)
{
this->k="良";
}
else if(ret_a>1)
{
this->k="優";
}
else
{
this->k="差";
}
this->setJ();
}
};
int main()
{
srand((unsigned)time(NULL));
Date date;
int a;
cin>>a;
date.run(a);
return 0;
}