24th Week Item 5-Apply Enumeration

Source: Internet
Author: User

(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.