面向对象程序设计-----图书管理系统,学生信息管理系统

图书管理系统包括增、删、查、改的功能,利用类的抽象、继承、多态的性质以及文件的储存。

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
class book
{
private:
    string name;
    float price;
public:
    book();//构造函数
    string get_name();
    void setname(const string newname);
    float get_price();
    void setprice(const float newprice);
};
book::book()
{
    name="liyan";
    price=0;
}
string book::get_name()
{
    return name;
}
void book::setname(const string newname)
{
    name=newname;
}
float book::get_price()
{
    return price;
}
void book::setprice(const float newprice)
{
    price=newprice;
}
class bookl:public book
{
protected:
    string isbn;
    string publisher;
    string writer;
    int quantity;
public:
    bookl();
    string get_writer();
    void setwriter(const string newwriter);
    string get_publisher();
    int get_quantity();
    string get_isbn();
    void setpublisher(const string newpublisher);
    void setquantity(const int newquantity);
    void setisbn(const string newisbn);
};
bookl::bookl()
{

}
string bookl::get_writer()
{
    return writer;
}
void bookl::setwriter(const string newwriter)
{
    writer=newwriter;
}
string bookl::get_publisher()
{
    return publisher;
}
int bookl::get_quantity()
{
    return quantity;
}
string bookl::get_isbn()
{
    return isbn;
}
void bookl::setpublisher(const string newpublisher)
{
    publisher=newpublisher;
}
void bookl::setquantity(const int newquantity)
{
    quantity=newquantity;
}
void bookl::setisbn(const string newisbn)
{
    isbn=newisbn;
}
class booklist
{
    bookl booklist1[99];
public:
    int num;//图书数量
    void readfile();
    booklist();
    void writerfile();
    void insert1(const string newname,const float newprice,const string writer,const string isbn,const string publisher,const int quantity);
    void update(int i,string newname);
    void showbook_title();
    void deleted(int i);
    void showall();
    void showbook(int i);
    int search1(string name);

};
booklist::booklist()
{
    num=0;
}
void booklist::readfile()
{
    cout<<"\t****************************************************\n";
    cout<<"                                       \n\n";
    cout<<"\n\n\t\t\t欢迎使用图书管理系统\n\n\n";
    cout<<"                                        \n\n";
    cout<<"\t****************************************************\n\n";
    float pr,qw;
    char temp[99],temp1[99],temp2[99],temp3[99];
    ifstream infile("booklist.txt");
    if(!infile)
    {
        cerr<<"cannot open booklist.txt for output\n\n\n\n";
        return ;
    }
    while((infile>>temp))
    {
        infile>>pr;
        infile>>temp1;
        infile>>temp2;
        infile>>temp3;
        infile>>qw;
    }
    cout<<"从booklist.txt中读取已有图书如下:"<<endl;
    infile.close();
}
void booklist::writerfile()
{
    ofstream outfile("booklist.txt",ios::out);
    if(!outfile)
    {
        cerr<<"cannot open booklist.txt for output\n\n\n\n\n";
        exit(-1);
    }
    for(int i=0; i<num; i++)
    {
        outfile<<setiosflags(ios::left)<<setw(15)<<booklist1[i].get_name();
        outfile<<setiosflags(ios::left)<<setw(15)<<booklist1[i].get_price();
        outfile<<setiosflags(ios::left)<<setw(15)<<booklist1[i].get_writer();
        outfile<<setiosflags(ios::left)<<setw(15)<<booklist1[i].get_isbn();
        outfile<<setiosflags(ios::left)<<setw(15)<<booklist1[i].get_publisher();
        outfile<<setiosflags(ios::left)<<setw(15)<<booklist1[i].get_quantity()<<endl;
    }
    outfile.close();
}
void booklist::insert1(string newname,float newprice,const string writer,const string isbn,const string publisher,const int quantity)
{
    booklist1[num].setname(newname);
    booklist1[num].setprice(newprice);
    booklist1[num].setwriter(writer);
    booklist1[num].setisbn(isbn);
    booklist1[num].setpublisher(publisher);
    booklist1[num].setquantity(quantity);
    num++;
}
void booklist::showbook(int i)
{
    cout<<setiosflags(ios::left)<<setw(15)<<booklist1[i].get_name()<<setiosflags(ios::left);
    cout<<setw(15)<<booklist1[i].get_price()<<setw(15)<<setiosflags(ios::left);
    cout<<setw(15)<<booklist1[i].get_writer()<<setw(15)<<setiosflags(ios::left);
    cout<<setw(15)<<booklist1[i].get_isbn()<<setw(15);
    cout<<setiosflags(ios::left)<<booklist1[i].get_publisher()<<setw(15);
    cout<<setiosflags(ios::left)<<booklist1[i].get_quantity()<<endl;
    //cout<<booklist1[i].get_name();
}
int booklist::search1(string name)
{
    int i;
    for(i=0; i<num; i++)
    {
        if(booklist1[i].get_name()==name)
            return i;
    }
    if(i==num)
        return -1;
}
void booklist::update(int i,string newname)
{
    booklist1[i].setname(newname);
}
void booklist::deleted(int i)
{
    for(int j=i; j<num-1; j++)
    {
        booklist1[j].setname(booklist1[j+1].get_name());
        booklist1[j].setprice(booklist1[j+1].get_price());
        booklist1[j].setwriter(booklist1[j+1].get_writer());
        booklist1[j].setisbn(booklist1[j+1].get_isbn());
        booklist1[j].setpublisher(booklist1[j+1].get_publisher());
        booklist1[j].setquantity(booklist1[j+1].get_quantity());

    }
    num--;
}
void booklist::showbook_title()
{
    cout<<setiosflags(ios::left)<<setw(15)<<"书名"<<setiosflags(ios::left);
    cout<<setw(15)<<"价格"<<setiosflags(ios::left)<<setw(15)<<"作者";
    cout<<setiosflags(ios::left)<<setw(15)<<"isbn";
    cout<<setiosflags(ios::left)<<setw(15)<<"出版社";
    cout<<setiosflags(ios::left)<<setw(15)<<"数量"<<endl;

}
void booklist::showall()
{
    showbook_title();
    for(int i=0; i<num; i++)
        showbook(i);
    cout<<"共有图书"<<num<<"本"<<endl;
}
ostream & operator<<(ostream &cout1,bookl&book2)
{
    cout1<<setiosflags(ios::left)<<setw(15)<<book2.get_name();
    cout1<<setw(15)<<book2.get_price()<<setw(15)<<book2.get_writer();
    cout1<<setw(15)<<book2.get_isbn()<<setw(15)<<book2.get_publisher();
    cout1<<setw(15)<<book2.get_quantity()<<endl;
    return cout1;
}
int main()
{
    booklist b1;
    float pr,qw;
    char temp[99],temp1[99],temp2[99],temp3[99];
    int f=1;
    b1.readfile();
    while(f==1)
    {

        cout<<"1.添加 2.查询 3.修改 4.删除 5.显示全部 6.退出\n\n";
        int xz;
        cin>>xz;
        if(xz==1)
        {
            cout<<"请输入新书的书名:";
            cin>>temp;
            cout<<"请输入新书的作者:";
            cin>>temp1;
            cout<<"请输入新书的Isbn:";
            cin>>temp2;
            cout<<"请输入新书的出版社:";
            cin>>temp3;
            cout<<"请输入新书的单价:";
            cin>>pr;
            cout<<"请输入新书的数量:";
            cin>>qw;
            b1.insert1(temp,pr,temp1,temp2,temp3,qw);
            b1.showbook_title();
            b1.showbook(b1.num-1);
        }
        if(xz==2)
        {
            cout<<"请要查找图书的书名:";
            cin>>temp;
            int x=b1.search1(temp);
            if(x>=0)
            {
                b1.showbook(x);
            }
            else
                cout<<"未找到该书!"<<endl;
        }
        if(xz==3)
        {
            cout<<"请输入要修改图书的书名:";
            cin>>temp;
            int y=b1.search1(temp);
            if(y>=0)
            {
                cout<<"请输入要修改图书的书名:";
                cin>>temp;
                b1.update(y,temp);
                b1.showbook(y);
            }
            else
                cout<<"未找到该书!"<<endl;
        }
        if(xz==4)
        {
            cout<<"请输入要删除图书的书名:";
            cin>>temp;
            int z=b1.search1(temp);
            if(z>=0)
            {
                b1.deleted(z);
                cout<<"共有图书本数:"<<b1.num<<endl;
            }
            else
                cout<<"未找到该书!"<<endl;
        }
        if(xz==5)
        {
            b1.showall();
        }
        if(xz==6)
        {
            b1.writerfile();
            f=0;
        }
    }
    return 0;
}

 

学生信息管理系统是图书管理系统的延申,包括学生基本信息和成绩信息的增删查改的功能。

#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
class Student
{
private:
    string name;//存储姓名
    int num;//存储学号
    string sex;//存储性别
public:
    Student();//无参构造函数,给姓名、学号和性别设置默认值。
    string get_name();//获取学生姓名
    int get_num();//获取学生学号
    string get_sex();//获取学生性别
    void set_name(const string newname);//设置学生姓名
    void set_num(const int newnum);//设置学生学号
    void set_sex(const string newsex);//设置学生性别
};
Student::Student()//构造函数
{
    name="yinmengzhen";
    num=181210231;
    sex="g";
}
string Student::get_name()
{
    return name;
}
int Student::get_num()
{
    return num;
}
string Student::get_sex()
{
    return sex;
}
void Student::set_name(const string newname)
{
    name=newname;
}
void Student::set_num(const int newnum)
{
    num=newnum;
}
void Student::set_sex(const string newsex)
{
    sex=newsex;
}
class score :public Student
{
protected:
    float math;//存储学生数学成绩
    float engl;//存储学生英语成绩
    float mxdx;//存储学生c++成绩
public:
    score();//构造函数
    float get_math();//获取学生数学成绩
    float get_engl();//获取学生英语成绩
    float get_mxdx();//获取学生c++成绩
    void set_math(const float newmath);//设置学生数学成绩
    void set_engl(const float newengl);//设置学生英语成绩
    void set_mxdx(const float newmxdx);//设置学生c++成绩
};
score::score()
{
    math=0.0;
    engl=0.0;
    mxdx=0.0;
}
float score::get_math()
{
    return math;
}
float score::get_engl()
{
    return engl;
}
float score::get_mxdx()
{
    return mxdx;
}
void score::set_math(const float newmath)
{
    math=newmath;
}
void score::set_engl(const float newengl)
{
    engl=newengl;
}
void score::set_mxdx(const float newmxdx)
{
    mxdx=newmxdx;
}
class Students:public Student
{
protected:
    int grade;//用来储存年级
    int class1;//用来储存班级
    string major;//用来储存专业
public:
    Students();//无参构造函数,给年级、班级和专业设置默认值。
    int get_grade();//获取年级
    int get_class1();//获取班级
    string get_major();//获取专业
    void set_grade(const int newgrade);//设置年级
    void set_class1(const int newclass1);//设置班级
    void set_major(const string newmajor);//设置专业

};
Students::Students()
{
    grade=18;
    class1=2;
    major="jisuanjikeuxeyujishu";
}
int Students::get_grade()
{
    return grade;
}
int Students::get_class1()
{
    return class1;
}
string Students::get_major()
{
    return major;
}
void Students::set_grade(const int newgrade)
{
    grade=newgrade;
}
void Students::set_class1(const int newclass1)
{
    class1=newclass1;
}
void Students::set_major(const string newmajor)
{
    major=newmajor;
}
class Studentlists//学生成绩
{
    score Studentlist2[100];//定义score 类型的数组 Studentlist2用来存储学生成绩信息
public:
    Studentlists();//构造函数
    int sum1;//学生数量
    void readfile1();//读取文件开始界面
    void writerfile1();//存储数据到文件
    void insert11(const string newname,const int newnum,const string newsex,const float math,const float engl,const float mxdx);
    //添加学生信息
    void update1(int i,string newname,int newnum, string newsex, float newmath, float newengl, float newmxdx);//修改
    void showstudent_title1();//输出
    void deleted1(int i);//删除
    void showall1();//显示
    void showstudent1(int i);
    int search11(string name);//查询
    float total1(const float math,const float engl,const float mxdx);//获取学生总成绩
    float average(const float math,const float engl,const float mxdx);//获取学生的平均成绩
};
Studentlists::Studentlists()
{
    sum1=0;
}
void Studentlists::readfile1()
{

    float sx,yy,mx;
    int xh;
    char temp3[99],temp4[99];
    ifstream infile("Studentlists.txt");
    //定义文件指针infile指向booklist.txt
    if(!infile)
    {
        cerr<<"cannot open Studentlists.txt for output\n\n\n\n";
        return ;
    }
    while((infile>>temp3))
    {
        infile>>xh;
        infile>>temp4;
        infile>>sx;
        infile>>yy;
        infile>>mx;
        insert11(temp3,xh,temp4,sx,yy,mx);
    }
    //cout<<"从Studentlist.txt中读取已有学生如下:"<<endl;
    //showall();
    infile.close();
}
void Studentlists::writerfile1()
{
    ofstream outfile("Studentlists.txt",ios::out);
    if(!outfile)
    {
        cerr<<"cannot open Studentlists.txt for output\n\n\n\n\n";
        exit(-1);
    }
    for(int i=0; i<sum1; i++)
    {
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist2[i].get_name();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist2[i].get_num();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist2[i].get_sex();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist2[i].get_math();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist2[i].get_engl();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist2[i].get_mxdx()<<endl;
    }
    outfile.close();
}
void Studentlists::insert11(const string newname,const int newnum,const string newsex,const float newmath,const float newengl,const float newmxdx)
//添加学生信息
{
    Studentlist2[sum1].set_name(newname);
    Studentlist2[sum1].set_num(newnum);
    Studentlist2[sum1].set_sex(newsex);
    Studentlist2[sum1].set_math(newmath);
    Studentlist2[sum1].set_engl(newengl);
    Studentlist2[sum1].set_mxdx(newmxdx);
    sum1++;
}
void Studentlists::update1(int i,string newname, int newnum, string newsex, float newmath, float newengl, float newmxdx)//修改
{
    Studentlist2[i].set_name(newname);
    Studentlist2[i].set_num(newnum);
    Studentlist2[i].set_sex(newsex);
    Studentlist2[i].set_math(newmath);
    Studentlist2[i].set_engl(newengl);
    Studentlist2[i].set_mxdx(newmxdx);
}
void Studentlists::showstudent_title1()//输出
{
    cout<<setiosflags(ios::left)<<setw(15)<<"姓名"<<setiosflags(ios::left);
    cout<<setw(15)<<"学号"<<setiosflags(ios::left)<<setw(15)<<"性别";
    cout<<setiosflags(ios::left)<<setw(15)<<"数学";
    cout<<setiosflags(ios::left)<<setw(15)<<"英语";
    cout<<setiosflags(ios::left)<<setw(15)<<"c++";
    cout<<setiosflags(ios::left)<<setw(15)<<"总成绩";
    cout<<setiosflags(ios::left)<<setw(15)<<"平均成绩"<<endl;
}
float Studentlists::total1(const float math,const float engl,const float mxdx)
{
    return math+engl+mxdx;
}
float Studentlists::average(const float math,const float engl,const float mxdx)
{
    return (math+engl+mxdx)/3;
}
void Studentlists::deleted1(int i)//删除
{
    for(int j=i; j<sum1-1; j++)
    {
        Studentlist2[j].set_name(Studentlist2[j+1].get_name());
        Studentlist2[j].set_num(Studentlist2[j+1].get_num());
        Studentlist2[j].set_sex(Studentlist2[j+1].get_sex());
        Studentlist2[j].set_math(Studentlist2[j+1].get_math());
        Studentlist2[j].set_engl(Studentlist2[j+1].get_engl());
        Studentlist2[j].set_mxdx(Studentlist2[j+1].get_mxdx());
    }
    sum1--;
}
void Studentlists::showall1()//显示
{
    showstudent_title1();
    for(int i=0; i<sum1; i++)
        showstudent1(i);
    cout<<"共有学生"<<sum1<<"个"<<endl;
}
void Studentlists::showstudent1(int i)
{

    cout<<setiosflags(ios::left)<<setw(15)<<Studentlist2[i].get_name()<<setiosflags(ios::left);
    cout<<setw(15)<<Studentlist2[i].get_num()<<setw(15)<<setiosflags(ios::left);
    cout<<setw(15)<<Studentlist2[i].get_sex()<<setw(15)<<setiosflags(ios::left);
    cout<<setw(15)<<Studentlist2[i].get_math()<<setw(15);
    cout<<setiosflags(ios::left)<<Studentlist2[i].get_engl()<<setw(15);
    cout<<setiosflags(ios::left)<<Studentlist2[i].get_mxdx()<<setw(15);
    cout<<setiosflags(ios::left)<<total1(Studentlist2[i].get_math(),Studentlist2[i].get_engl(),Studentlist2[i].get_mxdx())<<setw(15);
    cout<<setiosflags(ios::left)<<average(Studentlist2[i].get_math(),Studentlist2[i].get_engl(),Studentlist2[i].get_mxdx())<<endl;
}
int Studentlists::search11(string name)
{
    int i;
    for(i=0; i<sum1; i++)
    {
        if(Studentlist2[i].get_name()==name)
            return i;
    }
    if(i==sum1)
        return -1;
}
ostream & operator<<(ostream &cout2,score&score2)
{
    cout2<<setiosflags(ios::left)<<setw(15)<<score2.get_name();
    cout2<<setw(15)<<score2.get_num()<<setw(15)<<score2.get_sex();
    cout2<<setw(15)<<score2.get_math()<<setw(15)<<score2.get_engl();
    cout2<<setw(15)<<score2.get_mxdx()<<endl;
    return cout2;
}
class Studentlist
{
    Students Studentlist1[100];//定义Students 类型的数组Studentlist1用来存储学生的信息
public:
    Studentlist();//构造函数
    int sum;//学生数量
    void readfile();//读取文件开始界面
    void writerfile();//存储数据到文件
    void insert1(const string newname,const int newnum,const string newsex,const int grade,const int class1,const string major);
    //添加学生信息
    void update(int i,string newname,int newnum, string newsex, int grade, int class1, string major);//修改
    void showstudent_title();//输出
    void deleted(int i);//删除
    void showall();//显示
    void showstudent(int i);//输出第i个学生的信息
    int search1(string name);//查询
};
Studentlist::Studentlist()
{
    sum=0;
}
int Systemdoor()//设置界面的用户名和密码
{
    string username = "ymz", password = "0000";
    string name, temp;
    int number = 3;
    while (1)
    {
        cout << "                用 户 名:";
        cin >> name;
        cout << "                密    码:";
        cin >> temp;
        if (name != username || temp != password)
        {
            number--;
            if (number >0)
            {
                cout << "          用户名/密码错误!你还有" << number << "次机会" << endl;
            }
            else
                cout << "用户名/密码错误!" << endl, exit(0);

        }
        else
        {
            cout << "\t\t********************密码正确********************" << endl;
            return 1;
        }
    }

}
void Studentlist::readfile()
{

    float pr,qw,bj;
    char temp[99],temp1[99],temp2[99];
    ifstream infile("Studentlist.txt");
    //定义文件指针infile指向booklist.txt
    if(!infile)
    {
        cerr<<"cannot open Studentlist.txt for output\n\n\n\n";
        return ;
    }
    while((infile>>temp))
    {
        infile>>pr;
        infile>>temp1;
        infile>>qw;
        infile>>bj;
        infile>>temp2;
        insert1(temp,pr,temp1,qw,bj,temp2);
    }
    //cout<<"从Studentlist.txt中读取已有学生如下:"<<endl;
    //showall();
    infile.close();
}
void Studentlist::writerfile()
{
    ofstream outfile("Studentlist.txt",ios::out);
    if(!outfile)
    {
        cerr<<"cannot open Studentlist.txt for output\n\n\n\n\n";
        exit(-1);
    }
    for(int i=0; i<sum; i++)
    {
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist1[i].get_name();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist1[i].get_num();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist1[i].get_sex();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist1[i].get_grade();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist1[i].get_class1();
        outfile<<setiosflags(ios::left)<<setw(15)<<Studentlist1[i].get_major()<<endl;
    }
    outfile.close();
}
void Studentlist::insert1(const string newname,const int newnum,const string newsex,const int grade,const int class1,const string major)
//添加学生信息
{
    Studentlist1[sum].set_name(newname);
    Studentlist1[sum].set_num(newnum);
    Studentlist1[sum].set_sex(newsex);
    Studentlist1[sum].set_grade(grade);
    Studentlist1[sum].set_class1(class1);
    Studentlist1[sum].set_major(major);
    sum++;
}
void Studentlist::update(int i,string newname,int newnum, string newsex, int grade, int class1, string major)//修改
{
    Studentlist1[i].set_name(newname);
    Studentlist1[i].set_num(newnum);
    Studentlist1[i].set_sex(newsex);
    Studentlist1[i].set_grade(grade);
    Studentlist1[i].set_class1(class1);
    Studentlist1[i].set_major(major);
}
void Studentlist::showstudent_title()//输出
{
    cout<<setiosflags(ios::left)<<setw(15)<<"姓名"<<setiosflags(ios::left);
    cout<<setw(15)<<"学号"<<setiosflags(ios::left)<<setw(15)<<"性别";
    cout<<setiosflags(ios::left)<<setw(15)<<"年级";
    cout<<setiosflags(ios::left)<<setw(15)<<"班级";
    cout<<setiosflags(ios::left)<<setw(15)<<"专业"<<endl;
}
void Studentlist::deleted(int i)//删除
{
    for(int j=i; j<sum-1; j++)
    {
        Studentlist1[j].set_name(Studentlist1[j+1].get_name());
        Studentlist1[j].set_num(Studentlist1[j+1].get_num());
        Studentlist1[j].set_sex(Studentlist1[j+1].get_sex());
        Studentlist1[j].set_grade(Studentlist1[j+1].get_grade());
        Studentlist1[j].set_class1(Studentlist1[j+1].get_class1());
        Studentlist1[j].set_major(Studentlist1[j+1].get_major());
    }
    sum--;
}
void Studentlist::showall()//显示
{
    showstudent_title();
    for(int i=0; i<sum; i++)
        showstudent(i);
    cout<<"共有学生"<<sum<<"个"<<endl;
}
void Studentlist::showstudent(int i)
{
cout<<setiosflags(ios::left)<<setw(15)<<Studentlist1[i].get_name()<<setiosflags(ios::left);
    cout<<setw(15)<<Studentlist1[i].get_num()<<setw(15)<<setiosflags(ios::left);
    cout<<setw(15)<<Studentlist1[i].get_sex()<<setw(15)<<setiosflags(ios::left);
    cout<<setw(15)<<Studentlist1[i].get_grade()<<setw(15);
    cout<<setiosflags(ios::left)<<Studentlist1[i].get_class1()<<setw(15);
    cout<<setiosflags(ios::left)<<Studentlist1[i].get_major()<<endl;
}
int Studentlist::search1(string name)
{
    int i;
    for(i=0; i<sum; i++)
    {
        if(Studentlist1[i].get_name()==name)
            return i;
    }
    if(i==sum)
        return -1;
}
ostream & operator<<(ostream &cout1,Students&Student2)
{
    cout1<<setiosflags(ios::left)<<setw(15)<<Student2.get_name();
    cout1<<setw(15)<<Student2.get_num()<<setw(15)<<Student2.get_sex();
    cout1<<setw(15)<<Student2.get_grade()<<setw(15)<<Student2.get_class1();
    cout1<<setw(15)<<Student2.get_major()<<endl;
    return cout1;
}
int main()
{
    system("color 2");//设置界面字体颜色
    Systemdoor();//调用界面的用户名和密码函数
    int flag=0;
    cout<<"\n\n\t\t****************************************************\n\n";
    cout<<"\t\t*****************请选择要进入的系统****************"<<endl<<endl;
    cout<<"\t\t****************************************************\n\n";
    cout<<"\t\t\t1.学生信息统计"<<"\t\t"<<"2.学生成绩统计"<<endl;
    cin>>flag;
    if(flag==1)
    {
        Studentlist s1;
        int pr,qw,bj;
        char temp[99],temp1[99],temp2[99];
        int f=1;
        cout<<"\t\t****************************************************\n";
        //cout<<"                                       \n\n";
        cout<<"\n\n\t\t\t     欢迎使用学生信息管理系统\n\n\n";
        //cout<<"                                        \n\n";
        cout<<"\t\t****************************************************\n\n";
        s1.readfile();
        while(f==1)
        {
            cout << "\n\t\t\t"<<"* 1.录入" << "\t\t" << "2.查询 *" << endl;
            cout <<"\n\t\t\t"<< "* 3.修改" << "\t\t" << "4.删除 *" << endl;
            cout << "\n\t\t\t"<<"* 5.显示" << "\t\t" << "        " << endl;
            cout << "\n\t\t\t"<<"* 6.退出" << "\t\t" << "        " << endl;
            cout<<"\t\t----------------------------------------------------\n\n";
            cout << "输入你想执行的操作:";
            cout << endl;
            int xz;
            cin>>xz;
            if(xz==1)
            {
                cout<<"请输入学生的姓名:";
                cin>>temp;
                cout<<"请输入学生的学号:";
                cin>>pr;
                cout<<"请输入学生的性别:";
                cin>>temp1;
                cout<<"请输入学生的年级:";
                cin>>qw;
                cout<<"请输入学生的班级:";
                cin>>bj;
                cout<<"请输入学生的专业:";
                cin>>temp2;
                s1.insert1(temp,pr,temp1,qw,bj,temp2);
                s1.showstudent_title();
                s1.showstudent(s1.sum-1);
            }
            if(xz==2)
            {
                cout<<"请要查找学生的姓名:";
                cin>>temp;
                int x=s1.search1(temp);
                if(x>=0)
                {
                    s1.showstudent(x);
                }
                else
                    cout<<"未找到该学生!"<<endl;
            }
            if(xz==3)
            {
                cout<<"请输入要修改学生的姓名:";
                cin>>temp;
                int y=s1.search1(temp);
                if(y>=0)
                {
                    cout<<"请输入要修改学生的姓名:";
                    cin>>temp;
                    cout<<"请输入要修改学生的学号:";
                    cin>>pr;
                    cout<<"请输入要修改学生的性别:";
                    cin>>temp1;
                    cout<<"请输入要修改学生的年级:";
                    cin>>qw;
                    cout<<"请输入要修改学生的班级:";
                    cin>>bj;
                    cout<<"请输入要修改学生的专业:";
                    cin>>temp2;
                    s1.update(y,temp,pr,temp1,qw,bj,temp2);
                    s1.showstudent_title();
                    s1.showstudent(y);
                }
                else
                    cout<<"未找到该学生!"<<endl;
            }
            if(xz==4)
            {
                cout<<"请输入要删除学生的姓名:";
                cin>>temp;
                int z=s1.search1(temp);
                if(z>=0)
                {
                    s1.deleted(z);
                    cout<<"删除成功!"<<endl;
                    cout<<"共有学生几个:"<<s1.sum<<endl;
                }
                else
                    cout<<"未找到该学生!"<<endl;
            }
            if(xz==5)
            {
                s1.readfile();
                s1.showall();
            }
            if(xz==6)
            {
                cout<<endl<<"\t\t*****************退出系统!*****************"<<endl;
                s1.writerfile();

                f=0;
            }

        }

    }
    if(flag==2)
    {
        Studentlists s2;
        int xh;
        float sx,yy,mx;
        char temp3[99],temp4[99];
        int f=1;
        cout<<"\t\t****************************************************\n";
        //cout<<"                                       \n\n";
        cout<<"\n\n\t\t\t     欢迎使用学生成绩管理系统\n\n\n";
        //cout<<"                                        \n\n";
        cout<<"\t\t****************************************************\n\n";
        s2.readfile1();
        while(f==1)
        {
            cout << "\n\t\t\t"<<"* 1.录入" << "\t\t" << "2.查询 *" << endl;
            cout <<"\n\t\t\t"<< "* 3.修改" << "\t\t" << "4.删除 *" << endl;
            cout << "\n\t\t\t"<<"* 5.显示" << "\t\t" << "        " << endl;
            cout << "\n\t\t\t"<<"* 6.退出" << "\t\t" << "        " << endl;
            cout<<"\t\t----------------------------------------------------\n\n";
            cout << "输入你想执行的操作:";
            cout << endl;
            int g;
            cin>>g;
            if(g==1)
            {
                cout<<"请输入学生的姓名:";
                cin>>temp3;
                cout<<"请输入学生的学号:";
                cin>>xh;
                cout<<"请输入学生的性别:";
                cin>>temp4;
                cout<<"请输入学生的数学:";
                cin>>sx;
                cout<<"请输入学生的英语:";
                cin>>yy;
                cout<<"请输入学生的c++:";
                cin>>mx;
                s2.insert11(temp3,xh,temp4,sx,yy,mx);
                s2.showstudent_title1();
                s2.showstudent1(s2.sum1-1);

            }
            if(g==2)
            {
                cout<<"请要查找学生的姓名:";
                cin>>temp3;
                int a=s2.search11(temp3);
                if(a>=0)
                {
                    s2.showstudent1(a);
                }
                else
                    cout<<"未找到该学生!"<<endl;
            }
            if(g==3)
            {
                cout<<"请输入要修改学生的姓名:";
                cin>>temp3;
                int b=s2.search11(temp3);
                if(b>=0)
                {
                    cout<<"请输入要修改学生的姓名:";
                    cin>>temp3;
                    cout<<"请输入要修改学生的学号:";
                    cin>>xh;
                    cout<<"请输入要修改学生的性别:";
                    cin>>temp4;
                    cout<<"请输入要修改学生的数学:";
                    cin>>sx;
                    cout<<"请输入要修改学生的英语:";
                    cin>>yy;
                    cout<<"请输入要修改学生的c++:";
                    cin>>mx;
                    s2.update1(b,temp3,xh,temp4,sx,yy,mx);
                    s2.showstudent_title1();
                    s2.showstudent1(b);
                }
                else
                    cout<<"未找到该学生!"<<endl;
            }
            if(g==4)
            {
                cout<<"请输入要删除学生的姓名:";
                cin>>temp3;
                int c=s2.search11(temp3);
                if(c>=0)
                {
                    s2.deleted1(c);
                    cout<<"删除成功!"<<endl;
                    cout<<"共有学生几个:"<<s2.sum1<<endl;
                }
                else
                    cout<<"未找到该学生!"<<endl;
            }
            if(g==5)
            {
                s2.readfile1();
                s2.showall1();
            }
            if(g==6)
            {
                cout<<endl<<"\t\t*****************退出系统!*****************"<<endl;
                s2.writerfile1();
                f=0;
            }

        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值