标题实训项目:学生信息管理系统
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
typedef struct student {
unsigned m_id;
string m_name;
unsigned m_age;
string m_sex;
string m_address;
string m_contact;
string m_dormitory;
struct student *m_next;
}student;
class CStudent {
private :
student *head;
public :
CStudent() {
head = new student;
head->m_id = 0;
head->m_name = "noname";
head->m_next = NULL;
}
~CStudent() {
student *p = head,*q;
while(p) {
q = p;
p = q->m_next;
delete q;
}
}
student readdata(int model); // model = 1:不读取学号,2:不读取姓名,其他,读取所有信息
void entering();
bool insert(const student &astu);
student *findid(unsigned id) const;
student *findname(const string &name) const;
student *findsex(const string &sex) const;
student *finddormitory(const string &dormitory) const;
unsigned boys() const;
unsigned girls() const;
unsigned headcount() const;
bool eraseid();
bool erasename();
bool modifyid();
bool modifyname();
void Show() const;
void query() const;
void friend statistics(const CStudent &aclss);
void friend erase(CStudent &aclss);
void friend modify(CStudent &aclss);
};
string readstring() {
string str;
while(cin.get() != '\n');
cin >> str;
return str;
}
student CStudent::readdata(int model) {
student tmp;
if(model != 1) { cout << "学 号: "; cin >> tmp.m_id; }
if(model != 2) { cout << "姓 名: "; tmp.m_name = readstring(); }
cin >> tmp.m_age;
cout << "性 别: ";
tmp.m_sex = readstring();
cout << "住 址: ";
tmp.m_address = readstring();
cout << "联系方式: ";
tmp.m_contact =readstring();
cout << "寝 室: ";
tmp.m_dormitory = readstring();
return tmp;
}
void CStudent::entering() {
student tmp;
cout << "学号(0 to return): ";
cin >> tmp.m_id;
while(tmp.m_id) {