请c++高手对指出以下程序错误处~~~谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/21 06:26:57
1. #include<iostream>
using namespace std;
int main()
{ cout<<"This is a program."
return 0;
}
2. #include<iostream>
using namespace std;
int main()
{
x=3;
int y=x*x;
cout<<"y="<<y<<"\n";
return 0;
}
3. #include<iostream>
using namespace std;
class Aa
{
public:
Aa(int i=0){a=i; cout<<"Constructor "<<a<<endl; }
~Aa(){ cout<<"Destructor "<<a<<endl; }
void print( ){cout<<a<<endl;}
private:
int a;
};
int main()
{
Aa al(1),a2(2);
al.print();
cout<<a2.a<<endl;
return 0;
}

4.class A
{
int a,b;
public:
A(int aa,int bb){a=aa;b=bb;}
};
int main()
{
A

1.少“;”
2.x 无类型
3.访问权限
4.初始化实例的构造函数无定义 构造函数应该有个缺省值
5.Test::x没赋值 应该这么写 int Text::x =20;

不提供帮忙写作业服务,希望你尊重自己的学业

1."后面加;
2.int x=3;
3.Aa的constuctor你定义的是带默认参数的,调用的时候是带一个参数的,所以找不到合适的
4.错误和上面类似,x(2)只有一个参数,定义的是两个参数的
5.类里面的x没初始化,输不出来~