作业4
#include<iostream>
#define PI 3.1415926
using namespace std;
class Circle//类名
{
private:
float Radius;
public:
Circle(float r);//构造函数,参数用来初始化私有变量
float GetArea();
};//类的结束
Circle::Circle(float r)
{
Radius=r;
}
float Circle::GetArea()
{
return Radius*Radius*PI;
}
int main()
{
Circle c(5.6);
cout<<"圆的面积:"<<c.GetArea()<<endl;
return 0;
}
作业4
#include<iostream>
using namespace std;
//冒泡排序
void bubble_sort(int a[],int n)
{
int i,j,temp;
for (i=0;i<n;i++)
{
for (j=0;j<n-i-1;j++)
{
if (a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
int main()
{
int i,len;
int array[]={12,8,10,33,55,34,5,30};
len=sizeof(array)/sizeof(array[0]);
bubble_sort(array,len);
for (i=0;i<len;i++)
printf("%d ",array[i]);
return 0;
}