首页 > 其他 > 详细

期中测试题1

时间:2018-05-23 23:10:07      阅读:206      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
class Dice{
    public:
        Dice(int n);
        int cast();
    private:
        int sides;
}; 
Dice::Dice(int n){
    sides=n;
}
int Dice::cast(){
    return rand()%sides+1;
}
int main(){
    int a,b,i=0;
    srand((unsigned)time(NULL));
    Dice d1(40);
    for(a=1;a<=400;a++){
        b=d1.cast();
        if(b==17){
            i++;
        }
    }
    cout<<i<<endl;
}

技术分享图片

期中测试题1

原文:https://www.cnblogs.com/haruna/p/9080054.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!