1、编写一个类LEI,打印其私有成员变量a的值,并测试该类。#includeiostreamusingnamespacestd;classLEI{public:LEI(inti){a=i;}voidget(){coutaendl;}private:inta;};voidmain(){LEIA(10);A.get();}2、用面向对象的方法完成对三个数从大到小的排序并输出,并测试该类。#includeiostreamusingnamespacestd;classSort{public:Sort(){};Sort(inti,intj,intk){a=i;b=j;c=k;}voidmax(inta,intb,intc){if(a=b&&b=c)coutabcendl;if(ac&&cb)coutacbendl;if(bc&&ca)coutbcaendl;if(ba&&ac)coutbacendl;if(ca&&ab)coutcabendl;elsecoutcbaendl;}private:inta,b,c;};voidmain(){SortB;B.max(3,4,5);}3、定义类lei,完成一个整形数的输入和输出,并测试该类。#includeiostreamusingnamespacestd;classIO{public:IO(){};voidinput(){cina;}voidoutput(){coutaendl;}private:inta;};voidmain(){IOA;A.input();A.output();}4、用面向对象的方法,完成圆类的定义#includeiostreamusingnamespacestd;classCircle{public:Circle(doublei){r=i;}voidPrintf(){cout3.14*r*rendl;}private:doubler;};//下面为数据测试,本题不需要voidmain(){CircleB(4.0);B.Printf();}5、从键盘上输入一个3*3的整数矩阵,求其各行的平均值并输出,输出时保留位小数。#includeiostream#includeiomanip//小数定义文件usingnamespacestd;intmain(){inta[3][3],i,j;doubleave,b[3];for(i=0;i3;++i){for(j=0;j3;++j){cina[i][j];}ave=(a[i][0]+a[i][1]+a[i][2])/3.0;b[i]=ave;}for(i=0;i3;i++)coutsetprecision(3)fixedb[i]endl;return0;}6、编一个程序计算球体、正方体和圆柱体的体积。要求:(1)抽象出一个公共基类Cube为抽象类,在其中定义一个公共的数据成员radius,此数值可以作为球体的半径和圆柱体底面圆半径;定义对radius进行读写的设置函数和获取函数,再定义求体积的纯虚函数volume和显示半径的虚函数print;(2)由Cube派生出球体类Sphere,其中有求体积的实际定义;(3)从Cube派生出square类,新定义length,并可以对其进行读写,再定义volume和print函数;(3)在测试程序中分别创建一个Sphere类、square和一个Cylinder类的对象,通过调用相关成员函数显示其数据成员和体积信息。#includeiostreamusingnamespacestd;classCube{public:Cube(){};Cube(doublei){r=i;cout半径为:rendl;}private:doubler;};classSphere:publicCube{public:Sphere(){};Sphere(doublei):Cube(i){r=i;}voidvolume(){cout球体的体积为:(4*3.14*r*r*r)/3.0endl;}private:doubler;};classsquare:publicCube{public:square(){};square(doublei):Cube(i){length=i;}voidvolume(){V=length*length*length;}voidprintf(){cout正方体的体积为:Vendl;}private:doublelength,V;};classCylinder:publicCube{public:Cylinder(doublei):Cube(i){r=i;}voidvolume(){V2=3.14*r*r*r;}voidprintf(){cout圆柱体的体积为:V2endl;}private:doubler,V2;};voidmain(){SphereA(3.4);A.volume();squareB(3.4);B.volume();B.printf();CylinderC(3.4);C.volume();C.printf();}7、用面向对象方法从键盘输入12个数存入二维数组a[3][4]中,编写程序求出最大元素的值及它所在的行号和列号。#includeiostreamusingnamespacestd;intmain(){inta[3][4],i,j,max,b,c;for(i=0;i3;++i){for(j=0;j4;++j){cina[i][j];if(i==0&&j==0)max=a[0][0];if(a[i][j]max){max=a[i][j];b=i+1;c=j+1;}}}cout最大数为:max行数为:b列数为:cendl;return0;}8、用面向对象的方法设计求圆的面积、周长。要求:⑴、写出类Circle(圆)的定义,成员函数setRadius设置半径、getArea求面积以及getPerimeter求周长;⑵、在主函数中,从键盘输入半径,输出其面积和周长。#includeiostreamusingnamespacestd;classCircle{public:Circle(){};voidsetRadius(){cinr;}voidgetArea(){cout圆的面积是:3.14*r*rendl;}voidgetPerimeter(){cout圆的周长是:2*3.14*rendl;}private:doubler;};voidmain(){CircleA;A.setRadius();A.getArea();A.getPerimeter();}9、编写一个求方程ax2+bx+c=0的根的程序,用3个函数分别求当b2-4ac大于零、等于零、和小于零时的方程的根。要求从主函数输入a,b,c的值并输出结果。#includeiostream#includemath.husingnamespacestd;voidX(doublei,doublej,doublek){cout方程的根是:(-j+sqrt(j*j-4*i*k))/(2*i)和(-j-sqrt(j*j-4*i*k))/(2*i)endl;}voidX1(doublei,doublej,doublek){cout方程的根是:-j/(2*i)endl;}voidX2(doublei,doublej,doublek){cout方程无解!endl;}voidmain(){doublea,b,c;cout请输入a,b,c的值:;cinabc;if(b*b-4*a*c0)X(a,b,c);elseif(b*b-4*a*c==0)X1(a,b,c);elseX2(a,b,c);}10、定义一个复数类Complex,形式如下:RealPart(实部)+ImgPart(虚部)*i。定义含两个参数的构造函数、一个Show()函数(用以输出Real,ImgPart的值),另外作为成员函数重载的运算符”+”和“-”(功能是将此类二个对象相加、减)。#includeiostreamusingnamespacestd;classComplex{public:Complex(){RealPart=0;ImgPart=0;}Complex(doublea,doubleb){RealPart=a;ImgPart=b;}voidshow(){cout实部为:RealPart虚部为:ImgPartendl;}Complexoperator+(Complex&);friendostream&operator(ostream&,Complex&);private:doubleRealPart,ImgPart;};ComplexComplex::operator+(Complex&n){Complexc;c.RealPart=RealPart+n.RealPart;c.ImgPart=ImgPart+n.ImgPart;returnc;}ostream&operator(ostream&output,Complex&c){outputc.RealPart+c.ImgPartiendl;returnoutput;}voidmain(){ComplexA(2.5,3.5),B(2,5),k;k=A+B;A.show();B.show();coutk;}11、设计一个基类,从基类派生圆柱,设计成员函数输出它们的面积和体积。定义一个座标类Vector2d,二个数据成员为double型x,y为private属性。作为成员函数重载的运算苻”+”的功能是将此类二个对象的数据成员x和y对应相加。#includeiostreamusingnamespacestd;classA{public:A(){cout经计算,圆柱的体积和面积分别为:endl;}};classCylinder:publicA{public:Cylinder(doublei,doublej){r=i;high=j;}voidArea(){cout3.14*r*r+2*3.14*r*high和;}voidV(){cout3.14*r*r*highendl;}private:doubler,high;};classVector2d{public:Vector2d(){a=0;}Vector2d(doublei){a=i;}voidshow(){couta;}Vector2doperator+(Vector2d&);friendostream&operator(ostream&,Vector2d&);private:doublea;};Vector2dVector2d::operator+(Vector2d&n){Vector2dc;c.a=a+n.a;returnc;}ostream&operator(ostream&output,Vector2d&c){outputc.aendl;returnoutput;}voidmain(){Cylinders(1.0,1.0);s.Area();s.V();Vector2dp(10),q(8),c;p.show();q.show();c=p+q;coutendl;cout两个数之和为:cendl;}12、设计一个类Rect,要求如下:(1)该类中的私有数据成员length,width存放它的长和宽,并且设置它们的默认值是0。(2)通过成员函数设置其长和宽,并确保长和