好文档 - 专业文书写作范文服务资料分享网站

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

天下 分享 时间: 加入收藏 我要投稿 点赞

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++面向对象程序设计课后习题答案(谭浩强版)

classDate;classTime{public:Time(int,int,int);friendvoiddisplay(constDate&,constTime&);private:inthour;intminute;intsec;};Time::Time(in
推荐度:
点击下载文档文档为doc格式
3ac2t6ev9r6b8ve00zsa83uyx967u500v8d
领取福利

微信扫码领取福利

微信扫码分享