c++初学者,一个程序看不懂,请大神帮我解释一下每句话的含义,

c++初学者,一个程序看不懂,请大神帮我解释一下每句话的含义,

题目
c++初学者,一个程序看不懂,请大神帮我解释一下每句话的含义,
编写两个函数,函数的原型分别是:
void WriteFile(charfile_name[],double a[5][8]);
doubleReadElement(char file_name[],int i,int j);
第一个函数的功能是将指定数组写入到指定二进制文件内,第二个函数是从前一个函数写入的文件中读出元素.并编写主函数验证所写的函数.
#include
#include
using namespacestd;
void WriteFile(charfile_name[],double a[5][8])
{fstreamout(file_name,ios::out|ios::binary);
out.write((char*)&a[0][0],5*8*sizeof(double));
out.close();}
doubleReadElement(char file_name[],int i,int j)
{
fstreamin(file_name,ios::in|ios::binary);
double el;
in.seekg((i*8+j)*sizeof(double),ios::beg);
in.read((char*)&el,1*sizeof(double));
in.close();
return el;
}
void main()
{
int i,j;
double b[5][8];
double a[5][8];
char file_name[10];
coutfile_name;
cout
答案
#include //导入iostream库
#include //导入fstream库
using namespace std; //声明导入std命名空间中的所有成员
void WriteFile(char file_name[],double a[5][8]) //声明一个无返回值的WriteFile函数
{fstream out(file_name,ios::out|ios::binary); //以二进制写方式打开file_name指定的文件(并覆盖).
out.write((char*)&a[0][0],5*8*sizeof(double)); //向这个文件中写入double数组a中的所有数据.
out.close();} //关闭文件流.
doubleReadElement(char file_name[],int i,int j) //声明一个返回double的函数
{fstream in(file_name,ios::in|ios::binary); //以读方式打开文件
file_namedouble el; //声明一个double的el.
in.seekg((i*8+j)*sizeof(double),ios::beg); //将文件读取指针指向i,j指定的位置.
in.read((char*)&el,1*sizeof(double)); //从这个位置读取一个double数据到el中.
in.close(); //关闭文件流
return el; //返回读取的数据
}
void main(){
int i,j;
double b[5][8];
double a[5][8];
char file_name[10];
coutfile_name;
cout
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.