面向对象程序设计课后习题答案谭浩强版
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{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)
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)
return0;
}
int f(int x,int y,int z)
{
int m;
if (x<y) m=x;
else m=y;
if (z<m) m=z;
return(m);
}
8:#include <iostream> using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
float score;
};
int main()
{Student stud(101,;
();
(101,;
();
return0;
}
7:解法一
#include <iostream>
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
if(arr[i].score>max_score) {max_score=arr[i].score;k=i;} cout<<arr[k].num<<" "<<max_score<<endl;
}
6:
#include <iostream>
using namespacHale Waihona Puke Baidu std;
class Student
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 main()
{
int a,b,c;
a=10;
b=23;
c=a+b; cout<<"a+b=";
cout<<c; cout<<endl;
return0;
}
7:
#include <iostream> using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z); cin>>a>>b>>c; c=f(a,b,c); cout<<c<<endl;
Date d1(12,25,2004); display(d1,t1);
return0;
}
11:
#include <iostream> using namespace std; class Time;
class Date
{public:
Date(int,int,int); friend Time;
private:
c=a+b;
cout<<"a+b="<<a+b<<endl; return0;
}
9:
#include <iostream>
using namespace std;
int main()
{int add(int x,int y);
int a,b,c;
cin>>a>>b;
c=add(a,b); cout<<"a+b="<<c<<endl; return0;
}
int add(int x,int y)
{int c;
c=x+y;
return(c);
}
10:
#include <iostream>
using namespace std;
int main()
{void sort(int x,int y,int z); int x,y,z;
cin>>x>>y>>z;
{public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s) {num=n;score=s;}
void display(){cout<<num<<" "<<score<<endl;}
private:
int num;
{month=m;
day=d; year=y;
}
void display(const Date &d,const Time &t)
{
cout<<<<"/"<<<<"/"<<<<endl; cout<<<<":"<<<<":"<<<<endl;
int main()
{
Time t1(10,13,56);
sort(x,y,z);
return0;
}
void sort(int x, int y, int z)
{
int temp;
if (x>y) {temp=x;x=y;y=temp;} 2-4-12-4-22-5-12-5-2Box box1Box box1core; int k=0;
for(int i=1;i<5;i++)
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)
void change(int n,float s) {num=n;score=s;}
void display() {cout<<num<<" "<<score<<endl;}
otal();
Product::display();
return0;
}
10:
#include <iostream>
using namespace std;
第一章
5:
#include <iostream> using namespace std;
int main()
{
cout<<"This"<<"is"; cout<<"a"<<"C++"; cout<<"program."<<endl; return0;
}
6:
#include <iostream> using namespace std;
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)
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)
return0;
}
int f(int x,int y,int z)
{
int m;
if (x<y) m=x;
else m=y;
if (z<m) m=z;
return(m);
}
8:#include <iostream> using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
float score;
};
int main()
{Student stud(101,;
();
(101,;
();
return0;
}
7:解法一
#include <iostream>
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
if(arr[i].score>max_score) {max_score=arr[i].score;k=i;} cout<<arr[k].num<<" "<<max_score<<endl;
}
6:
#include <iostream>
using namespacHale Waihona Puke Baidu std;
class Student
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 main()
{
int a,b,c;
a=10;
b=23;
c=a+b; cout<<"a+b=";
cout<<c; cout<<endl;
return0;
}
7:
#include <iostream> using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z); cin>>a>>b>>c; c=f(a,b,c); cout<<c<<endl;
Date d1(12,25,2004); display(d1,t1);
return0;
}
11:
#include <iostream> using namespace std; class Time;
class Date
{public:
Date(int,int,int); friend Time;
private:
c=a+b;
cout<<"a+b="<<a+b<<endl; return0;
}
9:
#include <iostream>
using namespace std;
int main()
{int add(int x,int y);
int a,b,c;
cin>>a>>b;
c=add(a,b); cout<<"a+b="<<c<<endl; return0;
}
int add(int x,int y)
{int c;
c=x+y;
return(c);
}
10:
#include <iostream>
using namespace std;
int main()
{void sort(int x,int y,int z); int x,y,z;
cin>>x>>y>>z;
{public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s) {num=n;score=s;}
void display(){cout<<num<<" "<<score<<endl;}
private:
int num;
{month=m;
day=d; year=y;
}
void display(const Date &d,const Time &t)
{
cout<<<<"/"<<<<"/"<<<<endl; cout<<<<":"<<<<":"<<<<endl;
int main()
{
Time t1(10,13,56);
sort(x,y,z);
return0;
}
void sort(int x, int y, int z)
{
int temp;
if (x>y) {temp=x;x=y;y=temp;} 2-4-12-4-22-5-12-5-2Box box1Box box1core; int k=0;
for(int i=1;i<5;i++)
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)
void change(int n,float s) {num=n;score=s;}
void display() {cout<<num<<" "<<score<<endl;}
otal();
Product::display();
return0;
}
10:
#include <iostream>
using namespace std;
第一章
5:
#include <iostream> using namespace std;
int main()
{
cout<<"This"<<"is"; cout<<"a"<<"C++"; cout<<"program."<<endl; return0;
}
6:
#include <iostream> using namespace std;