还剩1页未读,继续阅读
文本内容:
项目三的基础知识C#
1.编写CH代码,输出九九乘法表#include iostreamint main{for inti=1;i=9;i++{for intj=1;j=i;j++{std::cout«j«/z x〃i〃=〃i*j«〃\t〃;std::coutstd::endl;return0;
2.编写一个程序,输入三角形的三条边长a、b、c,利用海伦定理S=Jpp-a p-bp-c计算三角形的面积其中,p=a+b+c/2ttinclude iostreamttinclude cmathdouble calculateTriangleAreadouble a,double b,doublec{double p=a+b+c/
2.0;double area=std::sqrt p*p-a*p-b*p-c;return area;int main{double a,b,c;std::cout〈〃请输入三角形的三条边长〃;std::cinabc;double area=calculateTriangleAreaa,b,c;std::cout〃三角形的面积为〃areastd::endl;
3.创建一个Circle圆类,其成员属性有圆心坐标x、y,以及半径r在oMain方法中初始化Circle类对象,并计算的周长和面积return0;^include iostreamftinclude cmathclass Circle{private:double x,y;double r;public:Circledouble centerX,double centerY,double radius{x二centerX;y二centerY;r=radius;double getPerimeter{return2*MPI*r;1double getAreaO{return MPI*r*r;;int main{double x,y,r;std::cout〃请输入圆的圆心坐标和半径〃;std::cinxyr;Circle circlex,y,r;double perimeter=circle.getPerimeter;double area=circle.getAreaO;std::cout〃圆的周长为〃perimeterstd::endl;std::cout〃圆的面积为〃areastd::endl;return0;
4.创建一个Shape形状类,从Shape类派生出一个Rectang Ie矩形类,在Main方法中初始化Rectang Ie类对象,并计算矩形的面积ttinclude iostreamclass Shape{protected:double width;double height;public:Shape doublew,double hwidth=w;height=h;virtual double getAreaO{return width*height;class Rectangle:public Shape{public:Rectangle doublew,double h:Shape w,h{}doublegetAreaOoverride{return width*height;int main{double width,height;std::cout«〃请输入矩形的宽度和高度:std::cinwidthheight;Rectangle rectanglewidth,height;double area=rectangle.getAreaO;std::cout〃矩形的面积为〃areastd::endl;return0;。