第二十四周项目5

(1)阅读教材7.3节,了解枚举类型的一般用法。阅读下面输出He先生买车方案的程序,理解使用枚举类型的意义。

#include <iostream>using namespace std;enum Color {red,black,white};enum Brand {lavida,tiggo,skoda};int main( ){ int color,brand; for(color=red; color<=white; color++)for(brand=lavida; brand<=skoda; brand++)if(!((color==red&&brand==tiggo)||(color==white&&brand==skoda))){switch(color){case red:cout<<"红";break;case black:cout<<"黑";break;case white:cout<<"白";break;}switch(brand){case lavida:cout<<"Lavida"<<endl;break;case tiggo:cout<<"Tiggo"<<endl;break;case skoda:cout<<"Skoda"<<endl;break;}} return 0;}运行结果:

(2)设计函数,,可以按指定的方式,输出一个平面点的对称点。

#include<iostream>using namespace std;enum SymmetricStyle {axisx, axisy, point};//分别表示按x轴, y轴, 原点对称三种方式void output(double,double,SymmetricStyle);int main(){int x,y;cout<<"输入点的坐标:";cin>>x>>y;cout<<"关于x轴的对称点是:";output(x,y,axisx);cout<<"关于y轴的对称点是:";output(x,y,axisy);cout<<"关于坐标原点的对称点是:";output(x,y,point);return 0;}void output(double x,double y, SymmetricStyle s){switch(s){case axisx:cout<<'('<<x<<','<<-y<<')';break;case axisy:cout<<'('<<-x<<','<<y<<')';break;case point:cout<<'('<<-x<<','<<-y<<')';break;}cout<<endl;return;}运行结果:

@ Mayuko

谁说的,人非要快乐不可,好像快乐由得人选择。

第二十四周项目5

相关文章:

你感兴趣的文章:

标签云: