高分求做C++练习题3

来源:百度知道 编辑:UC知道 时间:2024/05/06 09:42:29
25. Which is the running result of following program?
#include <iostream.h>
class X{
public:
X(int);
X(X&);
~X();
};

X::X(int s){ cout <<"constructor " <<s <<endl; }
X::X(X& x){ cout <<"copy-constructor\n"; }
X::~X(){ cout <<"destructor\n"; }

X f(X &x)
{
cout <<"hello\n";
return x;
}
void main()
{
X a(1);
X b=f(a);
}
A. B.
constructor 1 constructor 1
hello copy-constructor
copy-constructor hello
destructor copy-constructor
destructor destructor
destructor
destructor

C. D.
constructor 1

25.
constructor 1
hello
copy-constructor
destructor
destructor
第一题:
# include<iostream>
using namespace std;
const int N=10;
void f(int number[ ], int n, int &min, int &max) //实现求number数组中

的最大数和最小数
{
//①
for ( int i = 0; i < n; i++ )
{
if(number[i]< min)
//②
min = number[i];
else if(number[i]> max)
//③
max = number[i];
}
}
void main()
{
int num[N];
int min,max;
for(int i=0;i<N;i++)
cin>>num[i];
//④
min = 100; max = 0;
//⑤
f( num, N, min, max );
cout<<"the least of the 10 number is :"<<min<<endl;
cout<<"the last of the 10 number is :"<<max<<endl;
}
第二题:
#include <iostream>
//①
using namespace std;
class Clock
{
//②
i