第一范文网 - 专业文章范例文档资料分享平台

c++面向对象程序设计课后习题答案(谭浩强版)

来源:用户分享 时间:2025/5/15 8:22:14 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

class Date; class Time {public:

Time(int,int,int);

friend void display(const Date &,const Time &); private: int hour; int minute; int sec; };

Time::Time(int h,int m,int s) {hour=h; minute=m; sec=s; }

class Date {public:

Date(int,int,int);

friend void display(const Date &,const Time &); private: int month; int day; int year; };

Date::Date(int m,int d,int y)

{month=m; day=d; year=y; }

void display(const Date &d,const Time &t) {

cout<<<<\ cout<<<<\ }

int main() {

Time t1(10,13,56); Date d1(12,25,2004); display(d1,t1); return 0; } 11:

#include using namespace std; class Time; class Date {public:

Date(int,int,int); friend Time;

private: int month; int day; int year; };

Date::Date(int m,int d,int y):month(m),day(d),year(y){ }

class Time {public:

Time(int,int,int);

void display(const Date &); private: int hour; int minute; int sec; };

Time::Time(int h,int m,int s):hour(h),minute(m),sec(s){ }

void Time::display(const Date &d) {

cout<<<<\

cout<

int main() {

Time t1(10,13,56); Date d1(12,25,2004); (d1); return 0; } 12:

#include using namespace std; template class Compare {public:

Compare(numtype a,numtype b); numtype max(); numtype min(); private: numtype x,y; };

template

Compare::Compare(numtype a,numtype b) {x=a;y=b;}

template numtype Compare::max() {return (x>y)x:y;} template numtype Compare::min() {return (x

int main()

{Compare cmp1(3,7);

cout<<()<<\ cout<<()<<\ Compare cmp2,;

cout<<()<<\ cout<<()<<\ Compare cmp3('a','A');

cout<<()<<\ cout<<()<<\ return 0; }

第四章

1:

#include using namespace std; class Complex {public:

Complex(){real=0;imag=0;}

Complex(double r,double i){real=r;imag=i;} double get_real(); double get_imag(); void display(); private: double real;

c++面向对象程序设计课后习题答案(谭浩强版).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c3ac2t6ev9r6b8ve00zsa83uyx967u500v8d_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top