| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4936 人关注过本帖
标题:初学vs想用vs2010c++ mfc 为下面程序做出界面 望高手指点思路 要输出二 ...
只看楼主 加入收藏
ccccmeiyi
Rank: 1
等 级:新手上路
帖 子:14
专家分:7
注 册:2016-3-3
结帖率:60%
收藏
已结贴  问题点数:20 回复次数:2 
初学vs想用vs2010c++ mfc 为下面程序做出界面 望高手指点思路 要输出二维表,决策变量~近似集,概率近似精度等
// hg.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
void countPapp(double a, double b, int fenlei[], int jcld[][10],int low[][10],int up[][10]);
double gljsjd(int low[][10], int up[][10]);
void putintable();
void countfenlei(int);
void countjclei();


double arf1 = 0.75;  double bet1 = 0.60;//定义阈值   
int jcz[3] = { -1, -1, -1 };//存储决策类d的各个值
int jcld[2][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };

double Array[10][7];//存放信息表
int Core[6] = { 0, 0, 0, 0, 0, 0 };//存放核属性
int fenlei[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };//用数值中的值不同来表示分类

int aprablow[2][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };//概率粗糙集下近似集
int aprabup[2][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };//概率粗糙集上近似集
int aprlowlow[2][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };//在概率粗糙集下近似的粗糙集下近似集
int aprupup[2][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };//在概率粗糙集上近似的粗糙集上近似集
int aprlowup[2][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };//在概率粗糙集下近似的粗糙集上近似集
int apruplow[2][10] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };//在概率粗糙集上近似的粗糙集下近似集




int _tmain(int argc, _TCHAR* argv[])
{
    //int Core[6] = {0,0,0,0,0,0};//存放核属性

    putintable();       //输入二维表
    countfenlei(11);    //计算U/C
    countjclei();       //计算决策类个数

    countPapp(arf1,bet1,fenlei,jcld,aprablow,aprabup);//计算概率粗糙集的近似集
    cout << endl;
    countPapp(1, 0, fenlei, aprablow, aprlowlow, aprlowup);//计算粗糙集上下近似集
    cout << endl;
    countPapp(1, 0, fenlei, aprabup, apruplow, aprupup);//计算粗糙集上下近似集
    cout << endl;

    //输出粗糙集上近似集
    for (int i = 0; i != 2; ++i)
    {
        for (int j = 0; j != 10; ++j)
        {
            cout << aprlowlow[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
    //输出粗糙集下近似集
    for (int i = 0; i != 2; ++i)
    {
        for (int j = 0; j != 10; ++j)
        {
            cout << aprupup[i][j] << " ";
        }
        cout << endl;
    }

    double gljdArf = gljsjd(aprlowlow, aprupup);//计算概率近似精度
    cout << gljdArf << endl;

    return 0;
}

//计算粗糙集的上、下近似集通用函数
void countPapp(double a, double b, int fenlei[],int jcld[][10],int low[][10],int up[][10])
{
    double arf = a;
    double bet = b;
    int s = 0;   
    int t = 0;   
    int w = 0;
    int flz[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };//存储已经判断过的等价类的各个值
    int i = 0;
    for (int i = 0; i < 10; i++)
    {
        flz[w] = fenlei[i]; w++;
        int djd = 0;//记录等价类元素的个数
        int xd = 0;//记录分类中真包含在决策d中的个数
        double bl = 0.0;//计算出的划分在决策类中的比率,把它同阈值比较得到上下近似集

        int fltemp = fenlei[i];//当前等价类的哨兵值

        int templow[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };//临时存储正在比较的等价类的下标
        int v = 0;
        while (jcz[v] != -1)
        {
            int k = 0;
            int djd = 0;//记录等价类元素的个数
            int xd = 0;//记录分类中真包含在决策d中的个数
            for (int j = 0; j < 10; j++)
            {
                if (fenlei[j] == fltemp)
                {
                    templow[k] = j; k++;
                    if (jcld[v][j] == 1)
                    {
                        djd++; xd++;
                    }
                    else  djd++;
                }
            }
            bl = (double)(xd) / (double)(djd);
            if (bl >= arf)
            {
                for (int i = 0; i < k; i++)
                {
                    low[v][templow[i]] = 1;                    
                    up[v][templow[i]] = 1;
                }
            }
            else if (bl > bet)
            {
                for (int i = 0; i < k; i++)
                {
                    up[v][templow[i]] = 1;
                }
            }
            v++;
        }
        int j = 0;
        while (flz[j] != -1)
        {
            if (fenlei[i] == flz[j]) i++;
            else j++;
        }
        i--;
    }
   
}

//计算概率近似精度
double gljsjd(int low[][10], int up[][10])
{
    double countlow = 0;
    double countup = 0;
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            if (low[i][j] == 1) countlow++;
            if (up[i][j] == 1) countup++;
        }
    }
    double gljdArf = countlow / countup;
    return gljdArf;
}

//输入二维表
void putintable()
{
    //从记事本中输入信息表到二维数组中
    ifstream input("C:\\Users\\Administrator\\Desktop\\hg\\test.txt");
    if (!input)
    {
        cerr << "error!";
    }
    string line, word;
    //double Array[10][7];//存放信息表
    int m(0), n(0);
    while (getline(input, line)) //读取每行的字符
    {
        istringstream isstream(line);
        while (isstream >> word) //读取该行用空格隔开的单个数据
        {
            Array[m][n] = stod(word); //string转double
            ++n;
        }
        ++m;
        n = 0;
    }
    //输出
    for (int i = 0; i != 10; ++i)
    {
        for (int j = 0; j != 7; ++j)
        {
            cout << Array[i][j] << " ";
        }
        cout << endl;
    }
    input.close();
    //getchar();
}

//计算U/C
void countfenlei(int a)
{   
    fenlei[0] = 1;   
    for (int i = 0; i < 10; i++)//计算出划分1 1 1 2 3 4 5 6 6 7
    {
        for (int k = i + 1; k < 10; k++)
        {
            for (int j = 0; (j < 6&&j!=a); j++)
            {
                if (fenlei[k] == 0)
                {
                    if (Array[i][j] != Array[k][j])
                        break;
                    else if (j == 5)
                        fenlei[k] = fenlei[i];

                }
            }

        }

        for (int s = i + 1; s < 10; s++)
        {
            if (fenlei[s] == 0)
            {
                fenlei[s] = fenlei[i] + 1;
                i = s - 1;
                break;
            }
        }
    }
    //输出表示划分的数组值
    for (int j = 0; j != 10; ++j)
    {
        cout << fenlei[j] << " ";
    }
    cout << endl;
}

//将决策类分开放到二维数组中
void countjclei()
{   
    jcz[0] = Array[0][6];
    for (int i = 0; i < 10; i++)
    {
        int j = 0;

        while (jcz[j] != -1)
        {
            if (Array[i][6] == jcz[j])
            {
                jcld[j][i] = 1;
                break;
            }
            else if (jcz[j + 1] == -1)
                jcz[j + 1] = Array[i][6];
            else j++;
        }
    }
    //输出决策类的值
    for (int j = 0; j != 3; ++j)
    {
        cout << jcz[j] << " ";
    }
    cout << endl;
    //输出
    for (int i = 0; i != 2; ++i)
    {
        for (int j = 0; j != 10; ++j)
        {
            cout << jcld[i][j] << " ";
        }
        cout << endl;
    }
}
搜索更多相关主题的帖子: 应用程序 include double 控制台 
2016-03-31 23:10
天使梦魔
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
收藏
得分:20 
不用发的这么详细,估计也没人弄。
想好最终的界面样子,然后读内部数据
2016-04-02 10:10
ccccmeiyi
Rank: 1
等 级:新手上路
帖 子:14
专家分:7
注 册:2016-3-3
收藏
得分:0 
回复 2楼 天使梦魔
嗯~初学mfc感觉太混乱了;我在对话框中做界面。比如说我应该把函数头文件放在mfc的哪里?2.函数声明又应该放在哪里?3.控件消息中能否直接调用我写的函数?

我很菜,但我不放弃。
2016-04-03 17:20
快速回复:初学vs想用vs2010c++ mfc 为下面程序做出界面 望高手指点思路 要 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054834 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved