二道C++的题目 急急急啊!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/23 16:40:35
写出程序运行结果
1.
#include <iostream.h>
void main()
{
int x=5,y=4;
switch(x%2);
{
case 1; switch (y)
{
case 0;cout<<"AAAA\t";
case 1;cout<<"BBBB\t";break;
default;cout<<"cccc\t";
}
case 2;cout<<"Thanks\n";
}
}

2.
#include<iostream.h>
class A
{
public;
A(){a=5;b=10;cout<<"Default constructor.\n;}
A(int i,int j) {a=i,b=j;cout<<"Constructor.\n"}
~A() {cout<<"Destructor.\n"}
void print() {cout<<"a="<<a<<",b="<<b<<endl:}
private;
int a,b;
};
void main ()
{ A obj1,obj2(10,20);
obj1.print();
0bj2.print();
}

第一题
Thanks

第二题
Default constructor.
Constructor.
a=0,b=0
a=10,b=20
Destructor.
Destructor.

你写的什么烂程序 编译都不行
switch后面还写什么分号 你有没有学C++啊
#include <iostream.h>
void main()
{
int x=5,y=4;
switch(x%2)
{
case 1:
{
switch (y)
{
case 0:cout<<"AAAA\t";
case 1:cout<<"BBBB\t";break;
default:cout<<"cccc\t";
}
}
case 0:cout<<"Thanks\n";
default:break;
}
}
运行结果是 cccc Thanks

#include<iostream.h>
class A
{
public:
A()
{
a=5;b=10;
cout<<"Default constructor.\n";}
A(int i,int j)
{
a=i,b=j;
cout<<"Constructor.\n";
}

~A()
{
cout<<"Destructor.\n";
}
void print()
{
cou