关于C++的一些题目!!!

四、写出程序的运行结果
1、
#include <iostream>
using namespace std;
void main()
{
int a,b,c,d=5;
c=2,c+=10;
a=b=10;
a*=2;
b/=2;
c%=2;
cout<<a<<","<<b<<","<<c<<endl;
}

2、
#include <iostream>
using namespace std;
void main()
{
int a=50,b=0;
b=++a;
cout<<a<<","<<b<<endl;
b=a++;
cout<<a<<","<<b<<endl;
}

3、
#include <iostream>
using namespace std;
void main()
{
int f=2002, x;
if(f!=3)
x=2003;
else
x=20;
cout<<f<<","<<x<<endl;
}

4、
#include <iostream>
using namespace std;
void main()
{
int i=1,sum=0;
while(i<=10) sum+=++i;
cout <<"sum="<<sum<<",i="<<i<<endl;
}

5、
#include <iostream>
using namespace std;
void main()
{
int i;
for(i=4;i<=10;i++)
{ if(i%3==0) continue;
cout<<i<<endl;
}
}

6、
#include <iostream>
using namespace std;
void main()
{
char flag='c' ;
switch(flag)
{
case 'a': cout<<"1"<<endl;
case 'b': cout<<"2"<<endl; break;
case 'c': cout<<"3"<<endl;
default: cout<<"4"<<endl; break;
}
}

7、
#include <iostream>
using namespace std;
void swap(int &a,int &b);
void main()
{
int x=10, y=7;
cout<<"x="<<x<<",y="<<y<<endl;
swap(x,y);
cout<<"x="<<x<<",y="<<y<<endl;
}
void swap(int &a,int &b)
{ int temp; temp=a; a=b; b=temp; }

8、
#include <iostream>
using namespace std;
int add(int a,int b);
void main()
{
extern int x,y;
cout<<add(x,y)<<endl;
x/=y;
cout<<add(x,y)<<endl;
}
int x=50,y=100;
int add(int a,int b)
{ int s=a+b; return s; }

9、
#include <iostream>
using namespace std;
class A
{ public:
A(int aa=0){a=aa;}
~A(){cout<<"Destructor A!"<<a<<endl;}
private:
int a;
};
class B:public A
{ public:
B(int aa=0,int bb=0):A(aa){b=bb;}
~B(){cout<<"Destructor B!"<<b<<endl;}
private:
int b;
};
void main()
{ B x(5),y(6,7); }

10、
#include <iostream>
using namespace std;
int func(int a)
{ int b=0;
static int c=4;
b++; c--;
return(a+b+c);
}
void main()
{ int a=2;
for(int j=0;j<2;j++)
cout<<func(a+j)<<" ";
}

11、
#include <iostream>
using namespace std;
void main()
{ int x=3,y=3;
switch(x%2)
{ case 1: switch (y)
{ case 0: cout<<"First\t";
case 1: cout<<"Second\t"; break;
default: cout<<"Hellow\t";
}
case 2: cout<<"Third\n";
}
}

五、程序设计题
1、编写一个函数,函数名为swap,实现两个数的交换。
2、编写一个函数,函数名为min,要求返回三个整数形参中的最小值。
4、编程打印如下图形:
1
22
333
4444
55555

1 20,5,0
2 51, 51
52 ,51
3 2002,2003
4 sum = 65 ,i = 11
5 4
5
7
8
10
6 3
4
7 x = 10,y = 7
x = 7,y = 10
8 150
100
9 Destructor B!7
Destructor A!6
Destructor B!0
Destructor A!5
10 6 6
11 Hellow Third

五1.void swap(int &a,int &b)
{
int tmp ;
tmp = a;
a = b;
b = tem;
}
2. int min(int a,int b,int c)
{
return (a>b?b:a)>c?c:(a>b?b:a);
}
3
void fun(void)
{
cout<<"1"<<endl;
cout<<"22"<<endl;
cout<<"333"<<endl;
cout<<"4444"<<endl;
cout<<"55555"<<endl;
}追问

请问选择,填空,等所有题目都是正确答案吗?

追答

是我心中认为的正确答案。我不会把我认为的错误答案写上去当正确答案的。

来自:求助得到的回答
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-07
你自己跑一下不就行了追问

但是选择填空之类的没法跑啊?

相似回答