第六次作业代码(其他班)
2013-01-18 13:22
232 查看
#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;
}
}
#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;
}
}
相关文章推荐
- C++第六次上机实验其他作业
- 第六次c++作业————代码篇
- C++第六次作业(其他班)
- 第六次实验代码(其他班)
- 第四周作业一代码规范
- Java第二次作业參考代码
- 曲线解决CMFCPropertyGridCtrl掩码的bug2009年12月30日 星期三 下午 01:24CMFCPropertyGridCtrl这个控件当用到掩码时,会有问题.解决办法用其他掩码替代.下面是一个IP掩码处理方法.代码如下
- 吉软_Java_第六次作业
- 【Python数据挖掘课程】三.Kmeans聚类代码实现、作业及优化
- 模式识别课程作业 代码说明与源文件
- “System.NotSupportedException”类型的异常在 System.Data.Entity.dll 中发生,但未在用户代码中进行处理 其他信息: 在 LINQ to Entitie
- C++第六次实验—循环(作业1)
- 用.net实现远程获取其他网站页面内容!(核心代码分析)
- JS代码在IE和Firefox间的区别及其他
- 第六次作业--结对编程第二次
- 第六次作业--结对编程第二次
- svn更新代码的时候出现cleanup的问题,网上找到了答案,我是解决了,不知道其他版本适不适用!!!
- C++第六次作业
- C#后台代码 Post 提交表单上传文件及其他信息
- 代码作业——四则运算