9_76.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
源码类别:

文章/文档

开发平台:

C/C++

  1. #include<iostream.h>
  2. #include<string.h>
  3. #define Max 20
  4. class Destination
  5. {
  6. protected:
  7. char from[Max];
  8. char to[Max];
  9. public:
  10. Destination()
  11. {
  12. strcpy(from,"");strcpy(to,"");
  13. }
  14. Destination(char f[],char t[])
  15. {
  16. strcpy(from,f);strcpy(to,t);
  17. }
  18. void getdata()
  19. {
  20. cout<<"输入发话地点 收话地点:";
  21. cin>>from>>to;
  22. }
  23. void disp()
  24. {
  25. cout<<"计费从"<<from<<"到"<<to;
  26. }
  27. };
  28. class Time
  29. {
  30. protected:
  31. int hour,minute,second;
  32. double time;
  33. public:
  34. Time(){time=0;}
  35. Time(double t){time=t;}
  36. void getdata()
  37. {
  38. cout<<"输入通话时间:时 分 秒";
  39. cin>>hour>>minute>>second;
  40. time=(double)(hour*3600+minute*60+second);
  41. }
  42. void disp()
  43. {
  44. cout<<"通话时间是"<<time<<"秒";
  45. }
  46. };
  47. class Price:public Destination,public Time
  48. {
  49. double price;
  50. public:
  51. Price():Destination(),Time()
  52. {price=0;}
  53. Price(char f[],char t[],double tt):Destination(f,t),Time(tt)
  54. {
  55. price=(int)((tt+5)/6)*0.06;
  56. }
  57. void getdata()
  58. {
  59. Destination::getdata();
  60. Time::getdata();
  61. price=(int)((time+5)/6)*0.06;
  62. }
  63. void disp()
  64. {
  65. cout<<"  ";
  66. Destination::disp();
  67. Time::disp();
  68. cout<<",话费是"<<price<<"元"<<endl;
  69. }
  70. };
  71. void main()
  72. {
  73. Price A;
  74. A.getdata();
  75. Price B("AAA","BBB",123);
  76. cout<<"输出结果:"<<endl;
  77. A.disp();
  78. B.disp();
  79. }