// Note:Your choice is C++ IDE
#include "iostream.h"
#include "math.h"
class CalcSqrt
{
public:
CalcSqrt(float x)
{
y=x;
}
void print()
{
cout<<sqrt(y)<<endl;
}
private:
float y;
};
void main()
{
CalcSqrt x(把参数放到这里);
x.print();
}
用“文件名 参数”的格式执行程序,要求把参数填到倒数第三行括号内。
c语言如果想接收命令行参数,则main()函数要写成如下形式:
int main( int argc, char *argv[] )
说明:
int argc 表示参数个数,包括执行程序名,如果没有参数,该值为1
char *argv[] 表示参数列表,每个参数都是一个字符串。argv[0]是执行程序名
参考代码:
#include <stdio.h>能不能输入完整的代码?不知道怎么用。我初学。
追答// Note:Your choice is C++ IDE
#include
#include "math.h"
using namespace std;
class CalcSqrt
{
public:
CalcSqrt(float x)
{
y=x;
}
void print()
{
cout<<sqrt(y)<<endl;
}
private:
float y;
};
int main(int argc,char *argv[])
{
double a=atof(argv[1]);
CalcSqrt x(a);
x.print();
system("pause");
}