给出每个月的执勤记录,计算出当月的执勤天数(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;
}