我为什么写不进去文件呢

nana2zs 2007-05-03 10:57:04
我的程序是
#include "stdafx.h"
#include<string>
#include<cstdlib>
#include<ctime>
#include<fstream>
#include<iomanip>
#include<stdlib.h>

using std::cout;
using std::cin ;
using std::endl;
using std::string;
using std::ofstream ;
using std::setw;
struct TableNode
{
string rule;//规则段
int (*action)();//行为段 指向行为函数
TableNode *next;
};
typedef TableNode *Table;
int InitTable(Table &T);
int InsertAfter(Table P,string e,int(*a)());
int PrintTable(Table T);
float RandomNumber();
float RangRandom(float A,float B);
int a11();
int a12();
int a2();
int a3();
int a4();
int writecase(float,float,float);
int main()
{
int (*pfunction11)()=0;//函数指针a11
int (*pfunction12)()=0;//函数指针a12
int (*pfunction2)()=0;//函数指针a2
int (*pfunction3)()=0;//函数指针a3
int (*pfunction4)()=0;//函数指针a4
string zifu("1111");
pfunction11=&a11;
pfunction12=&a12;
pfunction2=&a2;
pfunction3=&a3;
pfunction4=&a4;
Table T1;
InitTable(T1);
srand((unsigned int)time(0));
InsertAfter(T1,zifu,pfunction11);//a11
InsertAfter(T1,zifu,pfunction12);//a12
InsertAfter(T1,zifu,pfunction2);//a2
InsertAfter(T1,zifu,pfunction3);//a3
InsertAfter(T1,zifu,pfunction4);//a3
PrintTable(T1);


system("pause");
return 0;
}
int InitTable(Table &T)
{
T=new TableNode;
T->next=NULL;
return 1;
}
int InsertAfter(Table P,string e,int(*a)())//向表中插入指定节点后面插入新节点
{
if (P==NULL) return 0;
TableNode *Q=new TableNode;
Q->rule=e;
Q->action =a;
Q->next =P->next ;
P->next=Q;
return 1;
}
int PrintTable(Table T)//遍历链表
{
//cout<<endl;
cout<<"结果为"<<endl;
T=T->next ;
while(T!=NULL)
{

// cout<<T->rule <<endl;
T->action();
T=T->next;
}
return 1;
}
float RandomNumber()//产生0-100随机数
{
float value;
value=static_cast<float>(100.0*static_cast<float>(rand()))/(RAND_MAX+1.0);
return value;
}
float RangRandom(float A,float B)//产生一定范围的随机数
{
float value;
value=static_cast<float>(A+((B-1)*static_cast<float>(rand()))/(RAND_MAX+1.0));

return value;
}
//以下为产生测试用例函数
int a11()//非三角形(第三边在0-(a-b))
{
float a,b,c,m;//定义三角形三条边
a=RandomNumber();
b=RandomNumber();
m=static_cast<float>(abs(a-b));
c=RangRandom(0.0,m);
cout<<a<<" "<<b<<" "<<c<<" "<<" 不是三角形"<<endl;
writecase(a,b,c);
return 1;
}
int a12()//非三角形(第三边在(a+b)-200.0)
{
float a,b,c,m;//定义三角形三条边
a=RandomNumber();
b=RandomNumber();

c=RangRandom(a+b,200);
cout<<a<<" "<<b<<" "<<c<<" "<<" 不是三角形"<<endl;
writecase(a,b,c);
return 1;
}
int a2()//三角形
{
float a,b,c,m;//定义三角形三条边
a=RandomNumber();
b=RandomNumber();
m=static_cast<float>(abs(a-b));
c=RangRandom(m,a+b);
cout<<a<<" "<<b<<" "<<c<<" "<<" 是三角形"<<endl;
writecase(a,b,c);
return 1;
}
int a3()//等腰三角形
{
float a,b,c;//定义三角形的三条边
a=b=RandomNumber();
c=RangRandom(0,a+b);
cout<<a<<" "<<b<<" "<<c<<" "<<" 等腰三角形"<<endl;
writecase(a,b,c);
return 1;
}
int a4()//等边三角形
{
float a,b,c;//定义三角形的三条边
a=b=c=RandomNumber();
cout<<a<<" "<<b<<" "<<c<<" "<<" 等边三角形"<<endl;
writecase(a,b,c);
return 1;
}
int writecase(float a, float b,float c)
{
ofstream outFile("D:\\my program\\case.txt");
outFile<<endl;
outFile<<a<<setw(10)<<b<<setw(10)<<c;
return 1;
}
可是case文件里只有函数a11产生的数
...全文
155 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文提出了一种基于快速稀疏辅助信号分解与非凸增强技术的轴承故障诊断方法,并提供了完整的Matlab代码实现。该方法旨在从复杂的机械设备振动信号中高效、准确地提取故障特征,通过优化信号分解过程克服传统方法在噪声干扰下敏感、分辨率不足的问题,结合非凸优化策略增强微弱故障信号的辨识能力,从而提升早期故障诊断的准确性与鲁棒性。研究涵盖了算法原理、模型构建、仿真验证及结果分析,展示了其在旋转机械状态监测中的实际应用价值。; 适合人群:具备一定信号处理基础和Matlab编程能力,从事机械故障诊断、状态监测、智能运维等相关领域的科研人员及工程技术人员,尤其适合研究生和从事相关项目研发的工程师。; 使用场景及目标:①应用于旋转机械(如电机、风机、齿轮箱)的轴承早期故障检测;②用于复杂噪声环境下微弱故障信号的提取与增强;③为开发高精度智能诊断系统提供算法支持和技术参考;④辅助完成科研论文复现、毕业课题或工业项目开发。; 阅读建议:此资源以算法实现为核心,强调理论与实践结合,建议读者在学习过程中同步运行Matlab代码,深入理解信号分解与优化增强的每一步处理逻辑,并尝试在不同数据集上进行测试与调参,以掌握算法的适应性与优化技巧。

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧