- #include <iostream.h>
- #include <stdlib.h>
- class Control{
- public:
- Control(int c);
- ~Control();
- void SetPostion(int c);
- int GetPostion();
- void SenceUp();
- void SenceDown();
- private:
- int conpos;
- };
- Control::Control(int c)
- {
- SetPostion(c);
- }
- Control::~Control()
- {}
- void Control::SetPostion(int c)
- {
- conpos = c;
- }
- int Control::GetPostion()
- {
- return conpos;
- }
- void Control::SenceUp()
- {
- switch(this->GetPostion())
- {
- case 0:
- this->SetPostion(1); break;
- case 1:
- this->SetPostion(2); break;
- case 2:
- this->SetPostion(3); break;
- default:
- break;
- }
- }
- void Control::SenceDown()
- {
- switch(this->GetPostion())
- {
- case 3:
- this->SetPostion(2); break;
- case 2:
- this->SetPostion(1); break;
- case 1:
- this->SetPostion(0); break;
- default:
- break;
- }
- }
- class Dial{
- public:
- Dial(int d);
- ~Dial();
- void SetPostion(int d);
- int GetPostion();
- void SenceUp();
- void SenceDown();
- private:
- int dialpos;
- };
- Dial::Dial(int d)
- {
- SetPostion(d);
- }
- Dial::~Dial()
- {}
- void Dial::SetPostion(int d)
- {
- dialpos = d;
- }
- int Dial::GetPostion()
- {
- return dialpos;
- }
- void Dial::SenceUp()
- {
- switch(this->GetPostion())
- {
- case 1:
- this->SetPostion(2); break;
- case 2:
- this->SetPostion(3); break;
- default:
- break;
- }
- }
- void Dial::SenceDown()
- {
- switch(this->GetPostion())
- {
- case 3:
- this->SetPostion(2); break;
- case 2:
- this->SetPostion(1); break;
- default:
- break;
- }
- }
- class Brush{
- public:
- Brush(int b);
- ~Brush();
- void SetSpeed(int s);
- int GetSpeed();
- private:
- int speed;
- };
- Brush::Brush(int b)
- {
- SetSpeed(b);
- }
- Brush::~Brush()
- {}
- void Brush::SetSpeed(int s)
- {
- speed = s;
- }
- int Brush::GetSpeed()
- {
- return speed;
- }
- class Agent{
- public:
- Agent();
- ~Agent();
- void ChargeSpeed();
- void Show();
- Control *C;
- Dial *D;
- Brush *B;
- };
- Agent::Agent()
- {
- C = new Control(0);
- D = new Dial(1);
- B = new Brush(0);
- }
- Agent::~Agent()
- {
- delete C;
- delete D;
- delete B;
- }
- void Agent::ChargeSpeed()
- {
- int speed;
- switch(C->GetPostion())
- {
- case 0:
- speed = 0; break;
- case 1:
- switch(D->GetPostion())
- {
- case 1:
- speed = 4; break;
- case 2:
- speed = 6; break;
- case 3:
- speed = 12;break;
- }
- break;
- case 2:
- speed = 30; break;
- case 3:
- speed = 60; break;
- }
- B->SetSpeed(speed);
- Show();
- }
- void Agent::Show()
- {
- cout<<"The Rusult:"<<endl;
- cout<<"The Control's Postion is:"<<C->GetPostion()<<endl;
- cout<<"The Dial's Postion is:"<<D->GetPostion()<<endl;
- cout<<"The Brush's Speed is:"<<B->GetSpeed()<<endl;
- }
- void menu()
- {
- cout<<"================================================"<<endl;
- cout<<"=====1: Control Up-----------2:Control Down====="<<endl;
- cout<<"=====3: Dial Up--------------4:Dial Down========"<<endl;
- cout<<"=====Q:Quit Program!============================"<<endl;
- cout<<"================================================"<<endl;
- };
- void main()
- {
- char c;
- Agent *A;
- A = new Agent;
- menu();
- cout<<"Please input the character of you want to choice:"<<endl;
- cin>>c;
- while(c != 'Q')
- {
- switch(c)
- {
- case '1':
- A->C->SenceUp();
- A->ChargeSpeed();
- break;
- case '2':
- A->C->SenceDown();
- A->ChargeSpeed();
- break;
- case '3':
- A->D->SenceUp();
- A->ChargeSpeed();
- break;
- case '4':
- A->D->SenceDown();
- A->ChargeSpeed();
- break;
- case 'Q':
- exit(0);
- default: break;
- }
- cout<<"Please input the character of you want to choice:"<<endl;
- cin>>c;
- }
- }
第六次作业代码(其他班)
最新推荐文章于 2024-08-12 21:47:59 发布