Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12832
  • 博文数量: 2
  • 博客积分: 143
  • 博客等级: 入伍新兵
  • 技术积分: 30
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-01 18:33
文章分类
文章存档

2010年(2)

最近访客

分类: C/C++

2010-06-01 18:43:26

源代码:

#include
#include
#include
struct worker
{
char name[30];
char department[30];
float basepay,allowance,total;
};
void main()
{
char filename[30]="paydata.txt";
struct worker data;
ofstream outstuf;
outstuf.open(filename,ios::out|ios::binary);
if(!outstuf) { cout<<"打开文件失败!"<
outstuf<<"这是一个和工人工资有关的文件.\n"<
char ch='N';
while(ch!='y'&&ch!='Y')
    {
cout<<"请输入工人名字,工人住址及其基本工资和奖金:"<
cin>>data.name>>data.department>>data.basepay>>data.allowance;//插入数据
outstuf<
cout<<"是否结束输入?Y or N?"<
cin>>ch;
}
outstuf.close();
//以下为改动操作*********
ifstream instuf;  
instuf.open(filename,ios::in|ios::binary);
if(!instuf)  {  cout<<"文件打开失败,程序退出!"<
instuf.clear();
int i=0;
while(!instuf.eof())
{
instuf>>data.name>>data.department>>data.basepay>>data.allowance>>data.total;
data.basepay=data.basepay+100;;
data.total=data.total+100;
cout<<"现在输出工人的名字、住址、基本工资、奖金、总共资金:"<
cout<
i++;
}
instuf.close();
}

阅读(1583) | 评论(0) | 转发(1) |
0

上一篇:基于邻接矩阵存储的AOE网关键路径算法

下一篇:没有了

给主人留下些什么吧!~~