博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++课程设计
阅读量:4286 次
发布时间:2019-05-27

本文共 8235 字,大约阅读时间需要 27 分钟。

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;class Student{//基类 Student  public:  Student(int Number , string Name , string Sex ,int Age , string Phone);  Student(){}  ~Student(){}//  virtual void Display(){}  protected:  int number;  string name;  string sex;  int age;  string phone;};Student::Student(int Number , string Name , string Sex , int Age ,string Phone){ number = Number; age = Age; sex = Sex; name = Name; phone = Phone;}class UStudent:public Student{//大学生    public:      UStudent(int Number , string Name , string Sex , int Age ,string Phone):Student(Number , Name , Sex , Age , Phone){}      UStudent(){}      ~UStudent(){}      UStudent *next;      friend ostream& operator<<(ostream& , const UStudent&);      friend istream& operator>>(istream& , UStudent&);      friend class StuMCtrol;};//操作符<< >> 的重载ostream& operator<<(ostream& output , const UStudent& t){    output<
<
<
<
<
<
<
<
<
<
<
<
>(istream& input , UStudent& t){    cout<<"                     请输入学生学号:     ";input>>t.number;    cout<<"                     请输入学生姓名:     ";input>>t.name;    cout<<"                     请输入学生性别:     ";input>>t.sex;    cout<<"                     请输入学生年龄:     ";input>>t.age;    cout<<"                     请输入学生电话:     ";input>>t.phone;    return input;}class StuMCtrol{//操作学生信息    public:      StuMCtrol()      {          Sp=NULL;          ReadFile();      }      ~StuMCtrol();      void UStudentMenu();      void NewBuild();      void Add();      void Search();      void Modify();      void Del();      void Display();      void Save();  void Sortt();      void ReadFile();    private:      UStudent *Sp;};void ShoWStudentM(){    cout<<"                                    学生通讯录"<
<
>*s;        s->next = Sp;        Sp = s;        Save();}void StuMCtrol::Add()//添加信息{    cout<
<
<<"            请输入添加信息"<
<
>*s;    s->next = Sp;    Sp = s;    Save();}void StuMCtrol::Del()//删除信息{    int alt=1;    char x;    while(1)    {        system("cls");cout<
<
<
>Endnumber;    }    if(alt==2)    {          cout<
<<"          请输入姓名:   ";          cin>>Endname;    }    if(alt==3)    {          cout<
<<"          请输入电话:   ";          cin>>Endphone;    }    UStudent *p1 = Sp;    UStudent *p2 = p1;    while(p1)    {        if(alt==1&&p1->number==Endnumber)        {            loop=1;            break;        }        if(alt==2&&p1->name==Endname)        {            loop=1;            break;        }        if(alt==3&&p1->phone==Endphone)        {            loop=1;            break;        }        p2 = p1;        p1 = p1->next;    }    if(loop==0)    {        cout<<"不存在!请重新删除\n\n";        Del();    }    else    {        if(p1 == Sp)        {            Sp = Sp->next;            delete p1;        }        else        {            p2->next = p1->next;            delete p1;        }        cout<<"删除成功";        Save();    }    system("pause\n");}void StuMCtrol::Modify()//修改信息{    int alt=1;    char x;    while(1)    {        system("cls");        cout<
<
<
>Endnumber;      }    if(alt==2)      {          cout<
<<"          请输入姓名:   ";          cin>>Endname;      }      if(alt==3)      {          cout<
<<"          请输入电话:   ";          cin>>Endname;      }    UStudent *p1 = Sp;    while(p1)    {        if(alt==1&&p1->number==Endnumber)        {            loop=1;            break;        }        if(alt==2&&p1->name==Endname)        {            loop=1;            break;        }        if(alt==3&&p1->phone==Endphone)        {            loop=1;            break;        }        p1 = p1->next;    }    if(loop==0)    {        cout<<"不存在!请重新修改\n"<
>*p1;        Save();    }    system("pause\n");}void StuMCtrol::Display()//显示信息{    ShoWStudentM();    UStudent *p1 = Sp;    while(p1)    {        cout<<*p1;        p1=p1->next;    }    system("pause\n");}void StuMCtrol::Search()//查找信息{    int alt=1;    char x;    while(1)    {        system("cls");cout<
<
<
>Endnumber;      }    if(alt==2)      {          cout<
<<"          请输入姓名:   ";          cin>>Endname;      }      if(alt==3)      {          cout<<"           请输入姓名:   ";          cin>>Endphone;      }    UStudent *p1 = Sp;    while(p1)    {        if(alt==1&&p1->number==Endnumber)        {            ShoWStudentM();            cout<<*p1;            loop=1;            break;        }        if(alt==2&&p1->name==Endname)        {            ShoWStudentM();            cout<<*p1;            loop=1;            break;        }        if(alt==3&&p1->phone==Endphone)        {            ShoWStudentM();            cout<<*p1;            loop=1;            break;        }        p1 = p1->next;    }    if(loop==0)    {        cout<<"不存在!请重新查找\n"<
next)    n++;    Head->next = Sp;    for(i=1;i
next;            q = p->next;            if(p->number > q->number)            {                loop->next=q;                p->next = q->next;                q->next = p;            }            loop = loop->next;        }    }    Sp=Head->next;    delete Head; cout<<"             **********排序成功!!!***********"<
number<<" ";        outfile<
name<<" ";        outfile<
sex<<" ";        outfile<
age<<" ";        outfile<
phone<<""<
next;    }    cout<<"保存文件成功"<
next;        delete p1;        p1 = Sp;    }}void StuMCtrol::ReadFile()//读取文件{    Sp = NULL;    ifstream infile("D:\\UStudent.txt",ios::in);    int number;    string name;    string sex;    int age;    string phone;    while(infile)    {        infile>>number>>name>>sex>>age>>phone;        if(!infile) continue;        UStudent *p = new UStudent(number,name,sex,age,phone);        p->next = Sp;        Sp = p;        cout<<"载入中 …………!!\n";    }    infile.close();    system("pause\n");}void StuMCtrol::UStudentMenu()  //菜单函数{    int alt=1;    char x,y;    while(1)    {        system("cls");//清屏!!        cout<
<
#include
#include
#include
#include
#include
#include
#include
using namespace std;class Student{//基类 Student  public:  Student(int Number , string Name , string Sex ,int Age , string Phone);  Student(){}  ~Student(){}//  virtual void Display(){}  protected:  int number;  string name;  string sex;  int age;  string phone;};Student::Student(int Number , string Name , string Sex , int Age ,string Phone){ number = Number; age = Age; sex = Sex; name = Name; phone = Phone;}class UStudent:public Student{//大学生    public:      UStudent(int Number , string Name , string Sex , int Age ,string Phone):Student(Number , Name , Sex , Age , Phone){}      UStudent(){}      ~UStudent(){}      UStudent *next;      friend ostream& operator<<(ostream& , const UStudent&);      friend istream& operator>>(istream& , UStudent&);      friend class StuMCtrol;};//操作符<< >> 的重载ostream& operator<<(ostream& output , const UStudent& t){    output<
<
<
<
<
<
<
<
<
<
<
<
>(istream& input , UStudent& t){    cout<<"                     请输入学生学号:     ";input>>t.number;    cout<<"                     请输入学生姓名:     ";input>>t.name;    cout<<"                     请输入学生性别:     ";input>>t.sex;    cout<<"                     请输入学生年龄:     ";input>>t.age;    cout<<"                     请输入学生电话:     ";input>>t.phone;    return input;}class StuMCtrol{//操作学生信息    public:      StuMCtrol()      {          Sp=NULL;          ReadFile();      }      ~StuMCtrol();      void UStudentMenu();      void NewBuild();      void Add();      void Search();      void Modify();      void Del();      void Display();      void Save();  void Sortt();      void ReadFile();    private:      UStudent *Sp;};void ShoWStudentM(){    cout<<"                                    学生通讯录"<
<
>*s;        s->next = Sp;        Sp = s;        Save();}void StuMCtrol::Add()//添加信息{    cout<
<
<<"            请输入添加信息"<
<
>*s;    s->next = Sp;    Sp = s;    Save();}void StuMCtrol::Del()//删除信息{    int alt=1;    char x;    while(1)    {        system("cls");cout<
<
<
>Endnumber;    }    if(alt==2)    {          cout<
<<"          请输入姓名:   ";          cin>>Endname;    }    if(alt==3)    {          cout<
<<"          请输入电话:   ";          cin>>Endphone;    }    UStudent *p1 = Sp;    UStudent *p2 = p1;    while(p1)    {        if(alt==1&&p1->number==Endnumber)        {            loop=1;            break;        }        if(alt==2&&p1->name==Endname)        {            loop=1;            break;        }        if(alt==3&&p1->phone==Endphone)        {            loop=1;            break;        }        p2 = p1;        p1 = p1->next;    }    if(loop==0)    {        cout<<"不存在!请重新删除\n\n";        Del();    }    else    {        if(p1 == Sp)        {            Sp = Sp->next;            delete p1;        }        else        {            p2->next = p1->next;            delete p1;        }        cout<<"删除成功";        Save();    }    system("pause\n");}void StuMCtrol::Modify()//修改信息{    int alt=1;    char x;    while(1)    {        system("cls");        cout<
<
<
>Endnumber;      }    if(alt==2)      {          cout<
<<"          请输入姓名:   ";          cin>>Endname;      }      if(alt==3)      {          cout<
<<"          请输入电话:   ";          cin>>Endname;      }    UStudent *p1 = Sp;    while(p1)    {        if(alt==1&&p1->number==Endnumber)        {            loop=1;            break;        }        if(alt==2&&p1->name==Endname)        {            loop=1;            break;        }        if(alt==3&&p1->phone==Endphone)        {            loop=1;            break;        }        p1 = p1->next;    }    if(loop==0)    {        cout<<"不存在!请重新修改\n"<
>*p1;        Save();    }    system("pause\n");}void StuMCtrol::Display()//显示信息{    ShoWStudentM();    UStudent *p1 = Sp;    while(p1)    {        cout<<*p1;        p1=p1->next;    }    system("pause\n");}void StuMCtrol::Search()//查找信息{    int alt=1;    char x;    while(1)    {        system("cls");cout<
<
<
>Endnumber;      }    if(alt==2)      {          cout<
<<"          请输入姓名:   ";          cin>>Endname;      }      if(alt==3)      {          cout<<"           请输入姓名:   ";          cin>>Endphone;      }    UStudent *p1 = Sp;    while(p1)    {        if(alt==1&&p1->number==Endnumber)        {            ShoWStudentM();            cout<<*p1;            loop=1;            break;        }        if(alt==2&&p1->name==Endname)        {            ShoWStudentM();            cout<<*p1;            loop=1;            break;        }        if(alt==3&&p1->phone==Endphone)        {            ShoWStudentM();            cout<<*p1;            loop=1;            break;        }        p1 = p1->next;    }    if(loop==0)    {        cout<<"不存在!请重新查找\n"<
next)    n++;    Head->next = Sp;    for(i=1;i
next;            q = p->next;            if(p->number > q->number)            {                loop->next=q;                p->next = q->next;                q->next = p;            }            loop = loop->next;        }    }    Sp=Head->next;    delete Head; cout<<"             **********排序成功!!!***********"<
number<<" ";        outfile<
name<<" ";        outfile<
sex<<" ";        outfile<
age<<" ";        outfile<
phone<<""<
next;    }    cout<<"保存文件成功"<
next;        delete p1;        p1 = Sp;    }}void StuMCtrol::ReadFile()//读取文件{    Sp = NULL;    ifstream infile("D:\\UStudent.txt",ios::in);    int number;    string name;    string sex;    int age;    string phone;    while(infile)    {        infile>>number>>name>>sex>>age>>phone;        if(!infile) continue;        UStudent *p = new UStudent(number,name,sex,age,phone);        p->next = Sp;        Sp = p;        cout<<"载入中 …………!!\n";    }    infile.close();    system("pause\n");}void StuMCtrol::UStudentMenu()  //菜单函数{    int alt=1;    char x,y;    while(1)    {        system("cls");//清屏!!        cout<
<

转载地址:http://wysgi.baihongyu.com/

你可能感兴趣的文章