因为要验证一个描图程序的正确性,想要一组sin函数图像的数据,结果怎么都找不到,只好自己写一个。
语言:C++
编译器:VC6.0
输入形式:TXT文件
下面是源代码:
#include<fstream.h>#include<math.h>const int n=300; //n是数据长度const int voluation=10000; //voluation是幅值const double step=0.1; //step是每一个数据点之间的间隔int main(){int i;double index;double y[n];index=0;fout.open("sindata.txt"); //创建一个TXT文件,文件名为sindatafor (i=0;i<n;i++){y[i]=voluation*sin(index);index=index+step;}for (i=0;i<n;i++){fout<<y[i]<<'n'; //每一个数据占一行}fout<<flush;fout.close();return 0;} 实现很简单的功能,需要修改数据量、幅值等直接修改代码最开始定义的常量就行了。
来一张自己的截图: