请教几个c++的简单问题,希望高手不吝赐教~

来源:百度知道 编辑:UC知道 时间:2024/05/28 18:54:51
1. What is the output of the following program?
#include <iostream>
void figure_me_out (int& x, int y, int& z);
int main( )
{
using namespace std;
int a, b, c;
a=10;
b=20;
c=30;
figure_me_out(a, b, c);
cout<< a << “ “ << b << “ “ <<c;
return 0;
}

void figure_me_out(int& x, int y, int& z)
{
using namespace std;
cout << x <<” “<<y<<” “ <<z<<endl;
x=1;
y=2;
z=3;
cout<<x<<” “ <<y<<” “<<z<<endl;
}

2.Write a void function definition for a function called zero_both that has two reference parameters, both of which are variables of type int, and sets the values of both variables to 0.

3.Suppose you have two function definitions with the following function declarations:
double score (double time,

第一题答案:
10 20 30
1 2 3
1 20 3
很简单,引用与指针的效果是一样的
-------------------------------------------
第二题答案:
void zero_both(int & a,int &b)
{
a=b=0;
}
-------------------------------------------
第三题答案:
假如你有两个函数声明
double score (double time, double distance);
int score (double points);
下面的函数调用将用哪一个函数(x 是 double类型)
final_score = score(x);
当然是int score (double points);
--------------------------------------------
第四题答案:
写一个把米与厘米转换成英寸的程序,子任务要用函数完成。
很简单,答案略。

第一道:10 20 30
1 2 3
1 20 3
明天写后面的。

第一道:输出结果是10 20 30
1 2 3
1 2 3
第二道: void zero_both (int &a,int &b)
{
a=0;
b=0;
}
第三道: 会调用第二个函数int score (double points); 。
这是关于函数重载的,调用函数score,编译器会拿实参的个数和类型与前边已声明或定义过的以score为名字的函数的形参进行匹配,第一个函数有两个形参,不能被调用,而对于第二个函数int型的实参可以隐式转换为double型,当然这中间有很多原则,建议参考一下c++Primer第四版的第七章,有详细说明
第四道:
#include&l