当前位置:
文档之家› 用链表与文件实现学生成绩管理系统
用链表与文件实现学生成绩管理系统
};
class Student
{
public:
Student();
void Ofile(ofstream &of);
void Infile(ifstream &f);
void Out();
void Set(char *name,int no,Class score);
char *GetName();
Student_First=new Student;
Read();
}
Function::~Function()
{
delete Student_First;
}
void Function::Add() //录入学生成绩信息函数
{
char name[20];
int no;
Class score;
char choose;
#include <iostream>
#include <fstream>
#include<cstring>
#include<conio.h>
#include <ctime>
using namespace std;
struct Class
{
int Chinese;
int Math;
int English;
do
{
cout<<"输入查询方式:\n1.按姓名查询\n2.按学号查询\n";
cin>>choose;
if(choose=='1')
{ cout<<"请输入您要查询的姓名:";
cin>>t1;
while(temp)
{
if(strcmp(t1,temp->GetName())==0)
{
flag=1;
break;
while(temp!=NULL)
{
temp->Out();
temp=temp->Next;
}
}
cout<<"1.返回主菜单"<<endl;
cin>>choose;
while(choose!='1')
{
cout<<"1.返回主菜单"<<endl;
cin>>choose;
}
Menu();
}
void Function::Menu()
while(p)
{
p->Ofile(of);
p=p->Next;
}
of.close();
}
void Function::Search()
{ int flag(0);
char choose;
char t1[20];
int t2;
system("cls");
Student *temp=Student_First->Next;
{
cout<<"1.返回主菜单\n2.继续删除"<<endl;cin>>choose;
}
if(choose=='1')
Menu();
else if(choose=='2')
Delete();
} void Function::Modify() //修改学生信息函数
{
char choose,name[20];
Student *temp,*p;
int no; Class score;
system("cls");
temp=p=Student_First;
cout<<"请输入您要修改的学生姓名:";
cin>>name;
while(temp)
{
if(strcmp(temp->GetName(),name)==0)
{
cout<<"姓名\t学号\t语文成绩\t数学成绩\t英语成绩\n";
temp->Out();
cout<<"请输入姓名:";
cin>>name;
cout<<"请输入学号:";
cin>>no;
cout<<"请输入语文成绩:";
cin>>score.Chinese;
cout<<"请输入数学成绩:";
cin>>score.Math;
p2->Infile(is);
p->Next=p2;
p2->Next=NULL;
p=p->Next;
}
}
void Function::Save() //保存学生成绩信息函数
{ ofstream of("Student.txt",ios::out);
Student *p=Student_First->Next;
cin>>choose;
}
while(choose=='y'||choose=='Y');
Save();
cout<<"1.返回主菜单"<<endl;
cin>>choose;
while(choose!='1')
{
cout<<"1.返回主菜单"<<endl;
cin>>choose;
}
Menu();
}
void Function::Delete() //删除信息函数
int GetNo();
Student *Next;
protected:
char Name[20];
int No;
Class Score;
};
Student::Student():Next(0){}
char *Student::GetName()
{
return Name;
}
int Student::GetNo()
{
char name[20];int no;
char choose;
Student *temp,*p;
system("cls");
p=temp=Student_First->Next;
cout<<"请输入姓名:";
cin>>name;
cout<<"输入学号:";
cin>>no; while(temp)
}
class Function //功能类
{
public:
Function(); //构造函数
~Function(); //析构函数
void Menu(); //菜单函数
void Add(); //录入学生成绩函数
void Search(); //查询学生成绩函数
void Delete(); //删除学生成绩函数{StudeFra bibliotekt *p,*p2;
p=Student_First;
ifstream is("Student.txt",ios::in);
if(!is)
{
ofstream os("Student.txt",ios::out);
os.close();
return;
}
while(!is.eof())
{
p2=new Student;
cout<<"请输入英语成绩:";
cin>>score.English;
temp->Set(name,no,score);
break;
}
temp=temp->Next;
} Save();
cout<<"修改成功!"<<endl;
cout<<"1.返回主菜单\n2.继续修改"<<endl;
cin>>choose;
{return No;}
void Student::Set(char *name,int no,Class score)
{
strcpy(Name,name);
No=no;
Score=score;
}
void Student::Infile(ifstream &f)
{
f>>Name>>No>>Score.Chinese>>Score.Math>>Score.English; //将数据输入到文件
cin>>choose;
}
if(choose=='1')
Menu();
else if(choose=='2')
Search();
}
void Function::Show()
{
char choose;
Student *temp;
system("cls");
temp=Student_First->Next;
if(!temp)