
百分悬赏 帮我做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,它是以前面两个类为基类的派生类。 展开
一 、目的和要求
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,它是以前面两个类为基类的派生类。 展开
5个回答
展开全部
#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 ();
}
#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 ();
}
展开全部
#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() {}
};
基本如此,其他的成员函数你可以考虑增加
#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() {}
};
基本如此,其他的成员函数你可以考虑增加
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要求很不明确啊~~~
类的基本定义是这样的:
class Date
{
protected:
int year;
int month;
int day;
};
class Time
{
protected:
int hour;
int minute;
int second;
};
class DateTime : public Date,public Time
{
};
类的基本定义是这样的:
class Date
{
protected:
int year;
int month;
int day;
};
class Time
{
protected:
int hour;
int minute;
int second;
};
class DateTime : public Date,public Time
{
};
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
120RMB
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询