c++程序设计谭浩强课后习题答案(完整版)
-CAL-FENGHAI-(2020YEAR-YICAI)_JINGBIAN
第八章
#include
std; class Time
{public: //成员改为公用的
int hour; int
minute; int sec; };
Time t;
void set_time(void) //在 main 函数之前定义 { cin>>t.hour;
cin>>t.minute;
cin>>t.sec;
}
void show_time(void) //在 main 函数之前定义 {
cout< int main() {set_time(); show_time(); return 0; } 8.2 题 #include std; class Time {public: void set_time(void) {cin>>hour; cin>>minute; cin>>sec; } void show_time(void) {cout< private: int hour; int minute; int sec; }; Time t; int main() { t.set_time(); t.show_time(); return 0; } 8.3 题 #include std; class Time {public: void set_time(void); void show_time(void); private: int hour; int minute; int sec; }; void Time::set_time(void) {cin>>hour; cin>>minute; cin>>sec; } void Time::show_time(void) {cout< Time t; int main() { t.set_time(); t.show_time(); return 0; } 8.4 题 //xt8-4.h(student.h) class Student { public: void display( ); void set_value(); private: int num; char name[20]; char sex ; }; 8.4 题 //xt8-4-1.cpp(main.cpp) #include #include "xt8-4.h" int main() {Student stud; stud.set_value(); stud.display(); return 0; } 8.4 题另一解 //xt8-4-2.cpp(即 student.cpp) #include "xt8-4.h" //在此文件中进行函数的定义 #include cout<<"name:"< } void Student::set_value() { cin>>num; cin>>name; cin>>sex; } 8.5 题 //xt8-5.h(arraymax.h) class Array_max {public: void set_value(); void max_value(); void show_value(); private: int array[10]; int max; }; 8.5 题 //xt8-5-1.cpp(file1.cpp) #include "xt8-5.h" int main() {Array_max arrmax; arrmax.set_value(); arrmax.max_value(); arrmax.show_value(); return 0; } 8.5 题 //xt8-5-2.cpp(arraymax.cpp) #include #include "xt8-5.h" void Array_max::set_value() { int i; for (i=0;i<10;i++) cin>>array[i]; } void Array_max::max_value() {int i; max=array[0]; for (i=1;i<10;i++) if(array[i]>max) max=array[i]; } void Array_max::show_value() {cout<<"max="< } 8.6 题 #include namespace std; class Box {public: void get_value(); float volume(); void display(); public: float lengh; float width; float height; }; void Box::get_value() { cout<<"please input lengh, width,height:"; cin>>lengh; cin>>width; cin>>height; } float Box::volume() { return(lengh*width*height);} void Box::display() { cout< int main()