1个回答
展开全部
#include <stdio.h>
#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <stdlib.h>
#include <iomanip.h>
void bulldFile(fstream& fsData);
void printFile(fstream& fsData);
void randomPrint(fstream& fsData);
int main()
{
fstream fsData;
bulldFile(fsData);
printFile(fsData);
randomPrint(fsData);
return 0;
}
void bulldFile(fstream& fsData)
{
if(!fsData)
{
cerr<<"Error opening file writing"<<endl;
exit(100);
}
for(int i=1;i<=10;i++)
{
int data;
data = i+1;
fsData.write((char*)&data,sizeof(int));
}
}
void printFile(fstream& fsData)
{
cout<<"File contents in sequnetial order."<<endl;
int data;
int recNum = 0;
for(int i=0;i<10;i++)
cout<<"Record"<<setw(4)<<recNum++<<"==>"<<(data = (recNum+1)*(recNum+1))<<endl;
fsData.clear();
}
void randomPrint(fstream& fsData)
{
cout<<"File contents in random sequence."<<endl;
int data;
int randSeek;
for(int i=0;i<10;i++)
{
randSeek=(rand()%10);
fsData.read((char*)&data,sizeof(int));
cout<<"Record"<<setw(4)<<randSeek<<"==>"<<setw(4)<<(data = (randSeek+1)*(randSeek+1))<<endl;
}
fsData.close();
}
#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <stdlib.h>
#include <iomanip.h>
void bulldFile(fstream& fsData);
void printFile(fstream& fsData);
void randomPrint(fstream& fsData);
int main()
{
fstream fsData;
bulldFile(fsData);
printFile(fsData);
randomPrint(fsData);
return 0;
}
void bulldFile(fstream& fsData)
{
if(!fsData)
{
cerr<<"Error opening file writing"<<endl;
exit(100);
}
for(int i=1;i<=10;i++)
{
int data;
data = i+1;
fsData.write((char*)&data,sizeof(int));
}
}
void printFile(fstream& fsData)
{
cout<<"File contents in sequnetial order."<<endl;
int data;
int recNum = 0;
for(int i=0;i<10;i++)
cout<<"Record"<<setw(4)<<recNum++<<"==>"<<(data = (recNum+1)*(recNum+1))<<endl;
fsData.clear();
}
void randomPrint(fstream& fsData)
{
cout<<"File contents in random sequence."<<endl;
int data;
int randSeek;
for(int i=0;i<10;i++)
{
randSeek=(rand()%10);
fsData.read((char*)&data,sizeof(int));
cout<<"Record"<<setw(4)<<randSeek<<"==>"<<setw(4)<<(data = (randSeek+1)*(randSeek+1))<<endl;
}
fsData.close();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询