#include<iostream>
#include <string>
using namespace std;
class Student
{
private:
string number;//学号
string name;//名字
string grade;//班级
string sex;//性别
int telephone;//手机号码
int identify;//身份证号码
string major;//专业
string political;//政治面貌
string address;//家庭地址
string nation;//籍贯
public:
Student* next;//next指向下一个学生,构成链表
Student() { next = NULL; }
Student(string n, string g, string num, string s, int tp, int i, string m, string p,string na,string a)
{
name = n;
grade = g;
number = num;
sex = s;
telephone = tp;
identify = i;
major = m;
political = p;
nation = na;
address = a;
next = NULL;
};//构造函数
string getname() { return name; }//名字
string getgrade() { return grade; }//班别
string getnum() { return number; }//学号
string gets() { return sex; }//性别
int gettp() { return telephone; }//
int geti() { return identify; }//
string getm() { return major; }
string getp() { return political; }
string getna() { return nation; }
string geta() { return address; }
void setnum(string num) { number = num; }//修改学号
void setgrade(string g) { grade = g; }//修改班级
void setname(string n) { name = n; }//修改名字
void sets(string s) { sex = s; }//修改性别
void settp(int tp) { telephone = tp; }//修改手机号码
void seti(int i) { identify = i; }//修改身份证
void setm(string m) { major = m; }
void setp(string p) { political = p; }
void setna(string na) {nation = na;}
void seta(string a) { address = a; }
};
class Operation
{
private:
Student* head;
public:
Operation()
{
head = new Student;
}
void Menu();//菜单
void Insert();//插入
void Search();//查找
void Remove();//修改
void Delete();//删除
void Print();//输出
};
void Operation::Menu()
{
cout << "*******************************************************************************************" << endl;
cout << "------------------------- xxx大学学生档案管理系统 -------------------------" << endl;
cout << "------------------------- *********************** -------------------------" << endl;
cout << "------------------------- 1.增加学生信息 -------------------------" << endl;
cout << "------------------------- 2.显示学生信息 -------------------------" << endl;
cout << "------------------------- 3.查找学生信息 -------------------------" << endl;
cout << "------------------------- 4.删除学生信息 -------------------------" << endl;
cout << "------------------------- 5.修改学生信息 -------------------------" << endl;
cout << "------------------------- 6.安全退出系统 -------------------------" << endl;
}
void Operation::Insert() //插入
{
string name;//名字
string grade;//班级
string number;//学号
string sex;//性别
int telephone;//手机号
int identify;//身份证号码
string major;
string political;
string nation;
string address;
Student* p = NULL;
cout << "请输入要添加学生的信息:" << endl;
cout << "请输入姓名:";
cin >> name;
cout << endl;
cout << "请输入班级:";
cin >> grade;
cout << endl;
cout << "请输入学号:";
cin >> number;
cout << endl;
cout << "请输入性别:";
cin >> sex;
cout << endl;
cout << "手机号码:";
cin >> telephone;
cout << endl;
cout << "身份证号码:";
cin >> identify;
cout << endl;
cout << "专业:";
cin >> major;
cout << endl;
cout << "政治面貌:";
cin >> political;
cout << endl;
cout << "籍贯:";
cin >> nation;
cout << endl;
cout << "家庭地址:";
cin >> address;
cout << endl;
Student* s = new Student(name, grade, number, sex, telephone, identify, major, political, nation, address);
p = head;
while (p->next != NULL && p->getnum() < s->getnum())
{
p = p->next;
}
s->next = p->next;
p->next = s;
}
void Operation::Delete()//删除
{
string name;
Student* p = head->next, * q = head;
cout << "请输入要删除学生信息的姓名:" << endl;
cin >> name;
while (p != NULL)
{
if (p->getname() == name)
{
q->next = p->next;
delete p;
break;
}
p = p->next;
q = q->next;
}
if (p != NULL)
{
cout << "删除成功!" << endl;
}
if (p == NULL)
{
cout << "\t\t没有找到!" << endl;
}
}
void Operation::Search()//查询
{
Student* p = NULL;
cout << "\n** 查询学生信息 **\n" << endl;
cout << "请输入查询方式:" << endl;
cout << "1.按学号查询" << endl;
cout << "2.按姓名查询" << endl;
cout << "3.返回" << endl;
char c;
cin >> c;
switch (c)
{
case '1':
{string n;
cout << "请输入你要查询的学生的学号" << endl;
cin >> n;
for (p = head; p != NULL; p = p->next)
{
if (p->getnum() == n)
{
cout
<< "姓名:" << p->getname() << endl
<< "班别:" << p->getgrade() << endl
<< "学号:" << p->getnum() << endl
<< "性别:" << p->getgrade() << endl
<< "电话号码:" << p->gettp() << endl
<< "身份证号码:" << p->geti() << endl
<< "专业:" << p->getm() << endl
<< "政治面貌:" << p->getp() << endl
<< "籍贯:" << p->getna() << endl
<< "家庭地址:" << p->geta() << endl;
}
}
break;
}
case '2':
{
string name;
cout << "请输入你要查询的学生姓名" << endl;
cin >> name;
for (p = head; p != NULL; p = p->next)
{
if (name == p->getname())
{
cout
<< "姓名:" << p->getname() << endl
<< "班级:" << p->getgrade() << endl
<< "学号:" << p->getnum() << endl
<< "性别:" << p->gets() << endl
<< "手机号码:" << p->gettp() << endl
<< "身份证号码:" << p->geti() << endl
<< "专业:" << p->getm() << endl
<< "政治面貌:" << p->getp() << endl
<< "籍贯:" << p->getna() << endl
<< "家庭地址:" << p->geta() << endl;
}
}
break;
}
case '3':
return;
}
}
void Operation::Print() //输出
{
Student* p;
cout
<< "姓名"
<< "\t班级"
<< "\t学号"
<< "\t性别"
<< "\t手机号码"
<< "\t身份证号码"
<< "\t专业"
<< "\t政治面貌"
<< "\t籍贯"
<< "\t地址" << endl;
for (p = head->next; p != NULL; p = p->next)
cout
<< p->getname()
<< "\t" << p->getgrade()
<< "\t" << p->getnum()
<< "\t" << p->gets()
<< "\t" << p->gettp()
<< "\t\t" << p->geti()
<< "\t\t" << p->getm()
<< "\t" << p->getp()
<< "\t\t" << p->getna()
<< "\t" << p->geta()
<< endl;
}
void Operation::Remove() //修改
{
string n;//修改项
string number;//学号
string grade;//班级
string name;//名字
string sex;//性别
int telephone;//手机号码
int identity;//身份证号码
int birth;//出生日期
string major;
string political;
string nation;
string address;
cout << "请输入你要修改的学生姓名" << endl;
cin >> n;
Student* p;
for (p = head->next; p != NULL; p = p->next)
if (p->getname() == n)
{
cout << "请选择您要修改的信息项:" << endl;
cout << "1、学号,2、班别,3、姓名,4、性别,5、手机号码,6、身份证号码,7、出生日期,8、专业,9、政治面貌,10、籍贯,11、家庭地址。" << endl;
int in;
cin >> in;
switch (in)
{
case 1:
cout << p->getnum() << "修改为:" << endl;
cin >> number; p->setnum(number);
break;
case 2:
cout << p->getgrade() << "修改为:" << endl;
cin >> grade; p->setgrade(grade);
break;
case 3:
cout << p->getname() << "修改为:" << endl;
cin >> name; p->setname(name);
break;
case 4:
cout << p->gets() << "修改为:" << endl;
cin >> sex; p->sets(sex);
break;
case 5:
cout << p->gettp() << "修改为:" << endl;
cin >> telephone; p->settp(telephone);
break;
case 6:
cout << p->geti() << "修改为:" << endl;
cin >> identity; p->seti(identity);
break;
case 8:
cout << p->getm() << "修改为:" << endl;
cin >> major; p->setm(major);
break;
case 9:
cout << p->getp() << "修改为:" << endl;
cin >> political; p->setp(political);
break;
case 10:
cout << p->getna() << "修改为:" << endl;
cin >> nation; p->setna(nation);
break;
case 11:
cout << p->geta() << "修改为:" << endl;
cin >> birth; p->seta(address);
break;
default:
cout << "输入错误!" << endl;
break;
}
}
}
int main()
{
Operation O;
O.Menu();
while (1)
{
int n;
cout << "\n\t\t\nt\t请选择:";
cin >> n;
switch (n)
{
case 1://增加
O.Insert();
break;
case 2://显示
O.Print();
break;
case 3://查找
O.Search();
break;
case 4://删除
O.Delete();
break;
case 5://修改
O.Remove();
break;
case 6:
cout << "******************************" << "\n感谢您的使用!\n" << "************************<< endl;
exit(0);
}
}
return 0;
}