C++程序填空题三道 100
填程序题1.Thefollowingprogramusestaticdatamemberobj_counttocountthetotalnumberoftheobject...
填程序题
1. The following program use static data member obj_count to count the total number of the objects that have been created, please fill in the blanks.
#include<iostream>
___________________
class CL
{ static int obj_count;
int x;
___________________
CL() { obj_count++;}
CL(int i){ x=i; obj_count++;}
~CL() { obj_count--; }
static int get_num()
{ return obj_count; }
};
____________________
void main()
{ CL a1;
CL a2(10);
CL a3[10];
cout<<CL::get_num()<<endl;
}
2.The following program use array to sort the 10 numbers that input from the keyboard by ascending(升序),please fill in the blanks.
#include<iostream>
using namespace std;
void main()
{
int a[10],i,j,temp;
for(i=0;i<=9;i++)
_____________
for(i=0;i<10;i++)
for(j=0;j<10-i-1;j++)
________________
{ temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
for(i=0;i<=9;i++)
cout<<a[i]<<endl;
}
3.class A{
int i;
public:
A(int ii){
_____________;
cout<<”The constructor is called”<<endl;
}
A(_____________){
Cout<<”the copy constructor is called”<<endl;
}
~A(){
cout<<”The destructor is called”
}
};
void main(){
A a(3);
A b=a;
}
请给出具体答案,并说明填空的原理和考点,最好给出一些例子,说明越明白详细,越好。谢谢。 展开
1. The following program use static data member obj_count to count the total number of the objects that have been created, please fill in the blanks.
#include<iostream>
___________________
class CL
{ static int obj_count;
int x;
___________________
CL() { obj_count++;}
CL(int i){ x=i; obj_count++;}
~CL() { obj_count--; }
static int get_num()
{ return obj_count; }
};
____________________
void main()
{ CL a1;
CL a2(10);
CL a3[10];
cout<<CL::get_num()<<endl;
}
2.The following program use array to sort the 10 numbers that input from the keyboard by ascending(升序),please fill in the blanks.
#include<iostream>
using namespace std;
void main()
{
int a[10],i,j,temp;
for(i=0;i<=9;i++)
_____________
for(i=0;i<10;i++)
for(j=0;j<10-i-1;j++)
________________
{ temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
for(i=0;i<=9;i++)
cout<<a[i]<<endl;
}
3.class A{
int i;
public:
A(int ii){
_____________;
cout<<”The constructor is called”<<endl;
}
A(_____________){
Cout<<”the copy constructor is called”<<endl;
}
~A(){
cout<<”The destructor is called”
}
};
void main(){
A a(3);
A b=a;
}
请给出具体答案,并说明填空的原理和考点,最好给出一些例子,说明越明白详细,越好。谢谢。 展开
7个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询