资源描述
上 海 电 力 学 院
课程设计报告
面向对象程序设计
(/第一学期)
课题名称 课程设计选题管理系统设计
院 (系) 电子与信息工程学院
专 业 通信工程
学 号 2234
姓 名 储昊
时 间 1月19日至1月23日
地 点 虚拟仿真实验室(南4教312)
指引教师 骆政屹
目 录
一、设计目与任务……………………………………………………………………….2
1、本课程设计目……………………………………………………………………….2
2、本课程设计任务……………………………………………………………………….2
二、设计方案…………………………………………………………………………………..3
1、总体设计……………………………………………………………………………………….3
2、系统设计……………………………………………………………………………………….3
3、系统实现……………………………………………………………………………………….5
4、系统测试………………………………………………………………………………………16
三.心得体会…………………………………………………………………………………….20
一、设计目与任务
1、本课程设计目
1)课程设计是实践教学环节。设立课程设计目是加强学生对本课程及有关课程知识理解,培养学生综合运用理论知识分析和解决实际问题办法与能力。有助于提高学生创新能力和创新意识。搞好课程设计教学工作,对实现专业培养目的,提高学生全面素质有重要作用。
2)通过课程设计更进一步理解 C++基本知识。
3)训练用系统观点及软件开发普通规范进行软件开发,并在此过程中培养严谨科学态度和良好工作作风。初步掌握软件开发过程中问题分析、系统设计、程序编码、调试、测试等方面基本办法和技能。
4) 纯熟掌握 C++知识在程序中应用,理解课本知识在解决实际问题中用途。
2、本课程设计任务
(1)问题描述
课程设计题目涉及:编号、名称、核心词、实现技术、人员数(由几种人来完毕)等信息。
学生信息涉及:学号、姓名、性别、年龄、班级、专业等信息。
(2)功能规定
① 添加功能:程序可以添加学生记录和课程设计题目记录,提供选取界面供顾客选取所要添加类别。添加记录时,规定学号和编号要唯一。如果添加了重复记录,则提示数据添加重复并取消添加。
② 查询功能:可依照学号、姓名、编号、名称等信息对已添加学生和课程设计题目进行查询,如果未找到,给出相应提示信息,如果找到,则显示相应记录信息。
③ 显示功能:可显示当前系统中所有学生信息和课程设计题目信息,每条记录占据一行。
④ 编辑功能:可依照查询成果对相应记录进行修改,修改时注意学号唯一性。
⑤ 删除功能:重要实现对已添加学生和课程设计题目记录进行删除。如果当前系统中没有相应记录,则提示“记录为空!”并返回操作。
⑥ 记录功能:能依照各种参数进行记录。能按课程设计题目名称记录出学生选取该题目人员信息。
⑦ 保存功能:可将当前系统中各类记录存入文献中,存入方式任意。
⑧ 读取功能:可将保存在文献中信息读入到当前系统中,供顾客进行使用。
二、 设计方案
1、总体设计
咱们设计一种程序对学生课程设计选题信息进行保存,对学生选题信息进行可执行各种操作,该程序涉及如下功能模块:1)学生信息添加模块:可以输入学生基本信息并保存到文献中。2)查询模块:显示所有符合规定课程设计信息。3)编辑模块:可对学生信息进行修改。4)删除模块:可删除相应学生信息。5)记录模块:能依照各种参数进行记录。6)查看模块:显示所有课程设计选题信息。7)退出系统。为了完善系统,咱们还添加了一种登录界面。
2、系统设计
1)类设计
定义一种学生类Student,类中涉及学号stuid,姓名stuname,性别sex,年龄age,班级clas,专业specialty,及所选课程课程编号couid,课程名称 couname,核心词keyword,实现技术technology;
定义一种管理类Guanli,其成员函数涉及向文献输入函数void write(int n);从文献读取函数,int read();添加学生信息函数void add(),查询信息函数void search (),按学号查询函数void searchsid(),按姓名查询函数void searchsname(),按题目编号查询函数void searchcid(),按题目名称查询函数void searchcname();修改信息函数void alter() ;删除信息函数void del();记录信息函数void total();显示函数void display()以及一种数据成员Student stu[50]。
2)函数设计
void write(int n),向文献中写入数据,打开文本文档,并将数据输入到文本文档中;int read(),向文献中写入数据从文献中读数据,打开文本文档,并将文本文档中数据输出;void add(),添加学生信息;void search()查询信息(可依照学生学号、姓名、所选课程编号、课程名称进行信息查询);void alter(),修改学生信息;void del(),删除学生信息,依照输入学生学号通过调用函数实现;void total(),记录学生信息(依照学生所选课程名称进行记录);void display(),显示函数用来显示所有学生信息;int main()主函数,显示主菜单,调用各个函数实现所有功能。
3)系统流程图
课程设计学生选课系统设计构造图:进入功能界面后,可以进行多项功能选取,如添加、查询、显示、修改、删除、记录,将数据写入文献以及从文献读取数据等;而查询功能又可以分为按学号、姓名、题目编号、题目名称等方式进行查询。如下图所示。
主菜单
退出系统
显示所有记录
记录所有记录
删除学生信息
修改学生信息
查询记录信息
添加新记录
按学号查询
按姓名查询
按编号查询
按名称查询
4)界面设计
主界面是“欢迎使用课程设计选课系统”,下面是所要使用功能:
1. 添加新纪录
2. 查询记录信息
3. 修改学生信息
4. 删除学生信息
5. 记录所有记录
6. 显示所有记录
0. 退出系统
其中,查询记录又可以弹出一种界面分别有如下几种功能:
1. 依照学号查询
2. 依照姓名查询
3. 依照编号查询
4. 依照题目名称查询
每实现一种功能,重新弹出主界面,进行下一种功能选取。
3、系统实现
1)类实现
class Student
{
public:
int stuid; //学号
char stuname[10]; //姓名
char sex[2]; //性别
int age; //年龄
char clas[10]; //班级
char specialty[10]; //专业
int couid; //题目编号
char couname[10]; //题目名称
char keyword[20]; //核心词
char technology[30]; //实现技术
}stu[50]; //定义对象
class Guanli
{
private:
Student stu[50];
public:
void add(); //添加学生信息
void search(); //查询信息
void searchsid(); //按学号查询信息
void searchsname(); //按名字查询信息
void searchcid(); //按题目编号查询信息
void searchcname(); //按题目名称查询信息
void alter(); //修改信息
void del(); //删除信息
void total(); //记录信息
void display(); //显示信息
void write(int n); //向文献中写入数据
int read(); //从文献中读数据
};
2)函数实现
void Guanli::write(int n)
{
fstream myfile;
myfile.open("student.txt",ios::out|ios::binary);
if(!myfile)
{
cout<<"该文献不能打开!"<<endl;
abort();
}
int count=n;
myfile<<count<<endl<<endl;
for(int i=0;i<=count;i++)
{
myfile<<stu[i].stuid<<" "<<stu[i].stuname<<" "<<stu[i].sex<<" "<<stu[i].age<<" "<<stu[i].clas<<" "<<stu[i].specialty<<" "<<stu[i].couid<<" "<<stu[i].couname<<" "<<stu[i].keyword<<" "<<stu[i].technology<<" "<<endl;
}
myfile.close();
}
int Guanli::read()
{
fstream myfile;
myfile.open("student.txt",ios::in|ios::binary);
if(!myfile)
{
cout<<"该文献不能打开!"<<endl;
abort();
}
int count;
myfile.seekg(0);
myfile>>count;
for(int i=0;i<=count;i++)
{
myfile>>stu[i].stuid>>stu[i].stuname>>stu[i].sex>>stu[i].age>>stu[i].clas>>stu[i].specialty>>stu[i].couid>>stu[i].couname>>stu[i].keyword>>stu[i].technology;
cout<<endl;
}
myfile.close();
return count;
}
void Guanli::add()
{
int n=read();
int i=0;
char sign;
cout<<endl<<"请输入增长学生有关信息:"<<endl;
while(sign!='N')
{
loop:
cout<<"学号:";
cin>>stu[i].stuid;
cout << endl;
int c=0;
while(c<i)
{
c++;
if(stu[i].stuid==stu[i-c].stuid)
{
cout<<"你输入学号已经存在!请重新输入"<<endl;
goto loop;
}
}
cout<<"姓名:";
cin>>stu[i].stuname;
cout<<endl;
cout<<"性别:";
cin>>stu[i].sex;
cout<<endl;
cout<<"年龄:";
cin>>stu[i].age;
cout<<endl;
cout<<"班级:";
cin>>stu[i].clas;
cout<<endl;
cout<<"专业:";
cin>>stu[i].specialty;
cout<<endl;
cout<<"题目编号:";
cin>>stu[i].couid;
cout<<endl;
cout<<"题目名称:";
cin>>stu[i].couname;
cout<<endl;
cout<<"核心词:";
cin>>stu[i].keyword;
cout<<endl;
cout<<"实现技术:";
cin>>stu[i].technology;
cout<<endl;
cout<<"提示:与否继续写入学生信息?(Y/N)";
cin>>sign;//输入判断
i++;
}
write(i);
}
void Guanli::search()
{
int n=read();
cout<<"** (1)依照学号查询 **"<<endl;
cout<<"** (2)依照姓名查询 **"<<endl;
cout<<"** (3)依照编号查询 **"<<endl;
cout<<"** (4)依照名称查询 **"<<endl;
cout<<endl;
int c;
Guanli g;
cout<<"请输入选取:";
cin>>c;
switch(c)
{
case 1:
g.searchsid();
break;
case 2:
g.searchsname();
break;
case 3:
g.searchcid();
break;
case 4:
g.searchcname();
break;
default:
cout<<"输入错误,请重新输入!"<<endl;
}
g.write(n);
}
void Guanli::searchsid()
{
int n=read();
int s;
int i=0;
cout<<endl<<"查找学生信息:"<<endl;
cout<<"请输入需要查找学生学号:"<<endl;
cin>>s;
while((stu[i].stuid-s)!=0&&i<n) i++;//查找判断
if(i==n)
{
cout<<"提示:对不起,无法找到该学生信息!"<<endl;
}
else
{
cout<<"******************************"<<endl;
cout<<"学号:"<<stu[i].stuid<<endl;
cout<<"姓名:"<<stu[i]. stuname<<endl;
cout<<"性别:"<<stu[i].sex<<endl ;
cout<<"年龄:"<<stu[i]. age<<endl;
cout<<"班级:"<<stu[i].clas<< endl;
cout<<"专业:"<<stu[i]. specialty<<endl;
cout<<"题目编号:"<<stu[i].couid<<endl;
cout<<"题目名称:"<<stu[i].couname<<endl;
cout<<"核心词:"<<stu[i].keyword<<endl;
cout<<"实现技术:"<<stu[i].technology<<endl;
}
}
void Guanli::searchsname()
{
int n=read();
char a[10];
cout<<"请输入需要查找学生姓名:"<<endl;
cin>>a;
for(int i=0;i<n;i++)
if(strcmp(stu[i].stuname,a)==0)
{
cout<<"******************************"<<endl;
cout<<"学号:"<<stu[i].stuid<<endl;
cout<<"姓名:"<<stu[i]. stuname<<endl;
cout<<"性别:"<<stu[i].sex<<endl ;
cout<<"年龄:"<<stu[i]. age<<endl ;
cout<<"班级:"<<stu[i].clas<<endl;
cout<<"专业:"<<stu[i]. specialty<<endl;
cout<<"题目编号:"<<stu[i].couid<<endl;
cout<<"题目名称:"<<stu[i].couname<<endl;
cout<<"核心词:"<<stu[i].keyword<<endl;
cout<<"实现技术:"<<stu[i].technology<<endl;
}
}
void Guanli::searchcid()
{
int n=read();
int b;
int i=0;
cout<<"请输入需要查找题目编号:"<<endl;
cin>>b;
while((stu[i].couid-b)!=0&&i<n) i++;//查找判断
if(i==n)
{
cout<<"提示:对不起,无法找到该信息!"<<endl;
}
else
{
cout<<"******************************"<<endl;
cout<<"学号:"<<stu[i].stuid<<endl;
cout<<"姓名:"<<stu[i]. stuname<<endl;
cout<<"性别:"<<stu[i].sex<<endl ;
cout<<"年龄:"<<stu[i]. age<<endl ;
cout<<"班级:"<<stu[i].clas<< endl;
cout<<"专业:"<<stu[i]. specialty<<endl;
cout<<"题目编号:"<<stu[i].couid<<endl;
cout<<"题目名称:"<<stu[i].couname<<endl;
cout<<"核心词:"<<stu[i].keyword<<endl;
cout<<"实现技术:"<<stu[i].technology<<endl;
}
}
void Guanli::searchcname()
{
int n=read();
char c[10];
cout<<"请输入需要查找题目名称:"<<endl;
cin>>c;
for(int i=0;i<n;i++)
if(strcmp(stu[i].couname,c)==0)
{
cout<<"******************************"<<endl;
cout<<"学号:"<<stu[i].stuid<<endl;
cout<<"姓名:"<<stu[i]. stuname<<endl;
cout<<"性别:"<<stu[i].sex<<endl ;
cout<<"年龄:"<<stu[i]. age<<endl ;
cout<<"班级:"<<stu[i].clas<< endl;
cout<<"专业:"<<stu[i]. specialty<<endl;
cout<<"题目编号:"<<stu[i].couid<<endl;
cout<<"题目名称:"<<stu[i].couname<<endl;
cout<<"核心词:"<<stu[i].keyword<<endl;
cout<<"实现技术:"<<stu[i].technology<<endl;
}
}
void Guanli::alter()
{
int n=read();
int s;
int i=0;
cout<<endl<<"修改学生信息:"<<endl;
cout<<"请输入需要修改学生学号:"<<endl;
cin>>s;
while((stu[i].stuid-s)!=0&&i<n) i++;//查找判断
if(i==n)
{
cout<<"提示:对不起,无该学生信息!!!"<<endl;//输入失败信息
}
else
{
cout<<"该学生信息:"<<endl;
cout<<"学号"<<stu[i].stuid<<'\n'<<"姓名"<<stu[i].stuname<<'\n'<<"性别"<<stu[i].sex<<'\n'<<"年龄"<<stu[i].age<<'\n'<<"班级"<<
stu[i].clas<<'\n'<<"专业"<<stu[i].specialty<<'\n'<<"题目编号"<<stu[i].couid<<'\n'<<"题目名称"<<stu[i].couname<<'\n'
<<"核心词"<<stu[i].keyword<<'\n'<<"实现技术"<<stu[i].technology<<'\n'<<endl;
cout<<"请重新输入该学生信息"<<endl;
cout<<"学号:";
cin>>stu[i]. stuid ;
cout<<endl;
cout<<"姓名:";
cin>>stu[i]. stuname;
cout<<endl;
cout<<"性别:";
cin>>stu[i].sex;
cout<<endl;
cout<<"年龄:";
cin>>stu[i].age;
cout<<endl;
cout<<"班级:";
cin>>stu[i].clas ;
cout<<endl;
cout<<"专业:";
cin>>stu[i]. specialty;
cout<<endl;
cout<<"题目编号:";
cin>>stu[i].couid;
cout<<endl;
cout<<"题目名称:";
cin>>stu[i].couname;
cout<<endl;
cout<<"核心词:";
cin>>stu[i].keyword;
cout<<endl;
cout<<"实现技术:";
cin>>stu[i].technology;
cout<<endl;
char c;
cout<<"与否保存数据?(y/n)"<<endl;
cin>>c;
if(c='y')
cout<<"修改成功!"<<endl;
write(n);
}
}
void Guanli::del()
{
int n=read();
int s;
int i=0,j;
cout<<endl<<"删除学生信息:"<<endl;
cout<<"请输入需要删除学生学号:"<<endl;
cin>>s;
while((stu[i].stuid-s)!=0&&i<n) i++;//查找判断
if(i==n)
{
cout<<"提示:记录为空!!!"<<endl;//返回失败信息
}
else
{
for(j=i;j<n-1;j++) //删除操作
{
stu[j].stuid=stu[j+1].stuid;
strcpy(stu[j].stuname,stu[j+1].stuname);
strcpy(stu[j].sex,stu[j+1].sex);
stu[j].age=stu[j+1].age;
strcpy(stu[j].clas,stu[j+1].clas);
strcpy(stu[j].specialty,stu[j+1].specialty);
stu[j].couid=stu[j+1].couid;
strcpy(stu[j].couname,stu[j+1].couname);
strcpy(stu[j].keyword,stu[j+1].keyword);
strcpy(stu[j].technology,stu[j+1].technology);
}
cout<<"提示:已成功删除!"<<endl;//返回成功信息
}
cout<<"你要删除信息如下:"<<endl;
cout<<"姓名:"<<stu[i].stuname<<endl;
cout<<"学号:"<<stu[i].stuid<<endl;
cout<<"性别:"<<stu[i].sex<<endl;
cout<<"年龄:"<<stu[i].age<<endl;
cout<<"班级:"<<stu[i].clas<<endl;
cout<<"专业:"<<stu[i].specialty<<endl;
cout<<"题目编号:"<<stu[i].couid<<endl;
cout<<"题目名称:"<<stu[i].couname<<endl;
cout<<"核心词:"<<stu[i].keyword<<endl;
cout<<"实现技术:"<<stu[i].technology<<endl;
write(n-1);
}
void Guanli::total()
{
{
int n=read();
char c[10];
cout<<"请输入需要查找题目名称:"<<endl;
cin>>c;
for(int i=0;i<n;i++)
if(strcmp(stu[i].couname,c)==0)
{
cout<<"你要记录信息如下:"<<endl;
cout<<"姓名:"<<stu[i].stuname<<endl;
cout<<"学号:"<<stu[i].stuid<<endl;
cout<<"性别:"<<stu[i].sex<<endl;
cout<<"年龄:"<<stu[i].age<<endl;
cout<<"班级:"<<stu[i].clas<<endl;
cout<<"专业:"<<stu[i].specialty<<endl;
cout<<"题目编号:"<<stu[i].couid<<endl;
cout<<"题目名称:"<<stu[i].couname<<endl;
cout<<"核心词:"<<stu[i].keyword<<endl;
cout<<"实现技术:"<<stu[i].technology<<endl;
}
else
{
cout<<"没有此条记录!"<<endl;
}
}
}
void Guanli::display()
{
int n=read();
cout<<endl<<"显示所有学生信息:"<<endl;
if(!stu)
cout<<"没有记录"<<endl;
else
{
for(int i=0;i<n;i++) //循环输入
cout<<"学号"<<stu[i].stuid<<'\n'<<"姓名"<<stu[i].stuname<<'\n'<<"性别"<<stu[i].sex<<'\n'<<"年龄"<<stu[i].age<<'\n'<<"班级"<<
stu[i].clas<<'\n'<<"专业"<<stu[i].specialty<<'\n'<<"题目编号"<<stu[i].couid<<'\n'<<"题目名称"<<stu[i].couname<<'\n'<<
"核心词"<<stu[i].keyword<<'\n'<<"实现技术"<<stu[i].technology<<'\n'<<endl;
}
}
3)主函数实现
int main()
{
char choice;
cout<<"\n\n\t **欢迎使用课程设计选题管理系统**\n\n";
cout<<"\t 1.********添加新记录********\n";
cout<<"\t 2.********查询记录信息********\n";
cout<<"\t 3.********修改学生信息********\n";
cout<<"\t 4.********删除学生信息********\n";
cout<<"\t 5.********记录所有记录********\n";
cout<<"\t 6.********显示所有记录********\n";
cout<<"\t 0.******** 退出系统 ********\n";
cout<<"\t 请输入您选取:";
cin>>choice;
Guanli g;
if(choice=='0')
{
cout<<"\n\t\t 谢谢您使用本系统!\n\n"<<endl;
exit(0);
}
else if(choice=='1')
{
g.add();
system("pause");
main();
}
else if(choice=='2')
{
g.search();
system("pause");
main();
}
else if(choice=='3')
{
g.alter();
system("pause");
main();
}
else if(choice=='4')
{
g.del();
system("pause");
main();
}
else if(choice=='5')
{
g.total();
system("pause");
main();
}
else if(choice=='6')
{
g.display();
system("pause");
main();
}
else
{
cout<<"\t 输入错误,请重新输入您选取:";
main();
}
return 0;
}
4、系统测试
1)添加功能
添加学生信息界面如下图所示:
2)查询功能
查询学生信息界面如下图所示:
①依照学生学号进行查询:
②依照学生姓名进行查询:
③依照题目编号进行查询:
④依照题目名称进行查询:
3)修改功能
修改学生有关信息,界面如下图所示:
4)删除功能
删除指定学生信息,界面如下图所示:
5)记录功能
依照题目名称记录学生信息,界面如下图所示:
6)显示功能
显示所有学生信息,界面如下图所示:
7)退出系统
退出使用系统,界面如下图所示:
三、心得体会
本课程设计中,我终于成功地实现了一种学生课程设计选题系统程序,一种一开始看来很难完毕任务。在做这个课程设计之前,我对课程设计均有一种笼统恐怕与抗拒,但在通过查阅资料,有了大概纹路,一步步开展咱们自己课程设计时,咱们发现看上去困难并不那么无法攻略,只要有耐心,细致往下做,悉心请教同窗与教师,咱们可以完毕看似无从下手设计。
在课程设计之前对 C++程序结识仅停留在看阶段, 而对编程实现结识很模糊, 只懂得大概意思, 在课程设计期间才懂得离独立编程尚有很远距离。 通过这次课程设计,一点点解决所遇到问题,咱们学到了诸多在课堂和课本上学不到知识。并且,咱们对面向对象编程、类、数组,指针等一系列概念也均有了更进一步结识,也初步意识到所学知识在实际应用中作用。
由于本人水平有限,在做课程设计是参照了诸多资料,并在某些书籍中找到理解决问题办法,在查阅书籍同步进行学习,通过多次修改与调试,最后交出了一份自己比较满意答卷。
通过这次课设,让我进一步掌握了C++程序设计语言,更好理解了面向对象程序设计思想。我相信这会对后来学习有协助作用。在后来学习中应当继续努力。
展开阅读全文