
问个菜鸟C++问题:请问下面两个函数有什么区别?
#include<iostream>intstonetolb(int);intmain(){usingnamespacestd;cout<<"Entertheweight...
#include<iostream>
int stonetolb(int);
int main()
{
using namespace std;
cout<<"Enter the weight in stone: ";
int stone;
cin>>stone;
int pounds=stonetolb(stone);
cout<<stone<<" stone=";
cout<<pounds<<" pounds"<<endl;
return 0;
}
int stonetolb(int sis)
{
return 14*sis;
}
#include<iostream>
int main()
{
using namespace std;
cout<<"Enter the weight in stone: ";
int stone;
cin>>stone;
int pounds=14*stone;
cout<<stone<<" stone=";
cout<<pounds<<" pounds"<<endl;
return 0;
}
非常感谢两位哥哥的帮助,如果在实际运行工作中哪一个会比较好呢? 展开
int stonetolb(int);
int main()
{
using namespace std;
cout<<"Enter the weight in stone: ";
int stone;
cin>>stone;
int pounds=stonetolb(stone);
cout<<stone<<" stone=";
cout<<pounds<<" pounds"<<endl;
return 0;
}
int stonetolb(int sis)
{
return 14*sis;
}
#include<iostream>
int main()
{
using namespace std;
cout<<"Enter the weight in stone: ";
int stone;
cin>>stone;
int pounds=14*stone;
cout<<stone<<" stone=";
cout<<pounds<<" pounds"<<endl;
return 0;
}
非常感谢两位哥哥的帮助,如果在实际运行工作中哪一个会比较好呢? 展开
4个回答
展开全部
两个作用是一样的。
但第一个比第二个要好。因为:第一个程序中,stonetolb被分离出来,作为一个独立的业务逻辑函数存在,为其他应用服务,main作为stonetolb的调用者,它只关心stonetolb的输入和输出,不关心stonetolb的内部实现。从分层和模块化角度来说,这样处理比较好。
第二个程序,一般来说就是初学者写出来的程序。
但第一个比第二个要好。因为:第一个程序中,stonetolb被分离出来,作为一个独立的业务逻辑函数存在,为其他应用服务,main作为stonetolb的调用者,它只关心stonetolb的输入和输出,不关心stonetolb的内部实现。从分层和模块化角度来说,这样处理比较好。
第二个程序,一般来说就是初学者写出来的程序。
展开全部
第一个在main中调用了int stonetolb(int)函数,在第二行声明的,功能是将传入的int乘14返回;
第二个直接将此功能写在了main函数中了:int pounds=14*stone;
第二个直接将此功能写在了main函数中了:int pounds=14*stone;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这么短的程序用第二个吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一个POUND是通过函数取值,一个是直接在MAIN里计算取得,
运行效率来看,第二个比较快。
运行效率来看,第二个比较快。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询