学生信息管理系统
一、编程目的
1.1对C++语法、基础知识进行综合运用,编写具有一定综合应用价值的稍大一些的程序, 掌握面向对象程序设计(OOP)的思想,培养学生使用面向对象的程序设计思想分析和解决实际问题的能力;
1.2掌握在Visual C++集成开发环境下编辑、编译、链接和运行一个C++程序的基本方法;
1.3加深对所学知识的理解和掌握;
1.4培养文档报告书面表达和思辨的能力。
二、系统简介
2.1开发环境:Microsoft Visual C++ 6.0;
2.2利用面向对象的方法以及C++的编程思想来完成学生信息管理系统的设计。学生信息包括:学号、姓名、性别、班级、联系电话等等信息。实现了学生信息的增加、修改、查询、删除、浏览等基本功能。学生信息保存在文件中。
2.3主要功能:
1.需求分析:
a. 向管理系统内添加学生信息
b. 从管理系统内根据学号删除学生信息
c. 从管理系统内根据姓名删除学生信息
d. 在管理系统内根据学号查找学生信息
e. 在管理系统内根据姓名查找学生信息
f. 更新管理系统内某位同学的学生信息
g. 浏览所有学生的个人信息。
h. 将对所有学生信息的更改更新到文件中
2.系统性能要求:
a.界面友好(良好的人机交互),提供菜单选项,并给出足够
的选择信息以及提示信息。
b.程序具有一定的健壮性,不会因为用户的输入错误引起程序
运行错误而中断执行。
c.源程序要加适当的注释,使程序容易阅读;
三、编程思路
根据C++课程所学的概念、理论和方法,按照C++程序设计的
基本步骤,设计出一个适当规模的程序来实现设计课程内容中的全部功能;设计主控模块程序.对给出的程序源代码要给出各部分的详细注释.自己根据能力及需要添加相应功能模块,增强模拟系统功能。包括系统的功能分析、系统的功能模块设计、程序流程图或结构框图、逻辑结构设计,数据库中的表、视图(如果使用)、索引的结构和定义、触发器、存储过程、课程设计体会。 通过主窗体调用其他窗体,具体实现可以参照系统分析相关内
容。应用系统主控界面包括增加信息,删除信息,查找信息,修改信息,浏览信息五个功能模块。通过输入每个模块的代号进入子窗体。
四、学生结构信息
1.学生信息
2.结构示意
五、总体设计(模块框架图)
五、关键技术说明
1.文件导入(get_from_file函数)导出(push_to_files函数)
使用文件流技术,将个人信息导出导入到文件中。
2.利用学生信息数组(student)与类的标记成员变量(has),
进行学生信息的删除,避免了使用链表结构的不易维护性,增
加了程序的可读性,同时在删除时将
has的值置为false,避免
了大量的数据移动以及空间需求,大大的提高了程序的效率。
3.通过option
接口,利用循环非递归的窗体执行结构,避
免长时间执行程序,不断递归而造成的栈溢出。
4.程序界面大部分模拟窗体结构,使用户操作界面清晰易
用,增加了界面友好程度。
六、源程序
#include
#include
#include
#include
#include
#define MAX 1000000
using namespace std;
string endofline;
class birthday
{
private:
int _year,_month,_day;
public:
birthday() {}
birthday(int &year,int &month,int &day) : _year(year),_month(month),_day(day) {}
void getbirth()
{
char c;
cout";
cin>>_year>>c>>_month>>c>>_day;
}
void show()
{
cout.fill('0');
cout
cout
}
void get(ifstream &is)
{
is>>_year>>_month>>_day;
}
void put(ofstream &os)
{
os
}
};
class address
{
private:
string _country,_province,_city;
public:
address() {}
address(const char *country,const char *province,const char *city)
:_country(country),_province(province),_city(city) { }
void getadd()
{
cout";
cin>>_country;
cout";
cin>>_province;
cout";
cin>>_city;
}
void get(ifstream &is)
{
is>>_city;
is>>_province;
is>>_country;
}
void show()
{
cout
cout
}
void put(ofstream &os)
{
os
os
os
}
};
class personal
{
private:
string _name,_sex,_telphone,_stuid;
birthday _birth;
public:
personal() {}
personal(const char *stuid,const char *name,const char *sex,birthday birth,const char *telphone)
: _stuid(stuid),_name(name),_sex(sex),_birth(birth),_telphone(telphone) { }
bool findid(string stuid)
{
return stuid==_stuid;
}
bool findname(string name)
{
return name==_name;
}
void getper()
{
cout";
cin>>_name;
cout
cout";
cin>>_stuid;
cout"; cin>>_sex;
_birth.getbirth();
cout";
cin>>_telphone;
}
void get(ifstream &is)
{
is>>_stuid;
is>>_name;
is>>_sex;
_birth.get(is);
is>>_telphone;
}
void show()
{
cout
cout
cout
_birth.show();
}
void put(ofstream &os)
{
os
os
os
_birth.put(os);
os
}
};
class belong // the school and the coollege which a student belongs to
{
private:
string _major,_college,_school;
public:
belong() {}
belong(const char *major,const char *college,const char *school)
: _major(major),_college(college),_school(school) { }
void getblg()
{
cout";
cin>>_school;
cout";
cin>>_college;
cout";
cin>>_major;
}
void show()
{
cout
void put(ofstream &os)
{
os
os
os
}
void get(ifstream &is)
{
is>>_school;
is>>_college;
is>>_major;
}
};
class student
{
private:
address _add;
personal _per;
belong _blg;
public:
bool has;
student() {}
student(address &add,personal &per,belong &blg)
: _add(add),_per(per),_blg(blg) {}
bool findID(string stuid)
{
return (_per.findid(stuid));
}
bool findname(string name)
{
return (_per.findname(name));
}
void getstu()
{
_per.getper();
_add.getadd();
_blg.getblg();
system("cls");
student::show();
cout
system!"
}
void get(ifstream &is)
{
_per.get(is);
_blg.get(is);
_add.get(is);
}
void show()
{
_per.show();
_blg.show();
_add.show();
cout
}
void put(ofstream &os)
{
_per.put(os);
_blg.put(os);
_add.put(os);
}
};
int N(0),del_tot(0);
student stu[MAX];
bool vis[MAX];
void get_from_file()
{
cout
cout
ifstream is;
is.open("student.dat",ios::in);
is>>N;
for(int i=0;i
stu[i].get(is),stu[i].has=true;
is.close();
cout
system("pause");
}
void push_to_file(student &p)
{
ofstream os;
os.open("student.dat",ios::app);
p.put(os);
os.close();
}
void del(int cur)
{
del_tot++,stu[cur].has=false;
cout
}
int main_menu()
{
system("cls");
cout
cout
cout
|******************************************************|"
cout
cout
cout
SIMS_V |"
cout
cout
|******************************************************|"
cout
cout
cout
SIMS_V |"
cout
cout
|******************************************************|"
cout
cout
|******************************************************|"
cout
cout
int option; cin>>option; return option;
}
int add_menu(student &p)
{
int option;
p.has=true;
system("cls");
cout
SIMS_V******************"
p.getstu();
cout
cout
*"
cout
cout
cin>>option;
return option;
}
int del_menu()
{
int option,count1(0),count2(0);
string tem_stuid,tem_command;
system("cls");
cout
SIMS_V****************"
cout"; cin>>tem_stuid;
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) count1++;
cout
for(int i=0;i
{
if(stu[i].has&&stu[i].findID(tem_stuid))
{
system("cls");
cout
SIMS_V****************"
cout
SIMS_V "
cout
stu[i].show();
cout>tem_command;
if(tem_command[0]=='Y') del(i),count1--;
cout
"
cout>tem_command;
if(tem_command[0]=='N') break;
}
}
cout
cout
cout
*"
cout
;
cout
cin>>option;
return option ? 2 : 0;
}
int sch_menu()
{
int option,count(0);
system("cls");
string tem_stuid,tem_command,tem_name;
cout
cout
cout
*"
cout
cout
cin>>option;
if(option==1)
{
cout"; cin>>tem_stuid;
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) count++;
cout
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) stu[i].show();
}
else
{
cout"; cin>>tem_name;
for(int i=0;i
if(stu[i].has&&stu[i].findname(tem_name)) count++;
cout
for(int i=0;i
if(stu[i].has&&stu[i].findname(tem_name)) stu[i].show();
}
system("pause");
option=0;
system("cls");
cout
cout
cout
*"
cout
cout
cin>>option;
return option ? 4 : 0;
}
int mod_menu()
{
int option,count1(0),count2(0);
system("cls");
string tem_stuid,tem_command,tem_name;
cout
cout
cout
*"
cout
cout
cin>>option;
if(option==1)
{
cout"; cin>>tem_stuid;
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) count1++;
for(int i=0;i
{
if(stu[i].has&&stu[i].findID(tem_stuid))
{
system("cls");
cout
SIMS_V****************"
cout
cout
SIMS_V "
stu[i].show();
cout
'N')"
cin>>tem_command;
if(tem_command[0]=='Y')
{
system("cls");
cout
SIMS_V****************"
stu[i].getstu();
}
cout
if(count2
{
cout
cout>tem_command;
if(tem_command[0]=='N') break;
}
}
}
}
else
{
cout"; cin>>tem_name;
for(int i=0;i
if(stu[i].has&&stu[i].findname(tem_name)) count1++;
for(int i=0;i
{
if(stu[i].has&&stu[i].findname(tem_name))
{
system("cls");
cout
SIMS_V****************"
cout
cout
SIMS_V "
stu[i].show();
cout
'N')"
cin>>tem_command;
if(tem_command[0]=='Y')
{
system("cls");
cout
SIMS_V****************"
stu[i].getstu();
}
cout
if(count2
{
cout
cout>tem_command;
if(tem_command[0]=='N') break;
}
}
}
}
system("cls");
cout
cout
cout
*"
cout
cout
cin>>option;
return option ? 4 : 0;
}
int all_menu()
{
system("cls");
cout
if(stu[i].has) stu[i].show();
cout
cout
system("pause");
return 0;
}
void thanks()
{
system("cls");
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
Xinxi,Math-1,Mengchong |"
cout
}
int main()
{
get_from_file();
while(int option=main_menu())
{
while(option)
switch(option)
{
case 1 : option=add_menu(stu[N++]); break; case 2 : option=del_menu(); break;
case 3 : option=mod_menu(); break;
case 4 : option=sch_menu(); break;
default: option=all_menu();
}
}
ofstream os;
os.open("student.dat",ios::out); os
if(stu[i].has) push_to_file(stu[i]);
thanks();
return 0;
}
七、测试结果
2添加信息
1.主界面
输入“1”继续添加信息,输入“0”返回主菜单。
3.删除信息
4.修改信息
5.
查找信息
6.显示所有信息
按任意键返回主菜单
八、总结
缺憾1.对于学生的每一项信息,不能输入空白字符
学生信息管理系统
一、编程目的
1.1对C++语法、基础知识进行综合运用,编写具有一定综合应用价值的稍大一些的程序, 掌握面向对象程序设计(OOP)的思想,培养学生使用面向对象的程序设计思想分析和解决实际问题的能力;
1.2掌握在Visual C++集成开发环境下编辑、编译、链接和运行一个C++程序的基本方法;
1.3加深对所学知识的理解和掌握;
1.4培养文档报告书面表达和思辨的能力。
二、系统简介
2.1开发环境:Microsoft Visual C++ 6.0;
2.2利用面向对象的方法以及C++的编程思想来完成学生信息管理系统的设计。学生信息包括:学号、姓名、性别、班级、联系电话等等信息。实现了学生信息的增加、修改、查询、删除、浏览等基本功能。学生信息保存在文件中。
2.3主要功能:
1.需求分析:
a. 向管理系统内添加学生信息
b. 从管理系统内根据学号删除学生信息
c. 从管理系统内根据姓名删除学生信息
d. 在管理系统内根据学号查找学生信息
e. 在管理系统内根据姓名查找学生信息
f. 更新管理系统内某位同学的学生信息
g. 浏览所有学生的个人信息。
h. 将对所有学生信息的更改更新到文件中
2.系统性能要求:
a.界面友好(良好的人机交互),提供菜单选项,并给出足够
的选择信息以及提示信息。
b.程序具有一定的健壮性,不会因为用户的输入错误引起程序
运行错误而中断执行。
c.源程序要加适当的注释,使程序容易阅读;
三、编程思路
根据C++课程所学的概念、理论和方法,按照C++程序设计的
基本步骤,设计出一个适当规模的程序来实现设计课程内容中的全部功能;设计主控模块程序.对给出的程序源代码要给出各部分的详细注释.自己根据能力及需要添加相应功能模块,增强模拟系统功能。包括系统的功能分析、系统的功能模块设计、程序流程图或结构框图、逻辑结构设计,数据库中的表、视图(如果使用)、索引的结构和定义、触发器、存储过程、课程设计体会。 通过主窗体调用其他窗体,具体实现可以参照系统分析相关内
容。应用系统主控界面包括增加信息,删除信息,查找信息,修改信息,浏览信息五个功能模块。通过输入每个模块的代号进入子窗体。
四、学生结构信息
1.学生信息
2.结构示意
五、总体设计(模块框架图)
五、关键技术说明
1.文件导入(get_from_file函数)导出(push_to_files函数)
使用文件流技术,将个人信息导出导入到文件中。
2.利用学生信息数组(student)与类的标记成员变量(has),
进行学生信息的删除,避免了使用链表结构的不易维护性,增
加了程序的可读性,同时在删除时将
has的值置为false,避免
了大量的数据移动以及空间需求,大大的提高了程序的效率。
3.通过option
接口,利用循环非递归的窗体执行结构,避
免长时间执行程序,不断递归而造成的栈溢出。
4.程序界面大部分模拟窗体结构,使用户操作界面清晰易
用,增加了界面友好程度。
六、源程序
#include
#include
#include
#include
#include
#define MAX 1000000
using namespace std;
string endofline;
class birthday
{
private:
int _year,_month,_day;
public:
birthday() {}
birthday(int &year,int &month,int &day) : _year(year),_month(month),_day(day) {}
void getbirth()
{
char c;
cout";
cin>>_year>>c>>_month>>c>>_day;
}
void show()
{
cout.fill('0');
cout
cout
}
void get(ifstream &is)
{
is>>_year>>_month>>_day;
}
void put(ofstream &os)
{
os
}
};
class address
{
private:
string _country,_province,_city;
public:
address() {}
address(const char *country,const char *province,const char *city)
:_country(country),_province(province),_city(city) { }
void getadd()
{
cout";
cin>>_country;
cout";
cin>>_province;
cout";
cin>>_city;
}
void get(ifstream &is)
{
is>>_city;
is>>_province;
is>>_country;
}
void show()
{
cout
cout
}
void put(ofstream &os)
{
os
os
os
}
};
class personal
{
private:
string _name,_sex,_telphone,_stuid;
birthday _birth;
public:
personal() {}
personal(const char *stuid,const char *name,const char *sex,birthday birth,const char *telphone)
: _stuid(stuid),_name(name),_sex(sex),_birth(birth),_telphone(telphone) { }
bool findid(string stuid)
{
return stuid==_stuid;
}
bool findname(string name)
{
return name==_name;
}
void getper()
{
cout";
cin>>_name;
cout
cout";
cin>>_stuid;
cout"; cin>>_sex;
_birth.getbirth();
cout";
cin>>_telphone;
}
void get(ifstream &is)
{
is>>_stuid;
is>>_name;
is>>_sex;
_birth.get(is);
is>>_telphone;
}
void show()
{
cout
cout
cout
_birth.show();
}
void put(ofstream &os)
{
os
os
os
_birth.put(os);
os
}
};
class belong // the school and the coollege which a student belongs to
{
private:
string _major,_college,_school;
public:
belong() {}
belong(const char *major,const char *college,const char *school)
: _major(major),_college(college),_school(school) { }
void getblg()
{
cout";
cin>>_school;
cout";
cin>>_college;
cout";
cin>>_major;
}
void show()
{
cout
void put(ofstream &os)
{
os
os
os
}
void get(ifstream &is)
{
is>>_school;
is>>_college;
is>>_major;
}
};
class student
{
private:
address _add;
personal _per;
belong _blg;
public:
bool has;
student() {}
student(address &add,personal &per,belong &blg)
: _add(add),_per(per),_blg(blg) {}
bool findID(string stuid)
{
return (_per.findid(stuid));
}
bool findname(string name)
{
return (_per.findname(name));
}
void getstu()
{
_per.getper();
_add.getadd();
_blg.getblg();
system("cls");
student::show();
cout
system!"
}
void get(ifstream &is)
{
_per.get(is);
_blg.get(is);
_add.get(is);
}
void show()
{
_per.show();
_blg.show();
_add.show();
cout
}
void put(ofstream &os)
{
_per.put(os);
_blg.put(os);
_add.put(os);
}
};
int N(0),del_tot(0);
student stu[MAX];
bool vis[MAX];
void get_from_file()
{
cout
cout
ifstream is;
is.open("student.dat",ios::in);
is>>N;
for(int i=0;i
stu[i].get(is),stu[i].has=true;
is.close();
cout
system("pause");
}
void push_to_file(student &p)
{
ofstream os;
os.open("student.dat",ios::app);
p.put(os);
os.close();
}
void del(int cur)
{
del_tot++,stu[cur].has=false;
cout
}
int main_menu()
{
system("cls");
cout
cout
cout
|******************************************************|"
cout
cout
cout
SIMS_V |"
cout
cout
|******************************************************|"
cout
cout
cout
SIMS_V |"
cout
cout
|******************************************************|"
cout
cout
|******************************************************|"
cout
cout
int option; cin>>option; return option;
}
int add_menu(student &p)
{
int option;
p.has=true;
system("cls");
cout
SIMS_V******************"
p.getstu();
cout
cout
*"
cout
cout
cin>>option;
return option;
}
int del_menu()
{
int option,count1(0),count2(0);
string tem_stuid,tem_command;
system("cls");
cout
SIMS_V****************"
cout"; cin>>tem_stuid;
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) count1++;
cout
for(int i=0;i
{
if(stu[i].has&&stu[i].findID(tem_stuid))
{
system("cls");
cout
SIMS_V****************"
cout
SIMS_V "
cout
stu[i].show();
cout>tem_command;
if(tem_command[0]=='Y') del(i),count1--;
cout
"
cout>tem_command;
if(tem_command[0]=='N') break;
}
}
cout
cout
cout
*"
cout
;
cout
cin>>option;
return option ? 2 : 0;
}
int sch_menu()
{
int option,count(0);
system("cls");
string tem_stuid,tem_command,tem_name;
cout
cout
cout
*"
cout
cout
cin>>option;
if(option==1)
{
cout"; cin>>tem_stuid;
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) count++;
cout
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) stu[i].show();
}
else
{
cout"; cin>>tem_name;
for(int i=0;i
if(stu[i].has&&stu[i].findname(tem_name)) count++;
cout
for(int i=0;i
if(stu[i].has&&stu[i].findname(tem_name)) stu[i].show();
}
system("pause");
option=0;
system("cls");
cout
cout
cout
*"
cout
cout
cin>>option;
return option ? 4 : 0;
}
int mod_menu()
{
int option,count1(0),count2(0);
system("cls");
string tem_stuid,tem_command,tem_name;
cout
cout
cout
*"
cout
cout
cin>>option;
if(option==1)
{
cout"; cin>>tem_stuid;
for(int i=0;i
if(stu[i].has&&stu[i].findID(tem_stuid)) count1++;
for(int i=0;i
{
if(stu[i].has&&stu[i].findID(tem_stuid))
{
system("cls");
cout
SIMS_V****************"
cout
cout
SIMS_V "
stu[i].show();
cout
'N')"
cin>>tem_command;
if(tem_command[0]=='Y')
{
system("cls");
cout
SIMS_V****************"
stu[i].getstu();
}
cout
if(count2
{
cout
cout>tem_command;
if(tem_command[0]=='N') break;
}
}
}
}
else
{
cout"; cin>>tem_name;
for(int i=0;i
if(stu[i].has&&stu[i].findname(tem_name)) count1++;
for(int i=0;i
{
if(stu[i].has&&stu[i].findname(tem_name))
{
system("cls");
cout
SIMS_V****************"
cout
cout
SIMS_V "
stu[i].show();
cout
'N')"
cin>>tem_command;
if(tem_command[0]=='Y')
{
system("cls");
cout
SIMS_V****************"
stu[i].getstu();
}
cout
if(count2
{
cout
cout>tem_command;
if(tem_command[0]=='N') break;
}
}
}
}
system("cls");
cout
cout
cout
*"
cout
cout
cin>>option;
return option ? 4 : 0;
}
int all_menu()
{
system("cls");
cout
if(stu[i].has) stu[i].show();
cout
cout
system("pause");
return 0;
}
void thanks()
{
system("cls");
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
Xinxi,Math-1,Mengchong |"
cout
}
int main()
{
get_from_file();
while(int option=main_menu())
{
while(option)
switch(option)
{
case 1 : option=add_menu(stu[N++]); break; case 2 : option=del_menu(); break;
case 3 : option=mod_menu(); break;
case 4 : option=sch_menu(); break;
default: option=all_menu();
}
}
ofstream os;
os.open("student.dat",ios::out); os
if(stu[i].has) push_to_file(stu[i]);
thanks();
return 0;
}
七、测试结果
2添加信息
1.主界面
输入“1”继续添加信息,输入“0”返回主菜单。
3.删除信息
4.修改信息
5.
查找信息
6.显示所有信息
按任意键返回主菜单
八、总结
缺憾1.对于学生的每一项信息,不能输入空白字符