百分悬赏 帮我做C++ 程序啊

共三题为了积分分开来问这是第一题一、目的和要求1熟悉继承对代码重用的意义;2掌握继承的方法、继承控制符的含义及对继承的基类成员的访问控制符在派生类中的变化规则;3分析并掌... 共三题 为了积分 分开来问 这是第一题
一 、目的和要求
1 熟悉继承对代码重用的意义;
2 掌握继承的方法、继承控制符的含义及对继承的基类成员的访问控制符在派生类中的变化规则;
3 分析并掌握由继承带来的二义性问题及解决方法;
4 熟悉多态的含义、种类及其成因;
5 掌握不同情况下多态的实现方法;
6 理解抽象类,掌握虚析构函数的必要性;
二、 实验题目
1 使用继承的方法编程实现求规则图形的面积,图形包括:
三角形面积:S=h*w/2
矩形面积: S=h*w
圆形面积: S=3.1415*r*r
梯形面积: S=(t+b)*h/2
正方形面积:S=s*s
运行正确会有加分的
sorry 第一题会了
这是第二题
2 编写一个有关日期(年、月、日)和时间(时、分、秒)的程序。该程序建立三个类,其中一个是日期类Date,一个是时间类Time,另一个是日期和时间类DateTime,它是以前面两个类为基类的派生类。
展开
 我来答
高原狼人
2007-11-11 · TA获得超过924个赞
知道小有建树答主
回答量:671
采纳率:100%
帮助的人:0
展开全部
#include<iostream>
#include<string>
using namespace std;

class Date
{
private:
int year,month, day;
public:
Date(int y,int m,int d): year(y),month(m),day(d){}
void get_date();
void out_date();
};

void Date::get_date ()
{
cout<<" 输入年/月/日 ";
cin>>year>>month>>day;
}
void Date::out_date ()

{
cout<<" 年/月/日 "<<year<<" /"<<month<<" /"<<day;
}

class Time
{
private:
int hour,mintue,second;
public:
Time(int h,int m,int s):hour(h),mintue(m),second(s){}
void get_time();
void out_time();
};

void Time::get_time ()
{
cout<<"输入时 / 分/ 秒 ";
cin>>hour>>mintue>>second;
}

void Time::out_time ()
{
cout<<"时 / 分/ 秒 "<<hour<<" /"<<mintue<<" /"<<second<<endl;
}

class Datetime: public Date, public Time
{
private:
Date date;
Time time;
public:
Datetime();

void get_datetime();
void out_datetime();
};

void Datetime::out_datetime()
{
date.out_date ();
time.out_time ();
}

void Datetime::get_datetime ()
{
date.get_date ();
time.get_time ();
}

void main()
{
Datetime dt;
dt.get_datetime ();
dt.out_datetime ();
}
tenglvjun
2007-10-30 · 超过16用户采纳过TA的回答
知道答主
回答量:75
采纳率:0%
帮助的人:64.7万
展开全部
#include<iostream>
#include<string>
using namespace std;

class Date
{
private:
string year;
string month;
string date;
public:
Date() : year(""), month(""), date("") {}
Date(string& y, string& m, string& d) : year(y), month(m), date(d) {}
Date(Date& d)
{
year = d.year;
month = d.month;
date = d.date;
}
virtual show()
{
cout << "年-月-日" << year << "-" << month << "-" << date <<endl;
}
virtual ~Date {}
};

class Time
{
private:
string hour;
string mintue;
string second;
public:
Time() : hour("0"), mintue("0"), second("0") {}
Time(string& h, string& m, string& s) : year(h), month(m), date(s) {}
Time(Time& d)
{
hour = d.hour;;
mintue = d.mintue;
second = d.second;
}
virtual show()
{
cout << "小时-分-秒" << hour << "-" << mintue << "-" << second << endl;
}
virtual ~Time {}
};

class DateTime : public Date, public Time
{
public:
virtual show()
{
cout << "年-月-日-小时-分-秒" << year << "-" << month << "-" << date
<< "-" << hour << "-" << mintue << "-" << second << endl;
}
virtual ~DateTime() {}
};
基本如此,其他的成员函数你可以考虑增加
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
HiRockCY
2007-10-30 · TA获得超过127个赞
知道小有建树答主
回答量:187
采纳率:0%
帮助的人:285万
展开全部
要求很不明确啊~~~
类的基本定义是这样的:
class Date
{
protected:
int year;
int month;
int day;
};

class Time
{
protected:
int hour;
int minute;
int second;
};

class DateTime : public Date,public Time
{
};
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
home2001me
2007-10-30 · TA获得超过1072个赞
知道小有建树答主
回答量:993
采纳率:0%
帮助的人:1074万
展开全部
120RMB
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
qwa463790130
2007-11-09
知道答主
回答量:51
采纳率:0%
帮助的人:24.2万
展开全部
嘿嘿
我明年才开这门课
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式