c++学生信息管理系统
全文是基于文件输入输出流基础上没有链接数据库,实现学生提交与老师批改作业。学生的增删改查,老师的评分等功能。
#include<string>
#include<iostream>
#include<fstream>
using namespace std;
class student{
private:
string name;
string major;
string yuanxi;
string student_num;
string work;
class student *next;
public:
student():next(NULL){}
void submit(class student* head);//录入提交作业
void findwork(class student* t);//按照学号查询学生作业内容
void findsorce(class student* t);//按照学号查询学生成绩
void updatework(class student* head);//修改作业
void deletework(class student* head);//作业删除
int read(class student* head);//文件读入
void write(class student* t);//文件写入
void view();//评分
void look();//查看提交情况
};
void student::submit(class student* head)
{
student *newSTD;
newSTD=head;
while(head->next != NULL)
{
head = head->next;
}
student* newnode = new student ;
head->next = newnode;
newnode->next = NULL;
cout<<"请输入学号"<<endl;
while(1)
{
int a=1;
string name1;
cout << "学号: " << endl;
cin>>name1;
while(newSTD->next!=NULL)
{
if(name1==newSTD->next->student_num)
{
cout<<"学号重复,请重新输入:"<<endl;
a=0;
break;
}
newSTD=newSTD->next;
}
if(a==1)
{
newnode->student_num=name1;
break;
}
}
cout<<"学生姓名: "<<endl;
cin>>newnode->name;
cout<<"学生专业: "<<endl;
cin>>newnode->major;
cout<<"学生院系: "<<endl;
cin>>newnode->yuanxi;
cout<<"请输入作业"<<endl;
//存入文件
cin>>newnode->work;
}
void student::findwork(class student* t)//按照学号查询学生作业内容
{
string n;
cout << "请输入你的学号:" << endl;
cin >> n;
int count = 0;
while(t->next != NULL)
{
if(t->next->student_num == n)
{
cout << "学号:" ;
cout << t->next->student_num<<'\t';
cout << "作业内容:";
cout << t->next->work <<'\t';
count++;
}
t = t->next;
}
if(count == 0)
{
cout << "查无此人!" << endl;
}
}
void student::findsorce(class student* t);//按照学号查询学生成绩
{
string n;
cout << "请输入你想查询的学生学号:" << endl;
cin >> n;
int count = 0;
while(t->next != NULL)
{
if(t->next->student_num == n)
{
cout << "学号:" ;
cout << t->next->student_num<<'\t';
cout << "成绩:";
cout << t->next->score <<'\t';
count++;
}
t = t->next;
}
if(count == 0)
{
cout << "查无此人!" << endl;
}
}
void student::updatework(class student* head)//修改作业
{
cout << "请输入你的的学号:"<< endl;
int count = 0;
string temp;
cin >> temp;
while(head->next != NULL)
{
if(temp == head->next->student_num)
{
count = 1;
while(1)
{
cout << "输入新作业: " << endl;
int temp2;
cin >> temp2;
head->next->work = temp2;
cout << "修改成功" << endl;
break;
}
break;
}
head = head->next;
}
if(count == 0)
{
cout << "查无此人" << endl;
}
}
void student::deletework(class student* t)//作业删除//temp是什么作用,我应该删除work
{
string n;
cout << "请输入你的学号:" << endl;
cin >> n;
int count = 0;
while(t->next != NULL)
{
if(t->next->student_num == n)
{
student* temp = t->next;
t->next = t->next->next;
delete temp;
temp = NULL;
cout << "删除成功!" << endl;
count++;
break;
}
t = t->next;
}
if(count == 0)
{
cout << "查无此人!" << endl;
}
}
void student::view(class student* t)//评分
{
string name1;
string score1;
cout << "请输入您的名字:" ;
cin>>name1;
newnode->teacher_name=name1;
string n;
cout << "请输入学生学号:" << endl;
cin >> n;
int count = 0;
while(t->next != NULL)
{
if(t->next->student_num == n)
{
cout << "学号:" ;
cout << t->next->student_num<<'\t';
cout << "名字:";
cout << t->next->name <<'\t';
cout << "专业:" ;
cout << t->next->major <<'\t';
cout << "院系:" ;
cout << t->next->yuanxi <<'\t';
cout << "作业:" ;
cout << t->next->work <<'\t';
count++;
cout << "请输入该学生的分数:" ;
cin>>score1;
newnode->student_score=score1;
}
t = t->next;
}
if(count == 0)
{
cout << "查无此人!" << endl;
}
}
void student::look(class student* t)//查看提交情况
{
int i = 0;
while(head->next != NULL)
{
i++;
cout << i << "." << "学号:" ;
cout << head->next->student_num <<'\t';
cout << "名字:";
cout << head->next->name <<'\t';
cout << "专业:" ;
cout << head->next->major <<'\t';
cout << "院系:" ;
cout << head->next->yuanxi <<endl;
head = head->next;
}
cout<<'\n';
cout<<"提交总人数为:";
cout<<i<<"人"<<endl;
}
int student::read(class student* head)//读入
{
ofstream infile1;
infile1.open("学生系统.txt",ios::app);
if(!infile1)
{
return 0;
}
else
{
infile1.close();
ifstream infile;
infile.open("学生系统.txt",ios::in);
while(!infile.eof())
{
student* newnode = new student;
infile >> newnode->student_num;
if(newnode->student_num.length() == 0)
{
delete newnode;
break;
}
infile >> newnode->name;
infile >> newnode->student_num;
infile >> newnode->major;
infile >> newnode->yuanxi;
head->next = newnode;
head = head->next;
}
infile.close();
}
return 0;
}
void student::write(class student* t)//写出
{
ofstream outfile;
outfile.open("学生系统.txt",ios::out);
while(t->next != NULL)
{
outfile << t->next->student_num <<'\t';
outfile << t->next->name << '\t';
outfile << t->next->major << '\t';
outfile << t->next->yuanxi << endl;
t = t->next;
}
outfile.close();
}
int main()
{
while(1)
{
cout<<"您想实现的功能是:1.学生提交 2.老师评分 0.退出系统 "<<endl;
int i;
cin>>i;
switch(i)
{
case 1:
{
int tmp=1;
while(tmp)
{
cout<<"请输入你想选择的功能:" << endl;
cout << " 1.提交作业" << endl;
cout << " 2.按照学号查询作业内容" << endl;
cout << " 3.按学号查询学生成绩" << endl;
cout << " 4.按照学号修改作业" << endl;
cout << " 5.按照学号删除作业"<<endl;
cout << " 0.返回上一级" << endl;
int t;
cin>>t;
switch(t)
{
case 1:
{
headstudent->submit(headstudent);
headstudent->write(headstudent);
break;
}
case 2:
{
headstudent->findwork(headstudent);
}
case 3:
{
headstudent->findsorce(headstudent);
break;
}
case 4:
{
headstudent->updatework(headstudent);
headstudent->write(headstudent);
break;
}
case 5:
{
headstudent->deletework(headstudent);
headstudent->write(headstudent);
break;
}
case 0:
{
tmp=0;break;
}
default: cout << "请重新输入正确的操作指令" << endl;
}
}
break;
}
case 2:
{
int tmp=1;
while(tmp)
{
cout<<"请输入你想选择的功能:" << endl;
cout << " 1.查看提交作业情况" << endl;
cout << " 2.学生作业评分" << endl;
cout << " 0.返回上一级" << endl;
int t;
cin>>t;
switch(t)
{
case 1:
{
headteacher->read(headstudent);
headteacher->view(headstudent);
break;
}
case 2:
{
headstudent->read(headstudent);
headstudent->view(headstudent);
headstudent->write(headstudent);
break;
}
case 0:
{
tmp=0;break;
}
default: cout << "请重新输入正确的操作指令" << endl;
}
}
break;
}
case 0:
{
cout<<"***********************************欢迎下次使用本系统**************************************";
return 0;
}
default: cout << "请重新输入正确的操作指令" << endl;
}
}
}