choujiang.cpp

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include<stdlib.h>
#include <time.h>
#include "Employee.h"
using namespace std;
const int MAX = 30;//员工数
void main(){
Employee employee[MAX];
ifstream emIn("employeeInfo.txt",ios::in);
int size;
if (!emIn) {
cout << "文件不存在" << endl;
//system("pause");
return;
}
//cout << "文件存在" << endl;
for (size = 0;size < MAX;size++) {
emIn >> employee[size].m_name >> employee[size].m_id >> employee[size].m_level;//为对象赋值
//cout << employee[size].m_name << " " << employee[size].m_id << " " << employee[size].m_level << endl;
}
emIn.close();//关闭文件流
//开始抽奖
//先抽3等。从所有对象中抽取5个
int a,b,c,d,e;
srand(time(0));
a = rand() % MAX + 1;
employee[a].m_bool =1;
b = rand() % MAX + 1;
employee[b].m_bool = 1;
c = rand() % MAX + 1;
employee[c].m_bool = 1;
d = rand() % MAX + 1;
employee[d].m_bool = 1;
e = rand() % MAX + 1;
employee[e].m_bool = 1;
cout << "中了三等奖的是:" << employee[a].m_name<<" "<< employee[b].m_name << " " <<employee[c].m_name << " "
<< employee[d].m_name << " " <<employee[e].m_name << endl;
//抽二等奖
int c2[30];//定义一个数组用来取随机值
cout << "中了二等奖的是:";
for (int i = 0; i < 3;i++)
{
c2[i] = rand() % MAX + 1;
while (employee[(c2[i])].m_bool == 1 && employee[(c2[i])].m_level>=3) //如果中奖了那么继续取随机值,级别大于等于3也不行
{
c2[i+1] = rand() % MAX + 1;
i = i + 1;
}
c2[i] = rand() % MAX + 1;
cout << employee[(c2[i])].m_name << " ";
}
cout << endl;
//抽一等奖
cout << "中了一等奖的是:";
int i = 0;
c2[i] = rand() % MAX + 1;
while (employee[(c2[i])].m_bool == 1 && employee[(c2[i])].m_level >= 3)
{
c2[i +1] = rand() % MAX + 1;
i = i + 1;
}
c2[i] = rand() % MAX + 1;
cout << employee[(c2[i])].m_name << " ";
system("pause");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值