C++课程设计:学生信息管理系统
2015-04-26 18:55
896 查看
课程设计内容
1.)学生信息的录入:录入新的学生的信息;2.)学生信息的添加:添加新的学生的信息;
3.) 学生信息的删除:删除不需要的学生的信息。
4.)学生信息的查找:查找你需要的学生的信息。
5.)学生信息的修改:修改错误的学生的信息。
6.)学生信息的显示:显示所有学生的信息。
7.)学生信息的保存:把学生的信息保存到文件并退出。
8.)学生信息的读取:从文件中读取所有学生的信息。
功能描述
1.添加、删除系统将提示用户输入新添加学生的信息;由用户输入要删除的学生的学号,然后调用删除函数,删除该名学生的资料。
2.查找
3.首先由用户输入要查找的学生的学号,系统用查找函数查找,然后系统就调用输出函数。
4.修改
首先由用户输入要修改的学生的学号,然后系统用修改函数查找,显示该名学生的资料,然后系统提示用户输入需要修改的项目和新的资料。
代码:
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstring>
using namespace std;
int n=0;
class Student
{
public:
int num;
char name[12];
char study[12];
char classe[12];
int score[3];
int s;
Student *next;
};
class Studentmanage
{
private:
Student *head,*p1,*p2,*p3;
public:
Studentmanage (){};
Student *creat();
Student *add(Student *head);
Student *delet(Student *head);
void *search(Student *head);
Student *modify(Student *head);
void display(Student *head);
void write_file(Student *head);
Student * read_file();
~Studentmanage (){};
};
Student *Studentmanage::creat()
{
p1=p2=new Student;
head=NULL;
cout<<"请输入学生的基本信息:以学号为0结束。\n";
while(1)
{
cout<<"学号:";
cin>>p1->num;
if(p1->num==0)
{
break;
}
cout<<"姓名:";
cin>>p1->name;
cout<<"院系:";
cin>>p1->study;
cout<<"班级:";
cin>>p1->classe;
cout<<"C++成绩:";
cin>>p1->score[0];
cout<<"高数成绩:";
cin>> p1->score[1];
cout<<"英语成绩:";
cin>>p1->score[2];
p1->s=p1->score[0]+p1->score[1]+p1->score[2];
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=new Student;
}
p2->next=NULL;
return head;
}
Student *Studentmanage::add(Student *head)
{
long int Num;
p1=p2=new Student;
p3=new Student;
p1=head;
int j=0;
cout<<"请输入你要添加学生的位置:\n";
cout<<"如果想放在头,请输入0, 否则请输入要添加前一个学生的学号:\n";
cin>>Num;
if(Num==0)
{
cout<<"请输入要添加学生的信息!\n学号:";
cin>>p3->num;
cout<<"姓名:";
cin>>p3->name;
cout<<"院系:";
cin>>p3->study;
cout<<"班级:";
cin>>p3->classe;
cout<<"C++成绩:";
cin>>p3->score[0];
cout<<"高数成绩:";
cin>>p3->score[1];
cout<<"英语成绩:";
cin>>p3->score[2];
p3->s=p3->score[0]+p3->score[1]+p3->score[2];
p1=head;
head=p3;
p3->next=p1;
n++;
j=1;
}
else
{
p1=head;
p2=p1->next;
while(p1!=NULL)
{
if(p1->num==Num)
{
cout<<"请输入要添加学生的信息!\n学号:";
cin>>p3->num;
cout<<"姓名:";
cin>>p3->name;
cout<<"院系:";
cin>>p3->study;
cout<<"班级:";
cin>>p3->classe;
cout<<"C++成绩:";
cin>>p3->score[0];
cout<<"高数成绩:";
cin>>p3->score[1];
cout<<"英语成绩:";
cin>>p3->score[2];
p3->s=p3->score[0]+p3->score[1]+p3->score[2];
p1->next=p3;
p3->next=p2;
n++;
j=1;
break;
}
else
{
p1=p2;
p2=p1->next;
}
}
}
if(j==0)
cout<<"你要添加的位置不存在,添加失败!\n";
else
cout<<"添加成功!\n";
return head;
}
Student *Studentmanage::delet(Student *head)
{
long int Num;
p2=p1=new Student;
cout<<"请输入要删除学生的学号:\n";
cin>>Num;
p2=p1=head;
int j=0;
if(head->num==Num&&head!=NULL)
{
head=head->next;
delete(p1);
j=1;
n--;
}
else
{
p1=head->next;
while(p1!=NULL)
{
if(p1->num==Num)
{
p2->next=p1->next;
free(p1);
j=1;
n--;
break;
}
else
{
p2=p1;
p1=p2->next;
}
}
}
if(j==0)
cout<<"此学生不存在,删除的失败!\n";
else
cout<<"删除成功!\n";
return head;
}
void *Studentmanage::search(Student *head)
{
long int Num;
p1=new Student;
cout<<"请输入要查找学生的学号:\n";
cin>>Num;
p1=head;
int j=0;
while(p1!=NULL)
{
if(p1->num==Num)
{
cout<<"学号:"<<p1->num;
cout<<" 姓名:"<<p1->name;
cout<<" 院系:"<<p1->study;
cout<<" 班级:"<<p1->classe;
cout<<" C++成绩:"<<p1->score[0];
cout<<" 高数成绩:"<<p1->score[1];
cout<<" 英语成绩:"<<p1->score[2];
cout<<" 总成绩:"<<p1->s<<endl;
j=1;
break;
}
p1=p1->next;
}
if(j==0)
cout<<"没有找到你要查找学生的信息。\n";
else
cout<<"这是你要查找学生的信息:\n";
}
Student *Studentmanage::modify(Student *head)
{
long int Num;
long int num1;
char name1[12];
char study1[12];
char classe1[12];
int score1[3];
p1=new Student;
int j=0;
cout<<"请输入你要更改学生的学号:\n";
cin>>Num;
p1=head;
if(head->num==Num)
{
cout<<"显示要修改学生的信息:\n";
cout<<"学号:"<<head->num<<" 姓名:"<<head->name<<" 院系:"<<head->study;
cout<<" 班级:"<<head->classe<<"C++成绩:"<<head->score[0];
cout<<" 高数成绩:"<<head->score[1]<<" 英语成绩:"<<head->score[2];
cout<<"总成绩:"<<head->s<<endl;
cout<<"请输入要更改学生的信息:\n";
cout<<"学号:";
cin>>num1;
cout<<"姓名:";
cin>>name1;
cout<<"院系:";
cin>>study1;
cout<<"班级:";
cin>>classe1;
cout<<"C++成绩:";
cin>>score1[0];
cout<<"高数成绩:";
cin>>score1[1];
cout<<"英语成绩:";
cin>>score1[2];
head->num=num1;
strcpy(head->name,name1);
strcpy(head->study,study1);
strcpy(head->classe,classe1);
head->score[0]=score1[0];
head->score[1]=score1[1];
head->score[2]=score1[2];
head->s=head->score[0]+head->score[1]+head->score[2];
j=1;
}
else
{
p1=head->next;
while(p1!=NULL)
{
if(p1->num!=Num)
{
p1=p1->next;
}
else
{
cout<<"显示要修改学生的信息:\n";
cout<<"学号:"<<p1->num<<" 姓名:"<<p1->name<<" 院系:"<<p1->study;
cout<<" 班级:"<<p1->classe<<"C++成绩:"<<p1->score[0];
cout<<" 高数成绩:"<<p1->score[1]<<" 英语成绩:"<<p1->score[2]<<endl;
cout<<"请输入要更改学生的信息:\n";
cout<<"学号:";
cin>>num1;
cout<<"姓名:";
cin>>name1;
cout<<"院系:";
cin>>study1;
cout<<"班级:";
cin>>classe1;
cout<<"C++成绩:";
cin>>score1[0];
cout<<"高数成绩:";
cin>>score1[1];
cout<<"英语成绩:";
cin>>score1[2];
p1->num=num1;
strcpy(p1->name,name1);
strcpy(p1->study,study1);
strcpy(p1->classe,classe1);
p1->score[0]=score1[0];
p1->score[1]=score1[1];
p1->score[2]=score1[2];
p1->s=p1->score[0]+p1->score[1]+p1->score[2];
j=1;
break;
}
}
}
if(j==0)
cout<<"没有找到你要更改的学生,更改失败!\n";
else
cout<<"更改成功!\n";
return head;
}
void Studentmanage::display(Student *head)
{
int i;
i=n;
cout<<"这里有"<<n<<"个学生的信息:"<<endl;
p1=head;
if(p1==NULL)
cout<<"这是一个空表!请先输入学生信息。"<<endl;
else
{
while(i>0)
{
cout<<"学号:"<<p1->num<<" 姓名:"<<p1->name<<" 院系:"<<p1->study;
cout<<" 班级:"<<p1->classe<<" C++成绩:"<<p1->score[0];
cout<<" 高数成绩:"<<p1->score[1]<<" 英语成绩:"<<p1->score[2];
cout<<" 总成绩:"<<p1->s<<endl;
p1=p1->next;
i--;
}
}
}
Student *Studentmanage::read_file()
{
int num;
int i=0;
char name[12];
char study[12];
char classe[12];
int score[3];
int s;
p1=p2=new Student;
head=NULL;
ifstream in;
in.open("yyy.txt");
if(!in)
{
cout<<"打开文件失败!"<<endl;
}
while(in)
{
in>>num>>name>>study>>classe>>score[0]>>score[1]>>score[2]>>s;
p1->num=num;
strcpy(p1->name,name);
strcpy(p1->study,study);
strcpy(p1->classe,classe);
p1->score[0]=score[0];
p1->score[1]=score[1];
p1->score[2]=score[2];
p1->s=s;
i++;
if(i==1)
{
head=p2=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=new Student;
n=i-1;
}
return head;
}
void Studentmanage::write_file(Student *head)
{
ofstream out;
out.open("yyy.txt");
if(!out)
{
cout<<"打开文件失败!"<<endl;
}
p1=NULL;
p1=head;
while(p1)
{
out<<p1->num<<setw(5)<<p1->name<<setw(5)<<p1->study<<setw(5)<<p1->classe<<setw(5)<<p1->score[0]<<setw(5)<<p1->score[1]<<setw(5)<<p1->score[2]<<setw(5)<<p1->s<<endl;
p1=p1->next;
}
out.close();
}
char menu()
{
system("cls");
char ch;
cout<<"\t\t\t---------请选择:-----------\n";
cout<<"\t\t\t---------1.录入功能-------\n";
cout<<"\t\t\t---------2.添加功能:-------\n";
cout<<"\t\t\t---------3.删除功能:-------\n";
cout<<"\t\t\t---------4.查找功能:-------\n";
cout<<"\t\t\t---------5.修改功能:-------\n";
cout<<"\t\t\t---------6.显示功能:----\n";
cout<<"\t\t\t---------7.保存并退出:----------\n";
cout<<"\t\t\t---------8读出文件-----------\n";
cin>>ch;
return ch;
}
int main ()
{
Studentmanage s;
Student *head;
char c;
cout<<"欢迎使用学生信息管理系统!\n";
cout<<"**********************************作者:于洋洋\n";
cout<<"----------------------- 祝你使用愉快!\n";
system("pause");
while(1)
switch (menu())
{
case'1':head=s.creat();system("pause");break;
case'2':head=s.add(head);system("pause");break;
case'3':head=s.delet(head);system("pause");break;
case'4':s.search(head);system("pause");break;
case'5':head=s.modify(head);system("pause");break;
case'6':s.display(head);system("pause");break;
case'7':s.write_file(head);cout<<"谢谢使用!再见!\n";system("pause");return 0;
case'8':head=s.read_file();system("pause");break;
default:cout<<"选择有错,请重新选择\n";
}
return 0;
}
相关文章推荐
- 关于c++ 课程设计(学生信息管理系统)
- 大一第一学期c语言课程设计,黑框框简易版学生信息管理系统
- 记C++课程设计--学生信息管理系统
- 数据结构课程设计——学生信息管理系统
- 课程设计: 学生信息管理系统
- 课程设计---学生信息管理系统
- C语言课程设计-学生信息管理系统
- C++课程设计:学生成绩管理系统
- 数据结构课程设计—学生信息管理系统
- 课程设计:学生信息管理系统设计
- 数据结构课程设计论文--学生信息管理系统
- 课程设计--学生信息管理系统
- 课程设计:学生管理系统(c++)
- JAVA课程设计-学生信息管理系统(个人博客)
- 课程设计————学生信息管理系统
- 课程设计-简易学生信息管理系统
- 数据结构课程设计【学生信息管理系统(烟大版)】
- C语言学生成绩信息管理系统课程设计报告
- 学生信息管理系统(cocos2d引擎)——数据结构课程设计
- 数据结构课程设计--学生信息管理系统