初学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;
}
}