OPP作业①

1.随机数

#include<iostream>
#include <ctime>    //产生time的
#include<cstdlib>   //产生俩随机函数的

using namespace std;

int main()
{
    const int N = 5;
    const int M = 24;
    const char strMonth[N][16] = {{"January" }, {"February"}, {"March"}, {"April"}, {"May"}};
    int month;

    srand(time(NULL));    //初始化函数,产生随机数的第一个值
                          //第一个值是time(NULL)的返回值
                          //以现在的系统时间来产生随机数
    for (int i=0; i<M; i++)
    {
        month = (rand() % N) + 1;   //根据初始值。随机产生一个数
        cout << month << "->" << strMonth[month-1] << endl;
    }
    return 0;
}

2.一串数字变成字符串只需要+'0'..

原文地址:https://www.cnblogs.com/syzyaa/p/12722746.html