编写一个c语言程序,关于“由圆和高多重继承派生出圆锥类在主函数中能够实现圆锥体积和表面积的计算”

Python017

编写一个c语言程序,关于“由圆和高多重继承派生出圆锥类在主函数中能够实现圆锥体积和表面积的计算”,第1张

#include<iostream>

#include<cmath>

#define N 3.1415

using namespace std

class Height

{

private:

float h

public:

Height(float h):h(h)

{}

float getheight()

{

return h

}

}

class Circle

{

private:

float radius

public:

Circle(float r):radius(r)

{}

float getradius()

float area()

}

float Circle::getradius()

{

return radius

}

float Circle::area()

{

return N*radius*radius

}

class cone:public Height,public Circle

{

private:

float line

public:

cone(float h,float r):Height(h),Circle(r)

{}

void getline()

float surarea()

float volume()

void show()

}

void cone::getline()

{

float a=getradius()

float b=getheight()

line=sqrt(a*a+b*b)

}

float cone::surarea()

{

return area()+N*getradius()*line

}

float cone::volume()

{

return area()*getheight()/3

}

void cone::show()

{

cout<<"圆锥的表面积为:"<<surarea()<<endl

cout<<"圆锥的体积为:"<<volume()<<endl

}

int

main()

{

cone A(4,3)

A.getline()

A.surarea()

A.volume()

A.show()

return 0

}

#include <math.h>

#include <graphics.h> /*预定义库函数*/

void circlePoint(int x,int y)/*八分法画圆程序*/

{

circle(320+x*20,240+y*20,3)

circle(320+y*20,240+x*20,3)

circle(320-y*20,240+x*20,3)

circle(320-x*20,240+y*20,3)

circle(320-x*20,240+y*20,3)

circle(320-x*20,240-y*20,3)

circle(320-y*20,240-x*20,3)

circle(320+y*20,240-x*20,3)

circle(320+x*20,240-y*20,3)

}

void MidBresenhamcircle(int r) /* 中点Bresenham算法画圆的程序 */

{

int x,y,d

x=0y=rd=1-r /* 计算初始值 */

while(x<y)

{ circlePoint(x,y) /* 绘制点(x,y)及其在八分圆中的另外7个对称点 */

if(d<0) d+=2*x+3/* 根据误差项d的判断,决定非最大位移方向上是走还是不走 */

else

{ d+=2*(x-y)+5

y--

}

x++

delay(900000)

} /* while */

}

main()

{

int i,j,r,graphmode,graphdriver

detectgraph(&graphdriver,&graphmode)

initgraph(&graphdriver,&graphmode," ")

printf("中点Bresenhamcircle算法画圆的程序\n")/*提示信息*/

printf("注意 |r|<=11")

printf("\n输入半径值 r:")

scanf("%d",&r)

printf("按任意键显示图形...")

getch()

cleardevice()

setbkcolor(BLACK)

for(i=20i<=620i+=20) /*使用双循环画点函数画出表格中的纵坐标*/

for(j=20j<=460j++)

putpixel(i,j,2)

for(j=20j<=460j+=20) &n欢迎光临学网,收藏本篇文章 [1] [2]

$False$

bsp/*使用双循环画点函数画出表格中的横坐标*/

for(i=20i<=620i++)

putpixel(i,j,2)

outtextxy(320,245,"0")/*原点坐标*/

outtextxy(320-5*20,245,"-5")circle(320-5*20,240,2) /*横坐标值*/

outtextxy(320+5*20,245,"5")circle(320+5*20,240,2)

outtextxy(320-10*20,245,"-10")circle(320-10*20,240,2)

outtextxy(320+10*20,245,"10")circle(320+10*20,240,2)

outtextxy(320-15*20,245,"-15")circle(320-15*20,240,2)

outtextxy(320+15*20,245,"15")circle(320+15*20,240,2)

outtextxy(320,240-5*20,"-5")circle(320,240-5*20,2) /*纵坐标值*/

outtextxy(320,240+5*20,"5")circle(320,240+5*20,2)

outtextxy(320,240-10*20,"-10")circle(320,240-10*20,2)

outtextxy(320,240+10*20,"10")circle(320,240+10*20,2)

outtextxy(20,10,"The center of the circle is (0,0) ") /*坐标轴左上角显示提示信息*/

setcolor(RED)/*标记坐标轴*/

line(20,240,620,240) outtextxy(320+15*20,230,"X")

line(320,20,320,460) outtextxy(330,20,"Y")

setcolor(YELLOW)

MidBresenhamcircle(r)

setcolor(BLUE)/*绘制圆*/

circle(320,240,r*20)

setcolor(2)

getch()

closegraph()

}

#include<stdio.h>

#include<math.h>

int main()

{

double y

int x,m

for(y=10y>=-10y–)

{

m=2.5*sqrt(100-y*y)/*计算行y对应的列坐标m,2.5是屏幕纵横比调节系数因为屏幕的

行距大于列距,不进行调节显示出来的将是椭圆*/

for(x=1x<30-mx++) printf(" ")/*图形左侧空白控制*/

printf("*")/*圆的左侧*/

for(x<30+mx++) printf(" ")/*图形的空心部分控制*/

printf("*\n")/*圆的右侧*/

}

return 0

}