sourcegenclass.cpp

来自「三种模拟调制与解调的算法」· C++ 代码 · 共 68 行

CPP
68
字号
// SourceGenClass.cpp: implementation of the SourceGenClass class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "mod_demod.h"
#include "SourceGenClass.h"
#include "head.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SourceGenClass::SourceGenClass(long points,CString filename)
{
	num_of_points=points;
	out_put_filename=filename;

}

SourceGenClass::~SourceGenClass()
{

}
////////////////////////////////
double SourceGenClass::uniform(double a,double b,long *seed)
{
	double t;
	*seed=2045*(*seed)+1;
	*seed=*seed-(*seed/1048576)*1048576;
	t=(*seed)/1048576.0;
	t=a+(b-a)*t;
	return t;
}
//////////////////////////////
void SourceGenClass::run()
{
	CFile outf(out_put_filename,CFile::modeCreate|CFile::modeWrite);
	if(!outf)
	{
		cout<<"Error occured when create file"<<out_put_filename<<endl;
		getch();
		exit(1);
	}
    unsigned rand_max;
	
	long i;          
	float *x;
	long seed;

	x=(float *)malloc(num_of_points*sizeof(float));
	if(!x) exit(1);
	rand_max=32760;
	srand(rand_max);
    seed=rand();
	for(i=0;i<num_of_points;i++)
		x[i]=uniform(-1.0,1.0,&seed);
	outf.WriteHuge(x,num_of_points*sizeof(float));
	outf.Close();
	free(x);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?