第六次作业代码(其他班)

  1. #include <iostream.h>  
  2. #include <stdlib.h>  
  3.   
  4. class Control{  
  5. public:  
  6.     Control(int c);  
  7.     ~Control();  
  8.     void SetPostion(int c);  
  9.     int GetPostion();  
  10.     void SenceUp();  
  11.     void SenceDown();  
  12. private:  
  13.     int conpos;  
  14. };  
  15.   
  16. Control::Control(int c)  
  17. {  
  18.     SetPostion(c);  
  19. }  
  20.   
  21. Control::~Control()  
  22. {}  
  23.   
  24. void Control::SetPostion(int c)  
  25. {  
  26.     conpos = c;  
  27. }  
  28.   
  29. int Control::GetPostion()  
  30. {  
  31.     return conpos;  
  32. }  
  33.   
  34. void Control::SenceUp()  
  35. {  
  36.     switch(this->GetPostion())  
  37.     {  
  38.     case 0:  
  39.         this->SetPostion(1); break;  
  40.     case 1:  
  41.         this->SetPostion(2); break;  
  42.     case 2:  
  43.         this->SetPostion(3); break;  
  44.     default:  
  45.         break;  
  46.     }  
  47. }     
  48.   
  49. void Control::SenceDown()  
  50. {  
  51.     switch(this->GetPostion())  
  52.     {  
  53.     case 3:  
  54.         this->SetPostion(2); break;  
  55.     case 2:  
  56.         this->SetPostion(1); break;  
  57.     case 1:  
  58.         this->SetPostion(0); break;  
  59.     default:  
  60.         break;  
  61.     }  
  62. }     
  63.   
  64. class Dial{  
  65. public:  
  66.     Dial(int d);  
  67.     ~Dial();  
  68.     void SetPostion(int d);  
  69.     int GetPostion();  
  70.     void SenceUp();  
  71.     void SenceDown();  
  72. private:  
  73.     int dialpos;  
  74. };  
  75.   
  76. Dial::Dial(int d)  
  77. {  
  78.     SetPostion(d);  
  79. }  
  80.   
  81. Dial::~Dial()  
  82. {}  
  83.   
  84. void Dial::SetPostion(int d)  
  85. {  
  86.     dialpos = d;  
  87. }  
  88.   
  89. int Dial::GetPostion()  
  90. {  
  91.     return dialpos;  
  92. }  
  93.   
  94. void Dial::SenceUp()  
  95. {  
  96.     switch(this->GetPostion())  
  97.     {  
  98.     case 1:   
  99.         this->SetPostion(2); break;  
  100.     case 2:   
  101.         this->SetPostion(3); break;  
  102.     default:   
  103.         break;  
  104.     }  
  105. }  
  106.   
  107. void Dial::SenceDown()  
  108. {  
  109.     switch(this->GetPostion())  
  110.     {  
  111.     case 3:   
  112.         this->SetPostion(2); break;  
  113.     case 2:   
  114.         this->SetPostion(1); break;  
  115.     default:   
  116.         break;  
  117.     }  
  118. }  
  119.   
  120. class Brush{  
  121. public:  
  122.     Brush(int b);  
  123.     ~Brush();  
  124.     void SetSpeed(int s);  
  125.     int GetSpeed();  
  126. private:  
  127.     int speed;  
  128. };  
  129.   
  130. Brush::Brush(int b)  
  131. {  
  132.     SetSpeed(b);  
  133. }  
  134.   
  135. Brush::~Brush()  
  136. {}  
  137.   
  138. void Brush::SetSpeed(int s)  
  139. {  
  140.     speed = s;  
  141. }  
  142.   
  143. int Brush::GetSpeed()  
  144. {  
  145.     return speed;  
  146. }  
  147.   
  148. class Agent{  
  149. public:  
  150.     Agent();  
  151.     ~Agent();  
  152.     void ChargeSpeed();  
  153.     void Show();  
  154.     Control *C;  
  155.     Dial *D;  
  156.     Brush *B;  
  157. };  
  158.   
  159. Agent::Agent()  
  160. {  
  161.     C = new Control(0);  
  162.     D = new Dial(1);  
  163.     B = new Brush(0);  
  164. }  
  165.   
  166. Agent::~Agent()  
  167. {  
  168.     delete C;  
  169.     delete D;  
  170.     delete B;  
  171. }  
  172.   
  173. void Agent::ChargeSpeed()  
  174. {  
  175.     int speed;  
  176.     switch(C->GetPostion())  
  177.     {  
  178.     case 0:   
  179.         speed = 0; break;  
  180.     case 1:  
  181.         switch(D->GetPostion())  
  182.         {  
  183.         case 1:  
  184.             speed = 4; break;  
  185.         case 2:  
  186.             speed = 6; break;  
  187.         case 3:  
  188.             speed = 12;break;  
  189.         }  
  190.         break;  
  191.     case 2:  
  192.         speed = 30; break;  
  193.     case 3:  
  194.         speed = 60; break;  
  195.     }  
  196.     B->SetSpeed(speed);  
  197.     Show();  
  198. }  
  199.   
  200. void Agent::Show()  
  201. {  
  202.     cout<<"The Rusult:"<<endl;  
  203.     cout<<"The Control's Postion is:"<<C->GetPostion()<<endl;  
  204.     cout<<"The Dial's Postion is:"<<D->GetPostion()<<endl;  
  205.     cout<<"The Brush's Speed is:"<<B->GetSpeed()<<endl;  
  206. }  
  207.   
  208. void menu()  
  209. {  
  210.     cout<<"================================================"<<endl;  
  211.     cout<<"=====1: Control Up-----------2:Control Down====="<<endl;  
  212.     cout<<"=====3: Dial Up--------------4:Dial Down========"<<endl;  
  213.     cout<<"=====Q:Quit Program!============================"<<endl;  
  214.     cout<<"================================================"<<endl;  
  215. };  
  216.   
  217.   
  218.   
  219.   
  220. void main()  
  221. {  
  222.     char c;  
  223.     Agent *A;  
  224.     A = new Agent;  
  225.     menu();  
  226.     cout<<"Please input the character of you want to choice:"<<endl;  
  227.     cin>>c;  
  228.     while(c != 'Q')  
  229.     {  
  230.         switch(c)  
  231.         {  
  232.         case '1':  
  233.             A->C->SenceUp();  
  234.             A->ChargeSpeed();  
  235.             break;  
  236.         case '2':  
  237.             A->C->SenceDown();  
  238.             A->ChargeSpeed();  
  239.             break;  
  240.         case '3':  
  241.             A->D->SenceUp();  
  242.             A->ChargeSpeed();  
  243.             break;  
  244.         case '4':  
  245.             A->D->SenceDown();  
  246.             A->ChargeSpeed();  
  247.             break;  
  248.         case 'Q':  
  249.             exit(0);  
  250.         defaultbreak;  
  251.         }  
  252.         cout<<"Please input the character of you want to choice:"<<endl;  
  253.         cin>>c;  
  254.     }  
  255. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值