在已经获得的决策树上面重新生成数据 

#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;
} 

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐