第1题
A.2
B.3
C.4
D.5
第2题
A.functionl运行1次,function2运行2次
B.functionl运行2次,function2运行l次
C.functionl运行2次,function2运行3次
D.functionl运行2次,function2运行2次
第3题
#include<iostream>
usingnamespacestd;
voidfunction2(intn);
voidfunctionl(intn):{
if(n<=0)return;
function2(n-2);
}
voidfunction2(intn){
if(n<=O)return;
functionl(n-1);
}
intmain(){
functionl(5);
return0;
}
下列关于程序运行情况的描述中,正确的是( )。
A.functionl运行1次,function2运行2次
B.functionl运行2次,function2运行l次
C.functionl运行2次,function2运行3次
D.functionl运行2次,function2运行2次
第4题
#include(iostream>
usingnamespacestd;
longfun(intn)
{
if(n)2)
return(fun(n-1)+fun(n-2));
else
return2;
}
intmain( )
{
cout<<fun(3)<<endl;
return0;
}
则该程序的输出结果应该是( )。
A.2
B.3
C.4
D.5
第5题
#include<iostream>
using namespace std;
class Pair{
int m;
int n;
public:
Pair ( int i , int j ) : m ( i ) , n ( j ) {}
boot operator > ( pair p ) const; // 须在类体外给出定义
} ;
int main () {
Pair Al ( 3,4 ) , p2 ( 4,3 ) ; p3 ( 4,5 ) ;
Cout<< ( pl>p2 ) << ( P2>P1 ) << ( p2>p3 ) << ( p3>p2 ) ;
return 0;
}
运算符函数 。 operator> 的功能是比较两个 Pair 对象的大小 , 当左边对象大时 , 返回 true , 否则返 回false 。 比较规则是首先比较两对象的 m 成员 , m 大者为大 ; 当 m 相等时比较 n , n 大者为大 。 程序输出 0101 ,下列对运算符重载函数的正确定义是
A ) bool Pair::operator> ( Pair p ) const
{if ( m!=p.m ) return m>p.m; return n>p.n;}
B ) bool Pair:;operator> ( Pair p )
{if ( m!=p.m ) return m>p.m; return n>p.n;}
C ) bool Pair::operator> ( Pair p ) const
{if ( m>p.m ) return true; return n>p.n;}
D ) bool Pair:;operator> ( Pair p )
{if ( m>p.m ) return true; return n>p.n;}
第6题
}}}}include<iostream>
using namespace std;
class Pair{
int m;
int n;
public:
Pair(int i,int J):m(i),n(J){}
bool operator>(Pair P)const; //需在类体外给出定义
};
int main(){
Pair pl(3,4),p2(4,3),p3(4,5);
COUt<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);
return 0;
{
运算符函数operator>功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n.n大者为大。程序输出0101,下列对运算符重载函数的正确定义是
A.bool Pair::operator>(Pair P)const {if(m!=P.m)return m>P.m;return n>P.n;)
B.bool Pair::operator>(Pair P) {if(m!=P.m)return m>P.m;return n>P.n;)
C.bool Pair::operator>(Pair P)const {if(m>P.m)return true;return 11>P.n;)
D.bool Pair::operator>(Pair P) {if(m>P.m)return true;return 11>P.n;}
第7题
}}}}include<iostream>
using namespace std;
class Pair{
int m;
int n;
public:
Pair(int i,int J):m(i),n(J){}
bool operator>(Pair P)const; //需在类体外给出定义
};
int main(){
Pair pl(3,4),p2(4,3),p3(4,5);
COUt<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);
return 0;
{
运算符函数operator>功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n.n大者为大。程序输出0101,下列对运算符重载函数的正确定义是
A.bool Pair::operator>(Pair P)const {if(m!=P.m)return m>P.m;return n>P.n;)
B.bool Pair::operator>(Pair P) {if(m!=P.m)return m>P.m;return n>P.n;)
C.bool Pair::operator>(Pair P)const {if(m>P.m)return true;return 11>P.n;)
D.bool Pair::operator>(Pair P) {if(m>P.m)return true;return 11>P.n;}
第8题
include<iostream>
using namespace std;
template <class T>
void sort(T b[],int n)
{
T temp;
int i,j;
T *a=new T[n];
for (i=0;i<n;i++){a[i]=b[i];}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{ if(a[i]>a[j])
{temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<n;i++){cout<<a[i]<<" ";}
cout<<endl;
delete []a;
}
void main()
{
int i,n=6;
int a[]={5,1,9,10,3,8};
____________;
for(i=0;i<n;i++)
{cout<<a[i]<<" ";}
cout<<endl;
}
第9题
阅读程序。阅读下列C++程序(共2个文件)。阅读后请说明程序的功能,并对每条语句进行注释,说明其作用。添加注释并提交源程序(请粘贴源代码或屏幕截图,不要上传附件)。 // 程序文件:1.cpp #include <iostream> using namespace std; void fun(int x) { if (x < 0) { cout << ‘-‘; x = -x; } while (x != 0) { cout << x%10; x /= 10; } cout << endl; } void fun(char *str) { int N = 0; while (str[N] != ‘\0’) N++; for (int n = N-1; n >= 0; n--) cout << str[n]; cout << endl; } // 程序文件:2.cpp #include <iostream> using namespace std; extern void fun(int x); extern void fun(char *str); int main( ) { fun( -2015 ); fun( “-2015” ); return 0; }
第10题
include<iostream>
using namespace std;
void copystr(_______________)
{
int n=0;
while(n<m-1)
{
n++;
p1++;
}
while(*p1!=&39;\0&39;)
{
*p2=*p1;
p1++;
p2++;
}
*p2=&39;\0&39;;
}
void main()
{
int m;
char str1[20],str2[20];
cout<<"输入字符串1:";
______________;
cout<<"从第m个字符串开始复制,请输入m:";
cin>>m;
if(strlen(str1)<m)
cout<<"输入超过str1的长度"<<endl;
else
{
copystr(str1,str2,m);
cout<<"复制的字符串是:"<<str2<<endl;
}
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!