第三章作业

3.22

#include<iostream>
#include<math.h>
using namespace std;
class Circle{
	public:
		void area(int x,double y);
		void show();
	private:
		int radius;
		double Area;
};
void Circle::area(int x,double y)
{
	radius=x;
	Area=y;
}
void Circle::show()
{
	cout<<"半径为R的圆的面积为:"<<Area<<endl;
}
int main()
{
	Circle circle1;
	int a;
	double b;
	cout<<"请输入圆的半径R:";
	cin>>a;
	b=3.14*a*a;
	circle1.area(a,b);
	circle1.show();
	return 0;
}

3.23

#include<iostream>
using namespace std;
struct cylinder{
public:
	void set(double x,double y,double z)
	{
		r=x;
		h=y;
		v=z;
	};
	void show();
private:
	double r;
	double h;
	double v;
};
void cylinder::show()
{cout<<"该圆柱体的底面半径为:"<<r<<endl<<"高为:"<<h<<endl<<"体积是:"<<v<<endl;}
int main()
{
	cylinder vo1;
	double a,b,c;
	a=3.0;
	b=4.0;
	c=3.14*a*a*b;
	vo1.set(a,b,c);
	vo1.show();
	return 0;
}

3.24

<p><pre name="code" class="cpp">#include<iostream>
using namespace std;
class Date{
public:
	Date(int a,int b,int c);
	Date();
	void printDate();
	void GetYear();
	void GetMonth();
	void GetDay();
	void SetDate(int Y,int m,int d)
	{
		year=Y;
		month=m;
		day=d;
	}
private:
	int year;
	int month;
	int day;
};
Date::Date(int a,int b,int c):year(a),month(b),day(c)
{}
Date::Date()
{}
void Date::printDate()
{
	cout<<year<<"."<<month<<"."<<day<<endl;
}
void Date::GetYear()
{
	cout<<"输入一个年份:";
	cin>>year;
}
void Date::GetMonth()
{
	cout<<"输入一个月份:";
	cin>>month;
}
void Date::GetDay()
{
	cout<<"输入一个日子:";
	cin>>day;
}
int main()
{
	Date d1(2010,6,8);
	d1.printDate();
	Date d2;
	d2.GetYear();
	d2.GetMonth();
	d2.GetDay();
	d2.printDate();
	Date d3(d1);
	d3.printDate();
	return 0;
}


 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值