期中测试题1

#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;
}

猜你喜欢

转载自www.cnblogs.com/haruna/p/9080054.html
今日推荐