第二章习题汇总

2.
[cpp]  view plain copy
  1. #include <iostream>  
  2. using namespace std;  
  3. class Time  
  4. {  
  5. private:  
  6.     int hour;  
  7.     int minute;  
  8.     int sec;  
  9. public:  
  10.     void set_time()  
  11.     {  
  12.         cin>>hour;  
  13.         cin>>minute;  
  14.         cin>>sec;  
  15.     }  
  16.     void show_time()  
  17.     {  
  18.         cout<<hour<<minute<<sec;  
  19.     }  
  20. };  
  21. int main()   
  22. {  
  23.     Time t1;  
  24.     t1. set_time();  
  25.     t1. show_time();  
  26.     return 0;  
  27. }


3.

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include <iostream>  
  2. using namespace std;  
  3. class Time  
  4. {  
  5. private:  
  6.     int hour;  
  7.     int minute;  
  8.     int sec;  
  9. public:  
  10.     void set_time();  
  11.     void show_time();     
  12. };  
  13.   
  14. void Time::set_time()  
  15.         {  
  16.             cin>>hour;  
  17.             cin>>minute;  
  18.             cin>>sec;  
  19.         }  
  20. void Time::show_time()  
  21. {  
  22.         cout<<hour<<"  "<<minute<<"  "<<sec;  
  23. }  
  24. int main()   
  25. {  
  26.     Time t1;  
  27.     t1. set_time();  
  28.     t1. show_time();  
  29.     return 0;  
  30. }  



4.
#include<iostream>
#include<string>
using namespace std;
class student
{
	private:
	int num;
	string name;
	char sex;
	public:
	void set_value();
	void disaplay();
};
void student::set_value()
{
	cin>>num;
	cin>>name;
	cin>>sex;
}
void student::disaplay()
{
	cout<<"num:"<<num<<endl;
	cout<<"name:"<<name<<endl;
	cout<<"sex:"<<sex<<endl;
}
int main()
{
	student stud;
	stud.set_value();
	stud.disaplay();
	return 0;
}



5.
[cpp]  view plain copy
  1. filel.cpp:  
  2. #include <iostream>  
  3. #include "arraymax.h"  
  4. int main()   
  5. {  
  6.     Array_max arrmax;  
  7.     arrmax.set_vaule();  
  8.     arrmax.max_vaule();  
  9.     arrmax.show_vaule();  
  10.     return 0;  
  11. }  
  12. arrymax.h:  
  13. using namespace std;  
  14. class Array_max  
  15. {  
  16.     public:  
  17.         void set_vaule();  
  18.         void max_vaule();  
  19.         void show_vaule();  
  20.     private:  
  21.         int array[10];  
  22.         int max;  
  23. };  
  24. arraymax.cpp:  
  25. #include<iostream>  
  26. #include"arraymax.h"  
  27. void Array_max::set_vaule()  
  28. {  
  29.     int i;  
  30.     for(i=0;i<10;i++)  
  31.     cin>>array[i];      
  32. }  
  33. void Array_max::max_vaule()  
  34. {  
  35.     int i;  
  36.     max=array[0];  
  37.     for(i=0;i<10;i++)  
  38.     if(array[i]>max) max=array[i];  
  39. }  
  40. void Array_max::show_vaule()  
  41. {  
  42.     cout<<"max="<<max;  




6.
[cpp]  view plain copy
  1. #include <iostream>  
  2. using namespace std;  
  3. class tiji  
  4. {  
  5.     private:  
  6.         float length,width,height;  
  7.     public:  
  8.         void set();  
  9.         void disaplay();  
  10. };  
  11. void tiji::set()  
  12. {  
  13.     cin>>length;  
  14.     cin>>width;  
  15.     cin>>height;  
  16. }  
  17. void tiji::disaplay()  
  18. {  
  19.     float v;  
  20.     v=length*width*height;  
  21.     cout<<v<<endl;  
  22.       
  23. }  
  24. int main()  
  25. {  
  26.     tiji stu;  
  27.     stu.set();  
  28.     stu.disaplay();  
  29.     return 0;  
  30. }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值