毕业设计博客(一)

来源:互联网 发布:科比2016数据 编辑:程序博客网 时间:2024/04/28 05:53

今天开始我的毕业设计代码分析

一.分析util.h

#ifndef __UTIL_H__#define __UTIL_H__
前面是条件编译指令

bool FileExists(const char* filename);布尔特征判断文件是否还存在
void StartOfDuration();int EndOfDuration();void my_srand(unsigned int newseed);int my_rand();
创建分类值结构体模板
<pre name="code" class="cpp">template<class T> struct sort_struct{    int id;    T value;} ;
创建布尔模板函数,比较输入结构体,前面的值要小于后面的值才给出ture。template<class T>bool Template_Less(const sort_struct<T>& elem1, const sort_struct<T>& elem2){    return elem1.value < elem2.value;}
产生随机置换void GenerateRandomPermutation(int* p,const int length,const unsigned int seed=0xffffffff);
产生一个K最近邻的类class KNN_Vote{private:    int K; //k值    double* scores;     int* votes;  //     int* indexes; //     bool findmax; //public:    KNN_Vote(const int _K,const bool _findmax);//构造函数    virtual ~KNN_Vote(); //虚析构函数    void Init(); //     void Examine(const double newscore,const int newvote,const int newindex);    double GetBestScore() const;// 获得最好的分数    int GetBestScoreClass() const; //获得最好的分数等级    int GetBestScoreIndex() const; //获得最好的分数时的指针    int GetVotedClass(const int nclass) const; // assume all class labels (votes[i]) are integers between {0,1,2,..,nclass-1}    int GetWeightVotedClass(const int nclass) const;    int GetLabel(const int pos) const;    int GetIndex(const int pos) const;    double GetScore(const int pos) const;};class KNN_FindMax:public KNN_Vote  //公共继承KNN_Vote类{public:    KNN_FindMax(const int _K):KNN_Vote(_K,true) {} //KNN_findmax的构造函数,由于基类使用的是虚析构函数,这里不需要                                                      再定义一遍了};class KNN_FindMin:public KNN_Vote  //公有继承KNN_Vote类{public:    KNN_FindMin(const int _K):KNN_Vote(_K,false) {}  //构造函数};#endif // __UTIL_H__

0 0
原创粉丝点击