
C++高手来帮我解决下这道题,谢谢!
4)程序4#include<iostream.h>classsample{intn;staticintm;public:sample(intk){n=k;m+=k;}st...
4) 程序4
#include <iostream.h>
class sample{
int n;
static int m;
public:
sample(int k){n=k; m+=k;}
static void disp(sample c){cout<<c.n<<","<<m<<endl;}
~sample(){}
};
int sample::m=0;
void main()
{
sample x(2),y(4);
sample::disp(x);
sample::disp(y);
}
5) 程序5
#include<iostream.h>
void main()
{
int i=1,j=2,k=3,a=10;
if(!i) a--;
else if(j)
if(k) a=5;
else a=6;
a++;
cout<<a<<endl;
}
6) 程序6
#include <iostream.h>
int f(int j);
int main()
{
int i;
for(i=0;i<5;i++) cout<<f(1)<<" ";
return 0;
}
int f(int j)
{
static int k=1;
for(;j>0;j--) k+=j;
return k;
}
7) 程序7
#include<iostream.h>
coid f(){
static int b=100;
int c=100;
c+=2; b+=2;
cout<<c<<”;”<<b<<endl;
}
void main(){
int k;
for(k=0;k<2;k++) f();
}
题目是让写出这些程序的运行结果,哪位高手会,帮忙解答一下,谢谢咯! 展开
#include <iostream.h>
class sample{
int n;
static int m;
public:
sample(int k){n=k; m+=k;}
static void disp(sample c){cout<<c.n<<","<<m<<endl;}
~sample(){}
};
int sample::m=0;
void main()
{
sample x(2),y(4);
sample::disp(x);
sample::disp(y);
}
5) 程序5
#include<iostream.h>
void main()
{
int i=1,j=2,k=3,a=10;
if(!i) a--;
else if(j)
if(k) a=5;
else a=6;
a++;
cout<<a<<endl;
}
6) 程序6
#include <iostream.h>
int f(int j);
int main()
{
int i;
for(i=0;i<5;i++) cout<<f(1)<<" ";
return 0;
}
int f(int j)
{
static int k=1;
for(;j>0;j--) k+=j;
return k;
}
7) 程序7
#include<iostream.h>
coid f(){
static int b=100;
int c=100;
c+=2; b+=2;
cout<<c<<”;”<<b<<endl;
}
void main(){
int k;
for(k=0;k<2;k++) f();
}
题目是让写出这些程序的运行结果,哪位高手会,帮忙解答一下,谢谢咯! 展开
2个回答
展开全部
4.
2,6
4,6
5.
6
6.
2 3 4 5 6
7.
102;102
102;104
你没要解答我就不解释了。上面的就是运行结果
2,6
4,6
5.
6
6.
2 3 4 5 6
7.
102;102
102;104
你没要解答我就不解释了。上面的就是运行结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询