(1) Read the 7.3 section of the textbook to learn about the general usage of enumeration types. Read the procedure below to output Mr. He buys a car solution, understanding the meaning of using enumerated types.
#include <iostream>using namespace Std;enum Color {red,black,white};enum Brand {lavida,tiggo,skoda};int main () { C0/>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<< "Red"; break; Case Black: cout<< "Black"; break; Case White: cout<< "Bai"; break; } Switch (brand) {case Lavida: cout<< "Lavida" <<endl; break; Case Tiggo: cout<< "Tiggo" <<endl; break; Case Skoda: cout<< "Skoda" <<endl; break; } } return 0;}
Operation Result:
(2) Design function, you can output a planar point symmetry point in a specified manner.
#include <iostream>using namespace Std;enum symmetricstyle {axisx, Axisy, point};//respectively by x axis, Y axis, origin symmetric three way void Output (double,double,symmetricstyle); int main () { int x, y; cout<< "Input point coordinates:"; cin>>x>>y; cout<< "The symmetry point about the X-axis is:"; Output (X,Y,AXISX); cout<< "The symmetry point about the y-axis is:"; Output (X,y,axisy); cout<< "The symmetry point about the origin of the coordinates is:"; 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;}
Operation Result:
@ Mayuko
24th Week Item 5-Apply Enumeration