自己用c++写的简单成绩管理系统框架
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<windows.h>
using namespace std;
void color(const unsigned short color1)
{
if(color1>=0&&color1<=15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color1);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
//个人信息的类
class information
{
public:
string name,num,phone,id,sex; //name是姓名,num是学号,age年龄,sex性别,phone是电话号码,id是身份证号码
int age;
information(string na="0",string nu="0",int ag=0,string se="0",string ph="0",string i="0"):name(na),num(nu),age(ag),sex(se),phone(ph),id(i){}//构造函数,初值均赋为零
//各项数据的输入
void inputname(string na){name=na;}
void inputnum(string na){num=na;}
void inputage(int na){age=na;}
void inputsex(string na){sex=na;}
void inputphone(string na){phone=na;}
void inputid(string na){id=na;}
//各项数据的输出
string outputname(){return name;}
string outputnum(){return num;}
int outputage(){return age;}
string outputsex(){return sex;}
string outputphone(){return phone;}
string outputid(){return id;}
};
//存放学生成绩的类
class grade
{
public:
double clang,eng,math; //clang就是c++
grade(double a=0,double b=0,double c=0):clang(a),eng(b),math(c){}
//输入成绩
void inputclang(double a){clang=a;}
void inputeng(double a){eng=a;}
void inputmath(double a){math=a;}
//返回成绩
double outputclang(){return clang;}
double outputeng(){return eng;}
double outputmath(){return math;}
};
class student:public information,public grade //学生类
{
public:
static int a;
student *next;
student(){a++;}
void print(); //输出成绩
~student(){a--;}
};
void student::print()
{
//color(6);
cout<<"姓名是"<<outputname()<<endl
<<"学号是"<<outputnum()<<endl
<<"年龄是"<<outputage()<<endl
<<"性别是"<<outputsex()<<endl
<<"电话是"<<outputphone()<<endl
<<"身份证号是"<<outputid()<<endl
<<"c++成绩是"<<outputclang()<<endl
<<"英语成绩是"<<outputeng()<<endl
<<"数学成绩是"<<outputmath()<<endl;
// color(16);
}
student *the,*head;
int student::a=0;
void add() //增加数据
{
string a;
int b;
double c;
if(!head)
{
head=new student;
the=head;
//在这里开始输入数据
color(14);
cout<<"请输入姓名:";cin>>a;the->inputname(a);
cout<<"请输入学号:";cin>>a;the->inputnum(a);
cout<<"请输入年龄:";cin>>b;the->inputage(b);
cout<<"请输入性别:";cin>>a;the->inputsex(a);
cout<<"请输入电话:";cin>>a;the->inputphone(a);
cout<<"请输入身份证号:";cin>>a;the->inputid(a);
cout<<"请输入c++成绩:";cin>>c;the->inputclang(c);
cout<<"请输入英语成绩:";cin>>c;the->inputeng(c);
cout<<"请输入数学成绩:";cin>>c;the->inputmath(c);
color(16);
the->next=NULL;
}
else
{
the->next=new student;
the=the->next;
//在这里开始输入数据
color(14);
cout<<"请输入姓名:";cin>>a;the->inputname(a);
cout<<"请输入学号:";cin>>a;the->inputnum(a);
cout<<"请输入年龄:";cin>>b;the->inputage(b);
cout<<"请输入性别:";cin>>a;the->inputsex(a);
cout<<"请输入电话:";cin>>a;the->inputphone(a);
cout<<"请输入身份证号:";cin>>a;the->inputid(a);
cout<<"请输入c++成绩:";cin>>c;the->inputclang(c);
cout<<"请输入英语成绩:";cin>>c;the->inputeng(c);
cout<<"请输入数学成绩:";cin>>c;the->inputmath(c);
color(16);
the->next=NULL;
}
}
void del() //删除,通过学号查询
{
student *t;
string a;
//color(11);
cout<<"请输入想删除的学生的学号:";cin>>a;
//color(16);
if(head->num==a){head=head->next;return;}
for(t=head;t->next;t=t->next)
{
if(t->next->num==a)
{
t->next=t->next->next;
return;
}
}
}
void seek() //查询一个学生的各项信息
{
student *t;
string a;
//color(11);
cout<<"请输入你想查看的学生的学号:";cin>>a;
//color(16);
for(t=head;t;t=t->next)
{
if(t->num==a)
{
t->print();
return;
}
}
}
void change() //修改学生信息
{
student *t;
string a;
int b;
double c;
//color(12);
cout<<"输入你想修改信息的学生的学号:";cin>>a;
//color(16);
for(t=head;;t=t->next)
{
if(t->num==a)
{
//color(13);
cout<<"原姓名是"<<the->outputname()<<" ";
cout<<"请输入想修改成的姓名:";cin>>a;the->inputname(a);
cout<<"原学号是"<<the->outputnum()<<" ";
cout<<"请输入想修改成的学号:";cin>>a;the->inputnum(a);
cout<<"原年龄是"<<the->outputage()<<" ";
cout<<"请输入想修改成的年龄:";cin>>b;the->inputage(b);
cout<<"原性别是"<<the->outputsex()<<" ";
cout<<"请输入想修改成的性别:";cin>>a;the->inputsex(a);
cout<<"原电话是"<<the->outputphone()<<" ";
cout<<"请输入想修改成的电话:";cin>>a;the->inputphone(a);
cout<<"原身份证号是"<<the->outputid()<<" ";
cout<<"请输入想修改成的身份证号:";cin>>a;the->inputid(a);
cout<<"原c++成绩是"<<the->outputclang()<<" ";
cout<<"请输入想修改成的c++成绩:";cin>>c;the->inputclang(c);
cout<<"原英语成绩是"<<the->outputeng()<<" ";
cout<<"请输入想修改成的英语成绩:";cin>>c;the->inputeng(c);
cout<<"原数学成绩是"<<the->outputmath()<<" ";
cout<<"请输入想修改成的数学成绩:";cin>>c;the->inputmath(c);
// color(16);
return;
}
}
}
void save()
{
student *t;
ofstream outfile("E:\\student.txt",ios::app);
for(t=head;t;t=t->next)
{
outfile<<t;
}
outfile.close();
}
void shuchu()
{
student *t;
for(t=head;t;t=t->next)
{
t->print();
}
}
void main()
{
int a;
//color(10);
cout<<"请输入一个数字以实现各功能"<<endl<<"输入1:增加。输入2:删除。输入3:查找。输入4:修改。输入5:存盘。输入6:显示。输入7:退出。"<<endl;
while(1)
{
cout<<"请输入:";cin>>a;
switch(a)
{
case 1: add();break;
case 2: del();break;
case 3: seek();break;
case 4: change();break;
case 5: save();break;
case 6: shuchu();break;
case 7:save();return;
}
}
system("pause");
}
#include<fstream>
#include<iomanip>
#include<string>
#include<windows.h>
using namespace std;
void color(const unsigned short color1)
{
if(color1>=0&&color1<=15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color1);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
//个人信息的类
class information
{
public:
string name,num,phone,id,sex; //name是姓名,num是学号,age年龄,sex性别,phone是电话号码,id是身份证号码
int age;
information(string na="0",string nu="0",int ag=0,string se="0",string ph="0",string i="0"):name(na),num(nu),age(ag),sex(se),phone(ph),id(i){}//构造函数,初值均赋为零
//各项数据的输入
void inputname(string na){name=na;}
void inputnum(string na){num=na;}
void inputage(int na){age=na;}
void inputsex(string na){sex=na;}
void inputphone(string na){phone=na;}
void inputid(string na){id=na;}
//各项数据的输出
string outputname(){return name;}
string outputnum(){return num;}
int outputage(){return age;}
string outputsex(){return sex;}
string outputphone(){return phone;}
string outputid(){return id;}
};
//存放学生成绩的类
class grade
{
public:
double clang,eng,math; //clang就是c++
grade(double a=0,double b=0,double c=0):clang(a),eng(b),math(c){}
//输入成绩
void inputclang(double a){clang=a;}
void inputeng(double a){eng=a;}
void inputmath(double a){math=a;}
//返回成绩
double outputclang(){return clang;}
double outputeng(){return eng;}
double outputmath(){return math;}
};
class student:public information,public grade //学生类
{
public:
static int a;
student *next;
student(){a++;}
void print(); //输出成绩
~student(){a--;}
};
void student::print()
{
//color(6);
cout<<"姓名是"<<outputname()<<endl
<<"学号是"<<outputnum()<<endl
<<"年龄是"<<outputage()<<endl
<<"性别是"<<outputsex()<<endl
<<"电话是"<<outputphone()<<endl
<<"身份证号是"<<outputid()<<endl
<<"c++成绩是"<<outputclang()<<endl
<<"英语成绩是"<<outputeng()<<endl
<<"数学成绩是"<<outputmath()<<endl;
// color(16);
}
student *the,*head;
int student::a=0;
void add() //增加数据
{
string a;
int b;
double c;
if(!head)
{
head=new student;
the=head;
//在这里开始输入数据
color(14);
cout<<"请输入姓名:";cin>>a;the->inputname(a);
cout<<"请输入学号:";cin>>a;the->inputnum(a);
cout<<"请输入年龄:";cin>>b;the->inputage(b);
cout<<"请输入性别:";cin>>a;the->inputsex(a);
cout<<"请输入电话:";cin>>a;the->inputphone(a);
cout<<"请输入身份证号:";cin>>a;the->inputid(a);
cout<<"请输入c++成绩:";cin>>c;the->inputclang(c);
cout<<"请输入英语成绩:";cin>>c;the->inputeng(c);
cout<<"请输入数学成绩:";cin>>c;the->inputmath(c);
color(16);
the->next=NULL;
}
else
{
the->next=new student;
the=the->next;
//在这里开始输入数据
color(14);
cout<<"请输入姓名:";cin>>a;the->inputname(a);
cout<<"请输入学号:";cin>>a;the->inputnum(a);
cout<<"请输入年龄:";cin>>b;the->inputage(b);
cout<<"请输入性别:";cin>>a;the->inputsex(a);
cout<<"请输入电话:";cin>>a;the->inputphone(a);
cout<<"请输入身份证号:";cin>>a;the->inputid(a);
cout<<"请输入c++成绩:";cin>>c;the->inputclang(c);
cout<<"请输入英语成绩:";cin>>c;the->inputeng(c);
cout<<"请输入数学成绩:";cin>>c;the->inputmath(c);
color(16);
the->next=NULL;
}
}
void del() //删除,通过学号查询
{
student *t;
string a;
//color(11);
cout<<"请输入想删除的学生的学号:";cin>>a;
//color(16);
if(head->num==a){head=head->next;return;}
for(t=head;t->next;t=t->next)
{
if(t->next->num==a)
{
t->next=t->next->next;
return;
}
}
}
void seek() //查询一个学生的各项信息
{
student *t;
string a;
//color(11);
cout<<"请输入你想查看的学生的学号:";cin>>a;
//color(16);
for(t=head;t;t=t->next)
{
if(t->num==a)
{
t->print();
return;
}
}
}
void change() //修改学生信息
{
student *t;
string a;
int b;
double c;
//color(12);
cout<<"输入你想修改信息的学生的学号:";cin>>a;
//color(16);
for(t=head;;t=t->next)
{
if(t->num==a)
{
//color(13);
cout<<"原姓名是"<<the->outputname()<<" ";
cout<<"请输入想修改成的姓名:";cin>>a;the->inputname(a);
cout<<"原学号是"<<the->outputnum()<<" ";
cout<<"请输入想修改成的学号:";cin>>a;the->inputnum(a);
cout<<"原年龄是"<<the->outputage()<<" ";
cout<<"请输入想修改成的年龄:";cin>>b;the->inputage(b);
cout<<"原性别是"<<the->outputsex()<<" ";
cout<<"请输入想修改成的性别:";cin>>a;the->inputsex(a);
cout<<"原电话是"<<the->outputphone()<<" ";
cout<<"请输入想修改成的电话:";cin>>a;the->inputphone(a);
cout<<"原身份证号是"<<the->outputid()<<" ";
cout<<"请输入想修改成的身份证号:";cin>>a;the->inputid(a);
cout<<"原c++成绩是"<<the->outputclang()<<" ";
cout<<"请输入想修改成的c++成绩:";cin>>c;the->inputclang(c);
cout<<"原英语成绩是"<<the->outputeng()<<" ";
cout<<"请输入想修改成的英语成绩:";cin>>c;the->inputeng(c);
cout<<"原数学成绩是"<<the->outputmath()<<" ";
cout<<"请输入想修改成的数学成绩:";cin>>c;the->inputmath(c);
// color(16);
return;
}
}
}
void save()
{
student *t;
ofstream outfile("E:\\student.txt",ios::app);
for(t=head;t;t=t->next)
{
outfile<<t;
}
outfile.close();
}
void shuchu()
{
student *t;
for(t=head;t;t=t->next)
{
t->print();
}
}
void main()
{
int a;
//color(10);
cout<<"请输入一个数字以实现各功能"<<endl<<"输入1:增加。输入2:删除。输入3:查找。输入4:修改。输入5:存盘。输入6:显示。输入7:退出。"<<endl;
while(1)
{
cout<<"请输入:";cin>>a;
switch(a)
{
case 1: add();break;
case 2: del();break;
case 3: seek();break;
case 4: change();break;
case 5: save();break;
case 6: shuchu();break;
case 7:save();return;
}
}
system("pause");
}