第二十四周项目5-应用枚举
生活随笔
收集整理的這篇文章主要介紹了
第二十四周项目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
轉載于:https://www.cnblogs.com/mayuko/p/4567542.html
總結
以上是生活随笔為你收集整理的第二十四周项目5-应用枚举的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gradle 2.1构建android出
- 下一篇: HT For Web 拓扑图背景设置