一. 10个圆面积1
实现代码:
#include<iostream>
using namespace std;
#define PI 3.14
#define N 10
int main()
{
double r,area,circumference;
for(int i=0;i<N;i++)
{
cin>>r;
area=PI*r*r;
circumference=2*PI*r;
cout<<"area="<<area<<" "<<"circumference="<<circumference<<endl;
}
return 0;
}
二. 10个圆面积2
#include<iostream>
using namespace std;
#define PI 3.14
#define N 10
class Circle
{
double radiu;
public:
void setRadius(int);
double area();
double circumference();
};
void Circle::setRadius(int r)
{
radiu=r;
}
double Circle::area()
{
return PI*radiu*radiu;
}
double Circle::circumference()
{
return 2*PI*radiu;
}
int main()
{
Circle c;
double r;
for(int i=0;i<N;i++)
{
cin>>r;
c.setRadius(r);
cout<<i+1<<":"<<"area="<<c.area()<<" "<<"circumference="<<c.circumference()<<endl;
}
return 0;
}
三. 2个学生的班级
#include<iostream>
#include<cstring>
using namespace std;
class Student
{
public:
string name;
int age;
};
int main()
{
Student s1,s2;
cin>>s1.name>>s1.age;
cin>>s2.name>>s2.age;
cout<<s1.name<<" "<<s1.age<<endl;
cout<<s2.name<<" "<<s2.age<<endl;
return 0;
}
四。输出数组的前几项
#include<iostream>
using namespace std;
void display(const int *s,int n)
{
for(int i=0;i<n;i++)
{
cout<<*s++<<endl;
}
}
int main()
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
int m;
cin>>m;
display(a,m);
return 0;
}
五。做个冰立方
#include<iostream>
using namespace std;
inline int cub(int x);
int main()
{
int a;
int b;
cin>>a>>b;
cout<<cub(a)<<endl;
cout<<cub(b)<<endl;
return 0;
}
inline int cub(int x)
{
return x*x*x;
}
六.冰立方多少钱?