?? qingqing.cpp
字號:
#include"iostream.h"
#include"math.h"
class circle
{private:
float f_mr;
public:
circle()
{f_mr=0;
}
~circle()
{cout<<" now destory the object of circle!"<<endl;
}
float area(float r);
float volume(float r);
};
float circle::area(float r)
{return 3.14*r*r;
}
float circle::volume(float r)
{return 0;
}
class yuanzhu:public circle//定義圓柱類;
{private:
float f_mh1;
//circle cc;
public:
yuanzhu(float r,float h1):circle()//,cc()//構造函數(shù);
{f_mh1=0;
}
~yuanzhu()//構析函數(shù)
{cout<<"now destroying the object of yuanzhu!"<<endl;
}
float area(float r,float h1);
float volume(float r,float h1);
};
float yuanzhu::area(float r,float h1)
{return 2*3.14*r*r+2*3.14*r*h1;
}
float yuanzhu::volume(float r,float h1)
{return 3.14*r*r*h1;
}
class zhui:public circle//定義圓錐類;
{private:
float f_mh2;
public:
zhui()//構造函數(shù);
{f_mh2=0;
}
~zhui()//構析函數(shù)
{cout<<"now destroying the object of zhui!"<<endl;
}
float area(float r,float h2);
float volume(float r,float h2);
};
float zhui::area(float r,float h2)
{return 3.14*r*r+3.14*r*sqrt(r*r+h2*h2);
}
float zhui::volume(float r,float h2)
{return 1.0/3.0*3.14*r*r*h2;
}
void main()
{float r,h1,h2;
cout<<"請輸入圓的半徑、圓柱的高、圓錐的高:"<<endl;
cin>>r>>h1>>h2;
circle *c;
yuanzhu *y;
zhui *z;
cout<<"圓的面積:"<<c->area(r)<<endl;
cout<<"圓的體積:"<<c->volume(r)<<endl;
cout<<"圓柱的表面積:"<<y->area(r,h1)<<endl;
cout<<"圓柱的體積:"<<y->volume(r,h1)<<endl;
cout<<"圓錐的表面積:"<<z->area(r,h2)<<endl;
cout<<"圓錐的體積:"<<z->volume(r,h2)<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -