第三周实验报告1

来源:互联网 发布:查网站域名是否被注册 编辑:程序博客网 时间:2024/06/15 18:36

/* (程序头部注释开始)

* 程序的版权和版本声明部分

* Copyright (c) 2011, 烟台大学计算机学院学生

* All rights reserved.

* 文件名称:

 * 作 者:于宸

* 完成日期: 2012年03 月05日

* 版 本 号:V1.0

 * 对任务及求解方法的描述部分

* 输入描述: ...

* 问题描述: ...

* 程序输出: ...

*程序头部的注释结束*/ 

错误程序:

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


改正后的程序:

[cpp] view plaincopy
  1. #include<iostream>  
  2.   
  3. using namespace std;  
  4.   
  5. class Time  
  6. {  
  7. public:                             //共有部分  
  8.     void set_time(void);  
  9.   
  10.     void show_time(void);  
  11. private:                            //私有部分  
  12.     int hour;  
  13.          
  14.     int minute;  
  15.   
  16.     int sec;  
  17. };  
  18.   
  19. Time t;  
  20.   
  21. void Time::set_time(void)                            //函数的返回值类型应该前后一致  
  22. {  
  23.     cin >> t.hour ;  
  24.   
  25.     cin >> t.minute ;  
  26.   
  27.     cin >> t.sec ;  
  28. }  
  29.   
  30. void Time::show_time(void)                            //需要注明域(Time::)  
  31. {  
  32.     cout << t.hour << ":" << t.minute << ":" << t.sec << endl;  
  33. }  
  34.   
  35. int main()  
  36. {  
  37.     t.set_time();                                   //调用时注明对象  
  38.   
  39.     t.show_time();  
  40.   
  41.     return 0;  
  42. }  

原创粉丝点击