1、1 定义一个输出:“Hello,world.”的类(Hello ) 。要求:1)在 Hello 类中没有数据成员;2)包括以下成员函数:类的构造函数,功能是输出:Hello ;类的析构函数,功能是输出:world.3)在主函数 main 中,按照 Hello 类创建一个对象 hello,通过运行该程序,说说构造函数、析构函数在何时执行?#include using namespace std;class Hellopublic:Hello()cout#include using namespace std;class Triangledouble a;double b;double c;pub
2、lic:Triangle(double a_=0,double b_=0,double c_=0):a(a_),b(b_),c(c_)double area()double s;s=(a+b+c)/2;double area=sqrt(s*(s-a)*(s-b)*(s-c);return area;void setA(double a_)a=a_; int getA() constreturn a; Triangle();int main()Triangle t(3,4,5);t.setA(2);cout#include using namespace std;class Trianglarp
3、rismdouble a;double b;double c;double height;public:Triangle(double a_=0,double b_=0,double c_=0,double h=0):a(a_),b(b_),c(c_)double area()double s;s=(a+b+c)/2;double area=sqrt(s*(s-a)*(s-b)*(s-c);return area;void setA(double a_)a=a_; int getA() constreturn a; Triangle();int main()Trianglarprism t(3
4、,4,5,10);t.setA(2);coutusing namespace std;int main()int n;coutn;if(n%2=0)coutusing namespace std;class Matrix public: Matrix(); Matrix:Matrix() for(int i=0;imatij;void Matrix:display() for (int i=0;i2;i+) for(int j=0;j3;j+) coutmatij“ “;coutendl;int main()Matrix a,b,c;a.input(); b.input(); coutendl“Matrix a:“endl; a.display(); coutendl“Matrix b:“endl; b.display(); c=a+b;