业余无线电 更换呼号:C++初级题目,大虾帮忙啊~~~~
来源:百度文库 编辑:杭州交通信息网 时间:2024/06/16 04:49:44
,送到用户指定的输出文件中。输入,输出文件名由用户在命令行给定。
提示:根据题
意,命令行格式为
change inputfilename output
其中, change 是该程序的名称。
2~~~设有一个大小可变的整型数组类;
class Array{
protected:
int Size ;
//数组的大小
int *Arr ; //数组的首地址
public :
Array (int
sz = 100 ); //构造函数:申请含sz个元素的动态整型数组
~ Array ( );
//析构函数:释放动态整型数组
int& GetElem (int i ); //设置/取下标为i的元素
}
;
试完成该类各成员函数的定义。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define MAX_LEN 1024
int main(int argc, char *argv[])
{
if( argc!=3 )
{
cout << "Usage:\n\t" << argv[0] << " <SrcFile> <DstFile>" << endl;
return -1;
}
int len;
char data, line[MAX_LEN];
ifstream sSrc(argv[1]);
if( sSrc.fail() )
{
cout << "Open file " << argv[1] << " failed : " << strerror(errno) << endl;
return -1;
}
ofstream sDst(argv[2]);
if( sSrc.fail() )
{
cout << "Open file " << argv[2] << " failed : " << strerror(errno) << endl;
sSrc.close();
return -1;
}
sSrc.getline(line, sizeof(line));
while( !sSrc.eof() )
{
if( (len=strlen(line))>1 )
{
data = line[0];
if( data>96 && data<123 )
line[0] = data - 32;
}
sDst.write(line, strlen(line));
sDst.put('\n');
sSrc.getline(line, MAX_LEN);
}
sSrc.close();
sDst.close();
return 0;
}
同意楼上