#if !defined(STUDENT_CLASS)
#define STUDENT_CLASS 1.0.1
#include <algorithm>
#include <iostream>
#include <string>
#include <list>
class school_class {
typedef std::list<std::string>::const_iterator student;
public:
bool empty() const throw();
void add_student(const std::string &newbie) throw();
void expel_student(const std::string &bad_boy) throw();
bool find_student(const std::string &some_one) const throw();
void list_students() const throw();
private:
std::list<std::string> student_list;
};
inline
bool school_class::empty() const throw()
{ return student_list.empty(); }
inline
void school_class::add_student(const std::string &newbie) throw()
{ student_list.push_back(newbie); }
inline
void school_class::expel_student(const std::string &bad_boy) throw()
{ student_list.remove(bad_boy); }
inline
bool school_class::find_student(const std::string &some_one) const throw()
{ return std::count(student_list.begin(), student_list.end(), some_one) != 0; }
inline
void school_class::list_students() const throw()
{
for (student some_one = student_list.begin();
some_one != student_list.end();
++some_one)
std::cout<<*some_one<<std::endl;
}
#endif // STUDENT_CLASS 1.0.1
using std::cout;
using std::endl;
using std::cin;
using std::getline;
using std::string;
int main()
{
school_class my_class;
string name;
while (cout<<"enter student : ", getline(cin, name) && !name.empty())
my_class.add_student(name);
while (!my_class.empty()) {
cout<<endl
<<string(5, '-')<<"[students in the class]"<<string(5, '-')<<endl;
my_class.list_students();
cout<<string(8 , '-')<<"[end of the list]"<<string(8, '-')<<endl;
cout<<"enter the name of the student to be kicked out: "<<endl;
getline(cin, name);
if (name.empty()) break;
if (my_class.find_student(name)) {
my_class.expel_student(name);
cout<<name<<" is out."<<endl;
} else
cout<<endl<<"hey man, no such student!"<<endl;
}
cout<<endl<<"bye."<<endl;
return 0;
}