学生执勤问题

给出每个月的执勤记录,计算出当月的执勤天数(STL)

   学生:刘某某    1月份:111111111111111111110000000000000001   2月份:1010111110101111111111111110101010

 

#include<iostream>
#include<string>
#include<bitset>
#include<vector>
using namespace std;

template<size_t N>
class MyAttend
{
	int month;
	bitset<N>b;
public:
	MyAttend(int mooth,string strAttend):b(strAttend)
	{
		this->month = mooth;
	}
	int GetMooth()
	{
		return month;
	}
	int GetAttendDays()
	{
		return b.count();
	}
};

class Student
{
	string name;
	vector<MyAttend<31>*>v;
public:
	Student(string name)
	{
		this->name = name;
	}
	void Add(MyAttend<31>&m)
	{
		v.push_back(&m);
	}
	void Add(int mooth,string&m)
	{
		MyAttend<31> * ma = new MyAttend<31>(mooth,m);
		v.push_back(ma);
	}

	void showAttendDays()
	{
		cout << "姓名:" << name << endl;
		cout << "月份:\t出勤天数" << endl;
		for (int i=0;i<v.size();i++)
		{
			MyAttend<31>&m = *v.at(i);
			int month = m.GetMooth();
			int days = m.GetAttendDays();
			cout << month << "\t" << days << endl;
		}
	}
};


int main()
{
	Student stu("刘某某");
	string s1 = "111111111111111111110000000000000001";
	string s2 = "1010111110101111111111111110101010";
	MyAttend<31>m1(1, s1);

	stu.Add(m1);
	stu.Add(2,s2);
	stu.showAttendDays();



	cin.get();
	return 0;
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值