c++课程设计
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<fstream>
#include<iomanip>
#include<windows.h>
#include<conio.h>
using namespace std;class Student{//基類 Studentpublic:
?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{//大學(xué)生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<<setiosflags(ios::right)<<setw(20)<<t.number<<setw(12)<<t.name<<setw(11)<<t.sex<<setw(15)<<t.age<<setw(15)<<t.phone<<endl;return output;
}//setiosflags(ios::left)數(shù)據(jù)按域?qū)捵髮R
istream& operator>>(istream& input , UStudent& t)
{cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生學(xué)號: ? ? ";input>>t.number;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生姓名: ? ? ";input>>t.name;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生性別: ? ? ";input>>t.sex;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生年齡: ? ? ";input>>t.age;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生電話: ? ? ";input>>t.phone;return input;
}
class StuMCtrol{//操作學(xué)生信息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<<" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?學(xué)生通訊錄"<<endl<<endl;cout<<" ? ? ? ? ? ? ? "<<"學(xué)號"<<" ? ? ? ?"<<"姓名"<<" ? ? ? ?"<<"性別"<<" ? ? ? ? ? "<<"年齡"<<" ? ? ? ?"<<"電話"<<endl<<endl;
}
void StuMCtrol::NewBuild()//新建信息
{cout<<endl<<endl<<" ? ? ? ? ? "<<"請輸入新建信息:"<<endl<<endl<<endl;Sp=NULL;UStudent *s = new UStudent;cin>>*s;s->next = Sp;Sp = s;Save();
}
void StuMCtrol::Add()//添加信息
{cout<<endl<<endl<<" ? ? ? ? ? ?請輸入添加信息"<<endl<<endl;UStudent *s = new UStudent;cin>>*s;s->next = Sp;Sp = s;Save();
}
void StuMCtrol::Del()//刪除信息
{int alt=1;char x;while(1){system("cls");cout<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 刪除方式 **********\n";if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ? *\n";if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 姓名 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 姓名 ? ? ? ? ? *\n";if(alt==3)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 3 : 電話 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 3 : 電話 ? ? ? ? ? *\n";if(alt==4)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 4 : 退出 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 4 : 退出 ? ? ? ? ? *\n";cout<<" ? ? ? ? ?**********************************\n";x=getch();if(x == 'u'){if(alt == 1) alt = 4;else alt -- ;}if(x == 'd'){if( alt == 4) alt=1;else alt ++ ;}if(x=='p') break;}int Endnumber,loop=0;string Endname,Endphone;if(alt==4) return ;if(alt==1){cout<<endl<<" ? ? ? ? ?請輸入學(xué)號: ? ";cin>>Endnumber;}if(alt==2){cout<<endl<<" ? ? ? ? ?請輸入姓名: ? ";cin>>Endname;}if(alt==3){cout<<endl<<" ? ? ? ? ?請輸入電話: ? ";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<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 修改方式 **********\n";if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ? *"<<endl;if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 姓名 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 姓名 ? ? ? ? ? *"<<endl;if(alt==3)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 3 : 電話 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 3 : 電話 ? ? ? ? ? *"<<endl;if(alt==4)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 4 : 退出 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 4 : 退出 ? ? ? ? ? *"<<endl;cout<<" ? ? ? ? ?**********************************"<<endl;x=getch();if(x == 'u'){if(alt == 1) alt = 4;else alt -- ;}if(x == 'd'){if( alt == 4) alt=1;else alt ++ ;}if(x=='p') break;}int Endnumber,loop=0;string Endname,Endphone;if(alt==4) return ;if(alt==1){cout<<endl<<" ? ? ? ? ?請輸入學(xué)號: ? ";cin>>Endnumber;}if(alt==2){cout<<endl<<" ? ? ? ? ?請輸入姓名: ? ";cin>>Endname;}if(alt==3){cout<<endl<<" ? ? ? ? ?請輸入電話: ? ";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"<<endl;Modify();}else{cout<<endl<<" ? ? ? ? ? 請輸入新的信息: ? ?"<<endl;cin>>*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<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 查找方式 **********"<<endl;if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ? *"<<endl;if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 姓名 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 姓名 ? ? ? ? ? *"<<endl;if(alt==3)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 3 : 電話 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 3 : 電話 ? ? ? ? ? *"<<endl;if(alt==4)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 4 : 退出 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 4 : 退出 ? ? ? ? ? *"<<endl;cout<<" ? ? ? ? ?**********************************"<<endl;x=getch();if(x == 'u'){if(alt == 1) alt = 4;else alt -- ;}if(x == 'd'){if( alt == 4) alt=1;else alt ++ ;}if(x=='p') break;}int Endnumber,loop=0;string Endname,Endphone;if(alt==4) return ;if(alt==1){cout<<endl<<" ? ? ? ? ?請輸入學(xué)號: ? ";cin>>Endnumber;}if(alt==2){cout<<endl<<" ? ? ? ? ?請輸入姓名: ? ";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"<<endl;Search();}system("pause\n");
}
void StuMCtrol::Sortt()//排序
{
int alt=1;char x;while(1){system("cls");cout<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 排序方式 **********"<<endl;if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ?*"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ?*"<<endl;if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 退出 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 退出 ? ? ? ? ? *"<<endl;cout<<" ? ? ? ? ?**********************************"<<endl;x=getch();if(x == 'u'){if(alt == 1) alt = 2;else alt -- ;}if(x == 'd'){if( alt == 2) alt=1;else alt ++ ;}if(x=='p') break;}if(alt==2) return ;
UStudent *p,*q;
UStudent *loop;
UStudent *Head = new UStudent;
int i,j,n=0;
for(loop = Sp ; loop ; loop = loop->next)
? ?n++;Head->next = Sp;for(i=1;i<n;i++){loop = Head;for(j=1;j<=n-i;j++){p = loop->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<<" ? ? ? ? ? ? **********排序成功!!!***********"<<endl;
Save();
}
void StuMCtrol::Save()//保存信息
{UStudent *p1 = Sp;ofstream outfile("D:\\UStudent.txt",ios::out);while(p1){cout<<"正在保存!!"<<endl;outfile<<p1->number<<" ";outfile<<p1->name<<" ";outfile<<p1->sex<<" ";outfile<<p1->age<<" ";outfile<<p1->phone<<""<<endl;p1 = p1->next;}cout<<"保存文件成功"<<endl;outfile.close();system("pause\n");
}
StuMCtrol::~StuMCtrol()//析構(gòu)函數(shù)
{UStudent *p1 = Sp;while(p1){Sp = Sp->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() ?//菜單函數(shù)
{int alt=1;char x,y;while(1){system("cls");//清屏!!cout<<endl<<endl;cout<<" ? ? ? ? ? ? ? ? ★★★★★ C++課程設(shè)計(jì) ★★★★★ ? \n"<<endl;cout<<" ? ? ? ? ?※※※※※※※ 大學(xué)生通訊錄管理系統(tǒng) ※※※※※※\n";if(alt==1)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 1 : 新建 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?1 : 新建 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==2)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 2 : 添加 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?2 : 添加 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==3)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 3 : 查找 ? ? ? ? u:上 ? ? ? ? ※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?3 : 查找 ? ? ? ? u:上 ? ? ? ? ※\n";if(alt==4)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 4 : 修改 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?4 : 修改 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==5)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 5 : 刪除 ? ? ? ? d:下 ? ? ? ? ※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?5 : 刪除 ? ? ? ? d:下 ? ? ? ? ※\n";if(alt==6)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 6 : 顯示 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?6 : 顯示 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==7)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 7 : 保存 ? ? ? ? p:確認(rèn) ? ? ? ※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?7 : 保存 ? ? ? ? p:確認(rèn) ? ? ? ※\n";if(alt==8)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 8 : 排序 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?8 : 排序 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==9)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 9 : 退出系統(tǒng) ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?9 : 退出系統(tǒng) ? ? ? ? ? ? ? ? ?※\n";cout<<" ? ? ? ? ?※※※※※※※※※※※※※※※※※※※※※※※※\n"<<endl;x = getch();if(x == 'u'){if(alt == 1) alt = 9;else alt -- ;}if(x == 'd'){if( alt == 9) alt=1;else alt ++ ;}if(x=='p') break;}system("cls");switch(alt){case 1: NewBuild();UStudentMenu();break;case 2: Add();UStudentMenu();break;case 3: Search();UStudentMenu();break;case 4: Modify();UStudentMenu();break;case 5: Del();UStudentMenu();break;case 6: Display();UStudentMenu();break;case 7: Save();UStudentMenu();break;case 8: Sortt();UStudentMenu();break;case 9: exit(0);default: cout<<"此輸入不合法,請重新輸入..."<<endl;Sleep(1000);UStudentMenu();;}
}
int main()
{system("color CE");StuMCtrol a;a.UStudentMenu();
}#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<fstream>
#include<iomanip>
#include<windows.h>
#include<conio.h>
using namespace std;class Student{//基類 Studentpublic:
?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{//大學(xué)生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<<setiosflags(ios::right)<<setw(20)<<t.number<<setw(12)<<t.name<<setw(11)<<t.sex<<setw(15)<<t.age<<setw(15)<<t.phone<<endl;return output;
}//setiosflags(ios::left)數(shù)據(jù)按域?qū)捵髮R
istream& operator>>(istream& input , UStudent& t)
{cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生學(xué)號: ? ? ";input>>t.number;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生姓名: ? ? ";input>>t.name;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生性別: ? ? ";input>>t.sex;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生年齡: ? ? ";input>>t.age;cout<<" ? ? ? ? ? ? ? ? ? ? 請輸入學(xué)生電話: ? ? ";input>>t.phone;return input;
}
class StuMCtrol{//操作學(xué)生信息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<<" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?學(xué)生通訊錄"<<endl<<endl;cout<<" ? ? ? ? ? ? ? "<<"學(xué)號"<<" ? ? ? ?"<<"姓名"<<" ? ? ? ?"<<"性別"<<" ? ? ? ? ? "<<"年齡"<<" ? ? ? ?"<<"電話"<<endl<<endl;
}
void StuMCtrol::NewBuild()//新建信息
{cout<<endl<<endl<<" ? ? ? ? ? "<<"請輸入新建信息:"<<endl<<endl<<endl;Sp=NULL;UStudent *s = new UStudent;cin>>*s;s->next = Sp;Sp = s;Save();
}
void StuMCtrol::Add()//添加信息
{cout<<endl<<endl<<" ? ? ? ? ? ?請輸入添加信息"<<endl<<endl;UStudent *s = new UStudent;cin>>*s;s->next = Sp;Sp = s;Save();
}
void StuMCtrol::Del()//刪除信息
{int alt=1;char x;while(1){system("cls");cout<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 刪除方式 **********\n";if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ? *\n";if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 姓名 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 姓名 ? ? ? ? ? *\n";if(alt==3)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 3 : 電話 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 3 : 電話 ? ? ? ? ? *\n";if(alt==4)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 4 : 退出 ? ? ? ? ? *\n";elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 4 : 退出 ? ? ? ? ? *\n";cout<<" ? ? ? ? ?**********************************\n";x=getch();if(x == 'u'){if(alt == 1) alt = 4;else alt -- ;}if(x == 'd'){if( alt == 4) alt=1;else alt ++ ;}if(x=='p') break;}int Endnumber,loop=0;string Endname,Endphone;if(alt==4) return ;if(alt==1){cout<<endl<<" ? ? ? ? ?請輸入學(xué)號: ? ";cin>>Endnumber;}if(alt==2){cout<<endl<<" ? ? ? ? ?請輸入姓名: ? ";cin>>Endname;}if(alt==3){cout<<endl<<" ? ? ? ? ?請輸入電話: ? ";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<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 修改方式 **********\n";if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ? *"<<endl;if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 姓名 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 姓名 ? ? ? ? ? *"<<endl;if(alt==3)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 3 : 電話 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 3 : 電話 ? ? ? ? ? *"<<endl;if(alt==4)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 4 : 退出 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 4 : 退出 ? ? ? ? ? *"<<endl;cout<<" ? ? ? ? ?**********************************"<<endl;x=getch();if(x == 'u'){if(alt == 1) alt = 4;else alt -- ;}if(x == 'd'){if( alt == 4) alt=1;else alt ++ ;}if(x=='p') break;}int Endnumber,loop=0;string Endname,Endphone;if(alt==4) return ;if(alt==1){cout<<endl<<" ? ? ? ? ?請輸入學(xué)號: ? ";cin>>Endnumber;}if(alt==2){cout<<endl<<" ? ? ? ? ?請輸入姓名: ? ";cin>>Endname;}if(alt==3){cout<<endl<<" ? ? ? ? ?請輸入電話: ? ";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"<<endl;Modify();}else{cout<<endl<<" ? ? ? ? ? 請輸入新的信息: ? ?"<<endl;cin>>*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<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 查找方式 **********"<<endl;if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ? *"<<endl;if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 姓名 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 姓名 ? ? ? ? ? *"<<endl;if(alt==3)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 3 : 電話 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 3 : 電話 ? ? ? ? ? *"<<endl;if(alt==4)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 4 : 退出 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 4 : 退出 ? ? ? ? ? *"<<endl;cout<<" ? ? ? ? ?**********************************"<<endl;x=getch();if(x == 'u'){if(alt == 1) alt = 4;else alt -- ;}if(x == 'd'){if( alt == 4) alt=1;else alt ++ ;}if(x=='p') break;}int Endnumber,loop=0;string Endname,Endphone;if(alt==4) return ;if(alt==1){cout<<endl<<" ? ? ? ? ?請輸入學(xué)號: ? ";cin>>Endnumber;}if(alt==2){cout<<endl<<" ? ? ? ? ?請輸入姓名: ? ";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"<<endl;Search();}system("pause\n");
}
void StuMCtrol::Sortt()//排序
{
int alt=1;char x;while(1){system("cls");cout<<endl<<endl<<endl;cout<<" ? ? ? ? ?************** 排序方式 **********"<<endl;if(alt==1)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 1 : 學(xué)號 ? ? ? ? ?*"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 1 : 學(xué)號 ? ? ? ? ?*"<<endl;if(alt==2)cout<<" ? ? ? ? ?* ? ? ? ? ?√ 2 : 退出 ? ? ? ? ? *"<<endl;elsecout<<" ? ? ? ? ?* ? ? ? ? ? ? 2 : 退出 ? ? ? ? ? *"<<endl;cout<<" ? ? ? ? ?**********************************"<<endl;x=getch();if(x == 'u'){if(alt == 1) alt = 2;else alt -- ;}if(x == 'd'){if( alt == 2) alt=1;else alt ++ ;}if(x=='p') break;}if(alt==2) return ;
UStudent *p,*q;
UStudent *loop;
UStudent *Head = new UStudent;
int i,j,n=0;
for(loop = Sp ; loop ; loop = loop->next)
? ?n++;Head->next = Sp;for(i=1;i<n;i++){loop = Head;for(j=1;j<=n-i;j++){p = loop->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<<" ? ? ? ? ? ? **********排序成功!!!***********"<<endl;
Save();
}
void StuMCtrol::Save()//保存信息
{UStudent *p1 = Sp;ofstream outfile("D:\\UStudent.txt",ios::out);while(p1){cout<<"正在保存!!"<<endl;outfile<<p1->number<<" ";outfile<<p1->name<<" ";outfile<<p1->sex<<" ";outfile<<p1->age<<" ";outfile<<p1->phone<<""<<endl;p1 = p1->next;}cout<<"保存文件成功"<<endl;outfile.close();system("pause\n");
}
StuMCtrol::~StuMCtrol()//析構(gòu)函數(shù)
{UStudent *p1 = Sp;while(p1){Sp = Sp->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() ?//菜單函數(shù)
{int alt=1;char x,y;while(1){system("cls");//清屏!!cout<<endl<<endl;cout<<" ? ? ? ? ? ? ? ? ★★★★★ C++課程設(shè)計(jì) ★★★★★ ? \n"<<endl;cout<<" ? ? ? ? ?※※※※※※※ 大學(xué)生通訊錄管理系統(tǒng) ※※※※※※\n";if(alt==1)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 1 : 新建 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?1 : 新建 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==2)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 2 : 添加 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?2 : 添加 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==3)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 3 : 查找 ? ? ? ? u:上 ? ? ? ? ※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?3 : 查找 ? ? ? ? u:上 ? ? ? ? ※\n";if(alt==4)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 4 : 修改 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?4 : 修改 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==5)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 5 : 刪除 ? ? ? ? d:下 ? ? ? ? ※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?5 : 刪除 ? ? ? ? d:下 ? ? ? ? ※\n";if(alt==6)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 6 : 顯示 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?6 : 顯示 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==7)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 7 : 保存 ? ? ? ? p:確認(rèn) ? ? ? ※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?7 : 保存 ? ? ? ? p:確認(rèn) ? ? ? ※\n";if(alt==8)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 8 : 排序 ? ? ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?8 : 排序 ? ? ? ? ? ? ? ? ? ? ?※\n";if(alt==9)cout<<" ? ? ? ? ?※ ? ? ? ? ? √ 9 : 退出系統(tǒng) ? ? ? ? ? ? ? ? ?※\n";elsecout<<" ? ? ? ? ?※ ? ? ? ? ? ? ?9 : 退出系統(tǒng) ? ? ? ? ? ? ? ? ?※\n";cout<<" ? ? ? ? ?※※※※※※※※※※※※※※※※※※※※※※※※\n"<<endl;x = getch();if(x == 'u'){if(alt == 1) alt = 9;else alt -- ;}if(x == 'd'){if( alt == 9) alt=1;else alt ++ ;}if(x=='p') break;}system("cls");switch(alt){case 1: NewBuild();UStudentMenu();break;case 2: Add();UStudentMenu();break;case 3: Search();UStudentMenu();break;case 4: Modify();UStudentMenu();break;case 5: Del();UStudentMenu();break;case 6: Display();UStudentMenu();break;case 7: Save();UStudentMenu();break;case 8: Sortt();UStudentMenu();break;case 9: exit(0);default: cout<<"此輸入不合法,請重新輸入..."<<endl;Sleep(1000);UStudentMenu();;}
}
int main()
{system("color CE");StuMCtrol a;a.UStudentMenu();
}
總結(jié)
- 上一篇: Ant-Design-Vue和Icon按
- 下一篇: centos7限制普通用户访问单一目录下