其他分享
首页 > 其他分享> > 枚举类型及定义新的类型名字

枚举类型及定义新的类型名字

作者:互联网

5、小作业:
课后自己练习定义枚举类型变量以及使用 typedef 定义新的类型名!

 

#include <iostream>
using namespace std;
enum Week
{
    Day1,
    Day2,
    Day3,
    Day4,
    Day5,
    Day6,
    Day7
};
typedef unsigned int uint;
union test
{
    char mark;
    long num;
    float score;
}student_1;
int main()
{
    Week day = Day2;
    switch (day)
    {
    case Day1:
        cout << "星期1" << endl;
        break;
    case Day2:
        cout << "星期2" << endl;
        break;
    case Day3:
        cout << "星期3" << endl;
        break;
    case Day4:
        cout << "星期4" << endl;
        break;
    case Day5:
        cout << "星期5" << endl;
        break;
    case Day6:
        cout << "星期6" << endl;
        break;
    case Day7:
        cout << "星期天" << endl;
        break;
    default:
        cout << "错误" << endl;
        break;
    }

    uint a = 1;
    cout << a << endl;

    student_1.num = 80;
    test student_2; 
    student_2.score = 10;
    cout << student_1.num << endl;
    cout << student_2.score << endl;
    
    return 0;
}

 

标签:Week,typedef,定义新,int,Day2,Day1,枚举,类型
来源: https://www.cnblogs.com/SakuraQAQ/p/14227092.html