资源简介
大连理工大学面向对象课程大作业源代码~拿去使用吧~~
代码片段和文件信息
#include “stdafx.h“
#include “Allen.h“
double AllenVariance::GaussianGenerator()
{
const int Num = 12;
double array[Num] = { 0 }Sum = 0;
double GaussianStdNumGaussianNum = 0;
for ( int i =0 ; i < Num ; i++ ) // To generate (01) distribution
{
//srand( (unsigned)time( NULL ) ); // To generate different random number
array[i] = static_cast(rand()) / RAND_MAX;
Sum += array[i];
//Sleep ( 50 );
}
GaussianStdNum = Sum - Num * 0.5; // Generatd standard Gaussian distribution
GaussianNum = GaussianStdNum * m_GaussVariance + m_GaussMean;
// Get the wanted distribution
while ( SelectStdData ( GaussianNum ) )
GaussianNum = ReGenerateGaussianNum ();
//return WriteToFile ( GaussianNum ) ? true : false;
// Write the data to files
return GaussianNum;
}
double AllenVariance::ReGenerateGaussianNum ()
{
const int Num = 12;
double array[Num]Sum = 0;
double GaussianStdNumGaussianNum = 0;
for ( int i =0 ; i < Num ; i++ ) // To generate (01) distribution
{
array[i] = static_cast(rand()) / RAND_MAX;
Sum += array[i];
}
GaussianStdNum = Sum - Num * 0.5; // Generatd standard Gaussian distribution
return GaussianNum = GaussianStdNum * m_GaussVariance + m_GaussMean;
}
bool AllenVariance::SelectStdData ( double data ) // To select the number from -3 sigma to 3 sigma
{
if ( data == (m_GaussMean + 3 * m_GaussVariance) &&
data == (m_GaussMean - 3 * m_GaussVariance) )
return true;
else
return false;
}
bool AllenVariance::WriteToFile ()
{
//ofstream fout(“data.txt“ios_base::app);
ofstream fout(“data.dat“ios_base::out|ios_base::app);
if ( !fout.is_open () )
{
cerr << “ File open error ! “ << endl;
return false;
}
for ( int i = 0 ; i < BufferNum ; i++ )
fout << fixed << setprecision(4) << setw(8) << GaussianNumBuffer[i] << “ “ ;
fout << endl;
fout.close ();
// To do a test
//for ( int j = 0 ; j < BufferNum ; j++ )
// cout << GaussianNumBuffer[j] << endl;
//cout << endl;
return true;
}
bool AllenVariance::ReadFromFile () // Read all datas from the file
{
ifstream fin(“data.dat“);
if ( !fin.is_open () )
{
cerr << “File ope error“ << endl;
return false;
}
string str;
stringstream sstr;
unsigned int i = 0;
double temp = 0;
while (!fin.eof())
{
getline(fin str);
sstr << str;
while((sstr >> temp))//m_DataArray[i]))
{
m_Data.push_back (temp);
i++;
}
sstr.clear();
}
//sstr.clear();
//getline(fin str);
//sstr << str;
//while((sstr >> array[i])) i++;
//for (int j = i - 1; j >= 0; j--)
// cout << array[j] << ‘ ‘ << endl;
fin.close ();
/* test
int j = 1;
for (vector::iterator it = m_Data.begin(); it != m_Data.end(); it++)
{
cout << *it << “ “;
if ((j%10) == 0)
cout << endl;
j++;
}
*/
return true ;
}
bool AllenVariance::FileBuffer ()
{
for ( in
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7303 2008-12-05 08:38 AllenVariance\Allen.cpp
文件 2064 2008-12-05 15:16 AllenVariance\Allen.h
文件 1904 2010-01-07 00:40 AllenVariance\AllenDialog.cpp
文件 1334 2008-11-29 09:39 AllenVariance\AllenDialog.h
文件 46200 2010-01-07 00:25 AllenVariance\AllenVariance.aps
文件 3382 2010-01-07 00:40 AllenVariance\AllenVariance.clw
文件 4335 2008-11-28 21:22 AllenVariance\AllenVariance.cpp
文件 5098 2008-12-05 09:13 AllenVariance\AllenVariance.dsp
文件 534 2008-11-28 21:38 AllenVariance\AllenVariance.dsw
文件 1433 2008-11-28 21:22 AllenVariance\AllenVariance.h
文件 99328 2010-01-07 00:51 AllenVariance\AllenVariance.ncb
文件 50688 2010-01-07 00:51 AllenVariance\AllenVariance.opt
文件 1135 2010-01-07 00:40 AllenVariance\AllenVariance.plg
文件 13223 2010-01-07 00:25 AllenVariance\AllenVariance.rc
文件 203 2008-12-04 20:58 AllenVariance\AllenVariance.sln
..A..H. 7168 2008-12-04 20:58 AllenVariance\AllenVariance.suo
文件 9415 2008-12-04 20:57 AllenVariance\AllenVariance.vcproj
文件 1427 2008-12-04 20:57 AllenVariance\AllenVariance.vcproj.746968735E3C4B2.jhl.user
文件 1882 2008-11-28 21:22 AllenVariance\AllenVarianceDoc.cpp
文件 1552 2008-11-28 21:22 AllenVariance\AllenVarianceDoc.h
文件 11979 2008-12-05 17:11 AllenVariance\AllenVarianceView.cpp
文件 2616 2008-12-03 20:45 AllenVariance\AllenVarianceView.h
文件 2514 2008-11-28 21:22 AllenVariance\MainFrm.cpp
文件 1581 2008-11-28 21:22 AllenVariance\MainFrm.h
文件 4479 2008-11-28 21:22 AllenVariance\ReadMe.txt
文件 1078 2008-11-28 21:22 AllenVariance\res\AllenVariance.ico
文件 405 2008-11-28 21:22 AllenVariance\res\AllenVariance.rc2
文件 1078 2008-11-28 21:22 AllenVariance\res\AllenVarianceDoc.ico
..A.SH. 6656 2010-01-07 00:51 AllenVariance\res\Thumbs.db
文件 1078 2008-11-28 21:22 AllenVariance\res\Toolbar.bmp
............此处省略9个文件信息
- 上一篇:STM32 硬件IIC读取BH1750
- 下一篇:黑瞳极速弱口令扫描器
评论
共有 条评论