小型学生信息管理系统样本.docx
《小型学生信息管理系统样本.docx》由会员分享,可在线阅读,更多相关《小型学生信息管理系统样本.docx(26页珍藏版)》请在冰豆网上搜索。
小型学生信息管理系统样本
综合实验规定
编写一种小型学生信息管理系统,可以对中学生、大学生和研究生信息进行简朴管理。
每一类学生都包具有学生学生名、成绩1、成绩2、成绩3和平均成绩,其中平均成绩=(成绩1+成绩2+成绩3)/3。
每一类学生尚有区别与其她类学生特殊信息,中学生有家长,大学生有专业,研究生有导师。
实现如下功能:
(1)输入学生基本信息;
(2)依照学生名查询某个学生信息;
(3)计算并显示某个学生平均成绩;
一、系统分析
1、基本信息类属性和操作
1)属性
学生类别编号、学生名、成绩1、成绩2、成绩3、平均成绩
(为了以便信息读取,程序中给每类学生设立了一种学生类别编号,以便区别各类学生)
2)操作
数据输入:
输入学生名、成绩1、成绩2和成绩3;
数据输出:
输出学生类别编号、姓名、成绩1、成绩2和成绩3;
计算平均成绩:
平均成绩=(成绩1+成绩2+成绩3)/3。
2、中学生类属性和操作
1)属性
继承基本信息类属性,并增长中学生类区别于其她学生类特殊属性,即家长。
2)操作
数据输入:
继承基本信息类数据输入操作,并增长输入“家长”、信息功能。
数据输出:
继承基本信息类数据输出操作,并增长输出“家长”、信息功能。
3、大学生类属性和操作
1)属性
继承基本信息类属性,并增长大学生类区别于其她学生类特殊属性,即专业。
2)操作
数据输入:
继承基本信息类数据输入操作,并增长输入“专业”、信息功能。
数据输出:
继承基本信息类数据输出操作,并增长输出“专业”、信息功能。
4、研究生属性和操作
1)属性
继承基本信息类属性,并增长研究生类区别于其她学生类特殊属性,即导师。
2)操作
数据输入:
继承基本信息类数据输入操作,并增长输入“导师”、信息功能。
数据输出:
继承基本信息类数据输出操作,并增长输出“导师”、信息功能。
5、系统管理类操作
系统管理类自成一种类:
系统管理类。
重要操作有:
1)输入学生基本信息;
2)依照学生姓名查询某个学生信息;
3)计算并显示某个学生平均成绩。
二、系统设计
1、基类和派生类设计
基类Record(基本信息类):
num(学生类别编号)、name(学生名)、score1(成绩1)、
score2(成绩2)、score3(成绩3)、average(平均成绩)。
Student(中学生类):
从基类继承来属性、patriarch(家长)。
U_student(大学生类):
从基类继承来属性、major(专业)。
Graduate(研究生类):
从基类继承来属性、mentor(导师)。
System(系统管理类):
成员函数In_information负责输入学生信息,成员函数Search查询学生信息,成员函数Out_average计算并显示平均成绩,成员函数Interface负责界面输出。
2、系统管理类设计
(1)将数据文献信息读入内存对象数组
程序一启动,由System构造函数自动调用函数readFile完毕。
(2)信息输入
成员函数In_information依照要输入学生类别分别调用相应学生信息输入功能函数完毕输入。
(3)成员函数Search接受从键盘输入学生类别和学生名,在相应对象
数组中查找,找到后调用对象成员函数Output显示学生信息。
(4)平均成绩计算和显示
接受从键盘输入学生类别和姓名,然后查找对象数组,找到后调用对象计算平均成绩函数计算平均成绩,然后显示。
三、系统实现
头文献:
Record.h、Student.h、U_student.h、Graudate.h、System.h
源文献:
Record.cpp、Student.cpp、U_student.cpp、Graudate.cpp、
System.cpp、main.cpp.
程序运营主界面如图:
实验代码:
头文献某些:
//Record.h
#ifndef_RECORD_H_
#define_RECORD_H_
#include
#include
usingnamespacestd;
classSystem;
classRecord{
public:
Record(){}
Record(stringn,floats1,floats2,floats3,floatavg):
name(n),score1(s1),score2(s2),score3(s3),average(avg){average=0;}
virtualvoidset_inf()=0;
virtualvoiddisplay_inf()=0;
floatcaculate_avg();
friendclassSystem;
protected:
stringname;
floatscore1;
floatscore2;
floatscore3;
floataverage;
};
#endif
//Student.h
#ifndef_STUDENT_H_
#define_STUDENT_H_
#include
#include"Record.h"
usingnamespacestd;
classSystem;
classStudent:
publicRecord{
public:
Student(){}//{//set_inf();}
Student(stringn,floats1,floats2,floats3,floatavg,stringpa):
Record(n,s1,s2,s3,avg),patriarch(pa){}
virtualvoidset_inf();
virtualvoiddisplay_inf();
friendclassSystem;
friendifstream&operator>>(ifstream&i,Student&s);
friendofstream&operator<<(ofstream&i,Student&s);
protected:
stringpatriarch;
};
#endif
//U_student.h
#ifndef_U_STUDENT_H_
#define_U_STUDENT_H_
#include
#include"Record.h"
usingnamespacestd;
classSystem;
classU_student:
publicRecord{
public:
U_student(){}//{//set_inf();}
U_student(stringn,floats1,floats2,floats3,floatavg,stringma):
Record(n,s1,s2,s3,avg),major(ma){}
virtualvoidset_inf();
virtualvoiddisplay_inf();
friendclassSystem;
friendifstream&operator>>(ifstream&i,U_student&s);
friendofstream&operator<<(ofstream&i,U_student&s);
protected:
stringmajor;
};
#endif
//Graduate.h
#ifndef_GRADUATE_H_
#define_GRADUATE_H_
#include
#include"Record.h"
usingnamespacestd;
classSystem;
classGraduate:
publicRecord{
public:
Graduate(){}//{//set_inf();}
Graduate(stringn,floats1,floats2,floats3,floatavg,stringme):
Record(n,s1,s2,s3,avg),mentor(me){}
virtualvoidset_inf();
virtualvoiddisplay_inf();
friendclassSystem;
friendifstream&operator>>(ifstream&i,Graduate&s);
friendofstream&operator<<(ofstream&i,Graduate&s);
protected:
stringmentor;
};
#endif
//System.h
#ifndef_SYSTEM_H_
#define_SYSTEM_H_
classSystem{
public:
System();
voidIn_information();
voidSearch();
voidOut_average();
voidInterface();
voidreadfile();
voiddelete_inf();
voidwritefile();
};
#endif
//源文献某些
//Record.cpp
#include"Record.h"
#include
usingnamespacestd;
floatRecord:
:
caculate_avg(){
returnaverage=(score1+score2+score3)/3;
}
//Student.cpp
#include"Student.h"
#include
#include
usingnamespacestd;
voidStudent:
:
set_inf(){
cout<<"姓名:
"<cin>>name;
cout<<"成绩一:
"<cin>>score1;
cout<<"成绩二:
"<cin>>score2;
cout<<"成绩三:
"<cin>>score3;
cout<<"家长:
"<cin>>patriarch;
this->caculate_avg();
}
voidStudent:
:
display_inf(){
cout<<"姓名:
"<cout<<"成绩一:
"<cout<<"成绩二:
"<cout<<"成绩三:
"<cout<<"家长:
"<}
ifstream&operator>>(ifstream&infile,Student&s)
{
infile>>s.name>>s.score1>>s.score2>>s.score3>>s.average>>s.patriarch;
returninfile;
}
ofstream&operator<<(ofstream&outfile,Student&s)
{
outfile<<returnoutfile;
}
//U_student.cpp
#include"U_student.h"
#include
#include
usingnamespacestd;
voidU_student:
:
set_inf(){
cout<<"姓名:
"<cin>>name;
cout<<"成绩一:
"<cin>>score1;
cout<<"成绩二:
"<cin>>score2;
cout<<"成绩三:
"<cin>>score3;
cout<<"专业:
"<cin>>major;
this->caculate_avg();
}
voidU_student:
:
display_inf(){
cout<<"姓名:
"<cout<<"成绩一:
"<cout<<"成绩二:
"<cout<<"成绩三:
"<cout<<"专业:
"<}
ifstream&operator>>(ifstream&infile,U_student&s)
{
infile>>s.name>>s.score1>>s.score2>>s.score3>>s.average>>s.major;
returninfile;
}
ofstream&operator<<(ofstream&outfile,U_student&s)
{
outfile<<returnoutfile;
}
//Graduate.cpp
#include"Graduate.h"
#include
#include
usingnamespacestd;
voidGraduate:
:
set_inf(){
cout<<"姓名:
"<cin>>name;
cout<<"成绩一:
"<cin>>score1;
cout<<"成绩二:
"<cin>>score2;
cout<<"成绩三:
"<cin>>score3;
cout<<"导师:
"<cin>>mentor;
this->caculate_avg();
}
voidGraduate:
:
display_inf(){
cout<<"姓名:
"<cout<<"成绩一:
"<cout<<"成绩二:
"<cout<<"成绩三:
"<cout<<"导师:
"<}
ifstream&operator>>(ifstream&infile,Graduate&s)
{
infile>>s.name>>s.score1>>s.score2>>s.score3>>s.average>>s.mentor;
returninfile;
}
ofstream&operator<<(ofstream&outfile,Graduate&s)
{
outfile<<returnoutfile;
}
//System.cpp
#include"System.h"
#include"Record.h"
#include"Student.h"
#include"U_student.h"
#include"Graduate.h"
#include
#include
#include
#include
#include"shlwapi.h"
#pragmacomment(lib,"shlwapi.lib")
#include
usingnamespacestd;
vectorstu_m;
vectorstu_u;
vectorstu_g;
System:
:
System(){
system("title小型学生信息管理");
system("color0b");
this->readfile();
this->Interface();
}
voidSystem:
:
readfile(){
/*HANDLEhFILE1=CreateFileA("中学生信息.txt",FILE_ATTRIBUTE_READONLY,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);*/
//*****
Studenttemp_stu_m;
if(!
PathFileExistsA("中学生信息.txt")){CreateFileA(".//中学生信息.txt",NULL,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);}
ifstreamiofile1("中学生信息.txt",ios:
:
in|ios:
:
out);
while(!
iofile1.eof())
{
iofile1>>temp_stu_m;
stu_m.push_back(temp_stu_m);
}
stu_m.pop_back();
iofile1.close();
//*****
U_studenttemp_stu_u;
/*HANDLEhFILE2=CreateFileA("大学生信息.txt",FILE_ATTRIBUTE_READONLY,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);*/
if(!
PathFileExistsA("大学生信息.txt")){CreateFileA(".//大学生信息.txt",NULL,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);}
ifstreamiofile2("大学生信息.txt",ios:
:
in|ios:
:
out);
while(!
iofile2.eof())
{
iofile2>>temp_stu_u;
stu_u.push_back(temp_stu_u);
}
stu_u.pop_back();
iofile2.close();
//******
Graduatetemp_stu_g;
/*HANDLEhFILE3=CreateFileA("研究生信息.txt",FILE_ATTRIBUTE_READONLY,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);*/
if(!
PathFileExistsA("研究生信息.txt")){CreateFileA(".//研究生信息.txt",NULL,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);}
ifstreamiofile3("研究生信息.txt",ios:
:
in|ios:
:
out);
while(!
iofile3.eof())
{
iofile3>>temp_stu_g;
stu_g.push_back(temp_stu_g);
}
stu_g.pop_back();
iofile3.close();
}
voidSystem:
:
writefile(){
//*****
ofstreamiofile4("中学生信息.txt",ios:
:
in|ios:
:
out|ios:
:
trunc);
if(!
iofile4){
cerr<<"openerror!
"<system("pause");
exit(0);
}
for(vector:
:
iteratorit=stu_m.begin();it!
=stu_m.end();it++)
{
iofile4<<*it;
}
iofile4.close();
//*****
ofstreamiofile5("大学生信息.txt",ios:
:
in|ios:
:
out|ios:
:
trunc);
if(!
iofile5){
cerr<<"openerror!
"<system("pause");
exit(0);
}
for(vector:
:
iteratorit=stu_u.begin();it!
=stu_u.end();it++)
{
iofile5<<*it;
}
iofile5.close();
//******
ofstreamiofile6("研究生信息.txt",ios:
:
in|ios:
:
out|ios:
:
trunc);
if(!
iofile6){
cerr<<"openerror!
"<system("pause");
exit(0);
}
for(vector:
:
iteratorit=stu_g.begin();it!
=stu_g.end();it++)
{
iofile6<<*it;
}
iofile6.close();
}
voidSystem:
:
In_information(){
intn;
cout<<"输入要创立学生类别:
"<cout<<"1.中学生"<<"2.大学生"<<"3.研究生"<cin>>n;
if(n==1){
Student*p_s=newStudent;
p_s->set_inf();
stu_m.push_back(*(p_s));
}
elseif(n==2){
U_student*p_s=newU_student;
p_s->set_inf();
stu_u.push_back(*(p_s