回忆是最好的记忆--简单管理系统
2016-08-10 06:49
141 查看
从简单通讯录说起:还是先摆源码吧.
整体结构文件addressbook.h
功能函数文件:addressbook.h
程序的主体思想:
利用宏变量控制的数组作为存储结构,以简单的for循环作为主要的循环遍历。
思考:
1.相应的算法是依据相应的存储结构而设计的;
2.对于程序中信息的属性,也应像splserver中的属性那样都有相应的形式存储;
3.对于信息的输出,深入一点可以利用execl或者word进行保存或者显示(我知道c#可以做到这一点);
4.这是c++面向对象的一个简单的 程序设计;
5.像提交表单那样,具有非法输入的判断这是依据2的产生的相应判断算法。
下一个当我学到了数据结构的时候用链表做了一个简单的系统:
基本函数文件algorithm.h:
思考:
1.面对程序中元素的查找,我们再深化一些可以实现sqlserver中的模糊查询;
2.对于元素的保存可以利用记事本的进行简单的保存即文件的输出输出;
3.还实现了对输出元素属性的判断,但是对于汉字的判断以及处理还需在进行掌握;
补上base.h的文件:
再贴一些简单的模板(可以进行大量的修改):
学生成绩管理:
stdmark.h:
简单的管理类小系统可以体现出很多的知识,对于其中的不足点,都发展成为了相应的技术。
对于此类系统的学习,应对sqlserver进行参照。
整体结构文件addressbook.h
#pragma once #include<iostream> #include<string> #define N 100 using namespace std; struct Student { string name;//编号、姓名、性别、年龄、宅电、手机电话 char number[20]; char sexual; int age; string hometele; char cellphone[20]; }; class addressbook { public: addressbook(void); ~addressbook(void); void showMenu();//显示目录 void Insert();//添加 int getChoice();//输入选择 void Outinfor();//信息的显示 void Quit();//退出 void Inquery();//查询 void doDelete();//删除 void Choice(int ch); void Found(int v);//创建 void Update();//修改 private: int nopeople;/人数的/计数 Student Volume ;//保存每个实体化的学生对象 };
功能函数文件:addressbook.h
#include "addressbook.h" addressbook::addressbook(void) { } addressbook::~addressbook(void) { } void addressbook::showMenu()//本函数主要是为了美观显示其中cls(cmd命令)的位置很关键 { cout<<"\t\t==简单通讯录系统=="<<endl; system("cls"); cout<<"\t\t请选择下面的一个项目:"<<endl; cout<<"\t\t1 创建"<<endl; cout<<"\t\t2 添加"<<endl; cout<<"\t\t3 查询"<<endl; cout<<"\t\t4 修改"<<endl; cout<<"\t\t5 删除"<<endl; cout<<"\t\t6 显示"<<endl; cout<<"\t\t7 退出"<<endl; cout<<"\t\t请选择:"<<endl; } void addressbook::Found(int v)//简单的for循环实现通讯录的建立功能 { cout<<"通讯录初始化!!"<<endl; for(nopeople=0;nopeople<v;nopeople++) { cout<<"输入第"<<nopeople+1<<"个学生的信息:"<<endl; cout<<"输入学生的编号:"<<endl; cin>>Volume[nopeople].number; cout<<"输入学生的姓名:"<<endl; cin>>Volume[nopeople].name; cout<<"输入学生的性别:"<<endl; cin>>Volume[nopeople].sexual; cout<<"输入学生的年龄:"<<endl; cin>>Volume[nopeople].age; cout<<"输入学生的宅电:"<<endl; cin>>Volume[nopeople].hometele; cout<<"输入学生的手机电话:"<<endl; cin>>Volume[nopeople].cellphone; } } void addressbook::Insert()//插入,nopeople实现人数的计数 { cout<<"输入你要插入学生的信息:"<<endl; cout<<"输入学生的编号:"<<endl; cin>>Volume[nopeople].number; cout<<"输入学生的姓名:"<<endl; cin>>Volume[nopeople].name; cout<<"输入学生的性别:"<<endl; cin>>Volume[nopeople].sexual; cout<<"输入学生的年龄:"<<endl; cin>>Volume[nopeople].age; cout<<"输入学生的宅电:"<<endl; cin>>Volume[nopeople].hometele; cout<<"输入学生的手机电话:"<<endl; cin>>Volume[nopeople].cellphone; nopeople++; } void addressbook::Inquery()//查询算法--这是值得深思的地方:效率、代码的美观程度 { int ch; char Tennum[20];//手机号 char Num[20];//编号 string Name;//姓名 int find=0; cout<<"\t\t请输入你要查询的方式:"<<endl; cout<<"\t\t1 按手机号查询2 按姓名查询3 按编号查询"<<endl; cin>>ch; switch(ch) { case 1: cout<<"输入你要查询学生的手机号:"<<endl; cin>>Tennum; for(int i=0;i<nopeople;i++) { if(!strcmp(Tennum,Volume[i].cellphone)) { //编号、姓名、性别、年龄、宅电、手机电话 find=1; cout<<"你要查找的学生信息如下:"<<endl; cout<<"学生编号为:"<<Volume[i].number<<endl; cout<<"学生姓名为:"<<Volume[i].name<<endl; cout<<"学生性别为:"<<Volume[i].sexual<<endl; cout<<"学生年龄为:"<<Volume[i].age<<endl; cout<<"学生宅电为:"<<Volume[i].hometele<<endl; cout<<"学生手机电话为:"<<Volume[i].cellphone<<endl; } } if(find==0) { cout<<"查找的学生信息不存在!!!"<<endl; } else { cout<<"查找学生信息成功!"<<endl; }break; case 2: cout<<"输入你要查询学生的姓名:"<<endl; cin>>Name; for(int i=0;i<nopeople;i++) { if(Name==Volume[i].name) { //编号、姓名、性别、年龄、宅电、手机电话 find=1; cout<<"你要查找的学生信息如下:"<<endl; cout<<"学生编号为:"<<Volume[i].number<<endl; cout<<"学生姓名为:"<<Volume[i].name<<endl; cout<<"学生性别为:"<<Volume[i].sexual<<endl; cout<<"学生年龄为:"<<Volume[i].age<<endl; cout<<"学生宅电为:"<<Volume[i].hometele<<endl; cout<<"学生手机电话为:"<<Volume[i].cellphone<<endl; } } if(!find) { cout<<"查找的学生信息不存在!!!"<<endl; } else { cout<<"查找学生信息成功!"<<endl; }break; case 3: cout<<"输入你要查询学生的编号:"<<endl; cin>>Num; for(int i=0;i<nopeople;i++) { if(!strcmp(Num,Volume[i].number)) { //编号、姓名、性别、年龄、宅电、手机电话 find=1; cout<<"你要查找的学生信息如下:"<<endl; cout<<"学生编号为:"<<Volume[i].number<<endl; cout<<"学生姓名为:"<<Volume[i].name<<endl; cout<<"学生性别为:"<<Volume[i].sexual<<endl; cout<<"学生年龄为:"<<Volume[i].age<<endl; cout<<"学生宅电为:"<<Volume[i].hometele<<endl; cout<<"学生手机电话为:"<<Volume[i].cellphone<<endl; } } if(find==0) { cout<<"查找的学生信息不存在!!!"<<endl; } else { cout<<"查找成功!"<<endl; }break; } } void addressbook::Quit() { cout<<"~欢迎下次使用本程序~"<<endl; exit(0); } void addressbook::doDelete()//删除的一般思想就是依据查找来进行的,但是不同的查找算法所产生的删除效率是大不相同的(详情参考数据结构) { char Tennum[20]; char Num[20]; string Name; int find=0,index; int ch; cout<<"输入你要删除的根据:1 按姓名删除 2 按手机号删除 3 按编号删除"<<endl; cin>>ch; switch(ch) { case 1: cout<<"请输入同学姓名:"<<endl; cin>>Name; for(int i=0;i<nopeople;i++) { if(Name==Volume[i].name) { find=1; index=i; break; } } if(!find) { cout<<"要删除的学生信息不存在!!!"<<endl; } else { for(int i=index;i<=nopeople;i++) { Volume[i]=Volume[i+1]; } nopeople--; cout<<"该学生信息已被删除!"<<endl; }break; case 2: cout<<"请输入同学的手机号码:"<<endl; cin>>Tennum; for(int i=0;i<nopeople;i++) { if(!strcmp(Tennum,Volume[i].cellphone)) { find=1; index=i; break; } } if(!find) { cout<<"要删除的学生信息不存在!!!"<<endl; } else { for(int i=index;i<=nopeople;i++) { Volume[i]=Volume[i+1]; } nopeople--; cout<<"该学生信息已被删除!"<<endl; }break; case 3: cout<<"请输入同学的编号:"<<endl; cin>>Num; for(int i=0;i<nopeople;i++) { if(!strcmp(Num,Volume[i].number)) { find=1; index=i; break; } } if(!find) { cout<<"要删除的学生信息不存在!!!"<<endl; } else { for(int i=index;i<=nopeople;i++) { Volume[i]=Volume[i+1]; } nopeople--; cout<<"该学生信息已被删除!"<<endl; }break; } }//用了一个c语言中判断是否相等的函数strcmp(,) void addressbook::Update()//更新的含义就是重新赋值 { string Name; int find=0; cout<& 4000 lt;"请输入要修改的学生姓名:"<<endl; cin>>Name; for(int i=0;i<nopeople;i++) { if(Name==Volume[i].name) { find=1; cout<<"你要查找的学生信息为:"<<endl; cout<<"学生编号为:"<<Volume[i].number<<endl; cout<<"学生姓名为:"<<Volume[i].name<<endl; cout<<"学生性别为:"<<Volume[i].sexual<<endl; cout<<"学生年龄为:"<<Volume[i].age<<endl; cout<<"学生宅电为:"<<Volume[i].hometele<<endl; cout<<"学生手机电话为:"<<Volume[i].cellphone<<endl; cout<<"请更新信息!!"<<endl; cout<<"学生编号为:";cin>>Volume[i].number;cout<<endl; cout<<"学生姓名为:";cin>>Volume[i].name;cout<<endl; cout<<"学生性别为:";cin>>Volume[i].sexual;cout<<endl; cout<<"学生年龄为:";cin>>Volume[i].age;cout<<endl; cout<<"学生宅电为:";cin>>Volume[i].hometele;cout<<endl; cout<<"学生手机电话为:";cin>>Volume[i].cellphone;cout<<endl; break; } } if(find==0) { cout<<"你想修改的学生信息不存在!!!"<<endl; } else { cout<<"该同学的信息已修改成功!"<<endl; } } void addressbook::Outinfor()//显示信息可以参考execl的表格形式 { for(int i=0;i<nopeople;i++) { cout<<"这是第"<<i+1<<"个学生的信息:"<<endl; cout<<"学生的编号:"<<Volume[i].number<<endl; cout<<"输入学生的姓名:"<<Volume[i].name<<endl; cout<<"输入学生的性别:"<<Volume[i].sexual<<endl; cout<<"输入学生的年龄:"<<Volume[i].age<<endl; cout<<"输入学生的宅电:"<<Volume[i].hometele<<endl; cout<<"输入学生的手机电话:"<<Volume[i].cellphone<<endl; } } void addressbook::Choice(int ch)//经常使用的switch选择 { switch(ch) { case 1: int v; cout<<"输入你要创建通讯录的大小:"<<endl; cin>>v; Found(v);//创建 break; case 2: Insert();//添加 break; case 3: Inquery();//查询 break; case 4: /*if(nopeople==0) cout<<"没有可修改量!"<<endl; else*/ Update();//修改 break; case 5: /*if(nopeople==0) cout<<"没有可删除量!"<<endl; else*/ doDelete();//删除 break; case 6: Outinfor();//显示 break; case 7: Quit();break; } } int addressbook::getChoice() { int choice; cout<<"输入你的选择:"<<endl; cin>>choice; return choice; }主函数调用:main.cpp
#include"addressbook.h" int main() { int choice; addressbook a; while(1) { a.showMenu(); choice=a.getChoice(); a.Choice(choice); cout<<"按enter键进行!"<<endl; system("pause>nul"); } return 0; }
程序的主体思想:
利用宏变量控制的数组作为存储结构,以简单的for循环作为主要的循环遍历。
思考:
1.相应的算法是依据相应的存储结构而设计的;
2.对于程序中信息的属性,也应像splserver中的属性那样都有相应的形式存储;
3.对于信息的输出,深入一点可以利用execl或者word进行保存或者显示(我知道c#可以做到这一点);
4.这是c++面向对象的一个简单的 程序设计;
5.像提交表单那样,具有非法输入的判断这是依据2的产生的相应判断算法。
下一个当我学到了数据结构的时候用链表做了一个简单的系统:
基本函数文件algorithm.h:
#include<algorithm>//还需要引入base.h文件(文章末尾) #include<cmath> #include<string> #include<iomanip> #include<sstream> /* the struct of link to finish this test */ typedef struct enode{ employee element; struct enode *next; }enode,*node; ///bool flag[9999]={false}; /* init to enode :3 elements */ node Initenode(node &e){ /* struct a empty enode */ e=new enode; e->next=NULL; node p=e; employee e1,e2,e3; e1.address="石家庄";e2.address="北京";e3.address="上海"; e1.brith.year=1996;e1.brith.month=5;e1.brith.day=12; e2.brith.year=1995;e2.brith.month=10;e2.brith.day=25; e3.brith.year=1995;e3.brith.month=4;e3.brith.day=27; e1.eduction="本科以下";e2.eduction="本科";e3.eduction="本科以上"; e1.name="田元";e2.name="张雪昭";e3.name="刘子蔚"; e1.num="20160003";e2.num="20160002";e3.num="20160001"; e1.post="开发工程师";e2.post="作家";e3.post="数据分析师"; e1.sex="男";e2.sex="F";e3.sex="M"; e1.telnum="15227887557";e2.telnum="15512722325";e3.telnum="13729048450"; node temp1=new enode; temp1->element=e1; temp1->next=p->next;p->next=temp1; node temp2=new enode; temp2->element=e2; temp2->next=p->next;p->next=temp2; node temp3=new enode; temp3->element=e3; temp3->next=p->next;p->next=temp3; return temp1; } /* add employee to linktable */ ostream&operator<<(ostream&os,brithday&brith){ cout<<brith.year<<"年"; if(brith.month<10)cout<<"0"; cout<<brith.month<<"月"; if(brith.day<10)cout<<"0"; cout<<brith.day<<"日"; return cout; } istream &operator>>(istream&is,brithday&brith){ cout<<"请输入员工出生的年份:"<<endl; cin>>brith.year; cout<<"请输入员工出生的月份:"<<endl; cin>>brith.month; cout<<"请输入员工出生的日份:"<<endl; cin>>brith.day; return cin; } bool operator>(brithday brith1,brithday brith2){ if(brith1.year<brith2.year) return true; else if(brith1.year==brith2.year){ if(brith1.month<brith2.month) return true; else if(brith1.month==brith2.month){ if(brith1.day<brith2.day) return true; else return false; }else return false; } else return false; } bool operator >(string str1,string str2){ int m=str1.length(),n=str2.length(); for(int i=0;i<m||i<n;i++){ if(str1[i]>str2[i]){ return true; } } return false; } ostream&operator<<(ostream &os,employee &e){ cout<<"|"<<setw(11)<<e.num<<"|"<<setw(12)<<e.name<<"|"<<setw(10)<<e.sex<<"|"<<setw(6)<<e.brith<<"|"<<setw(11)<<e.eduction<<"|"<<setw(24)<<e.post<<"|"<<setw(13)<<e.telnum<<"|"<<setw(18)<<e.address<<"|"<<endl; cout<<"|-----------|------------|----------|----------------|-----------|------------------------|-------------|------------------|"<<endl; return cout; } bool is_brithday(brithday brith){ if(brith.month==1||brith.month==3||brith.month==5||brith.month==7||brith.month==8||brith.month==10||brith.month==12){ if(brith.day>0&&brith.day<=31)return true; else return false; } else{ if(brith.month==2){ if( (brith.year%4==0&&brith.year%100!=0) || (brith.year%400==0)){ if(brith.day>0&&brith.day<=29)return true; else return false; } else{ if(brith.day>0&&brith.day<=28)return true; else return false; } } else{ if(brith.month<=0||brith.month>12)return false; else{ if(brith.day>0&&brith.day<=30)return true; else return false; } } } } bool is_num(string num){ if(num.length()==8){ if(num.compare("20160000")>0&&num.compare("20169999")<0)return true; else return false; } else return false; } bool is_num_exisit(node&e,string num){ node p=e->next; while(p){ if(p->element.num.compare(num)==0) return false; p=p->next; } return true; } bool is_sex(string sex){ if((sex.compare("男")==0)||(sex.compare("女")==0)||(sex.compare("F")==0)||(sex.compare("M")==0)||(sex.compare("m")==0)||(sex.compare("f")==0)) return true; else return false; } bool is_education(string education){ if(education.compare("本科以上")==0||education.compare("本科")==0||education.compare("本科以下")==0)return true; else return false; } bool is_telnum(string telnum){ if(telnum.length()>12||telnum.length()<4)return false; else return true; } void Inputstew(){ cout<<"|-----------|------------|----------|----------------|-----------|------------------------|-------------|------------------|"<<endl; cout<<"| 编号 | 姓名 | 性别 | 出生日期 | 教育程度 | 职务 | 电话号码 | 住址 |"<<endl; cout<<"|-----------|------------|----------|----------------|-----------|------------------------|-------------|------------------|"<<endl; } istream &operator >> (istream &is,employee &e){ //cout<<"请输入员工编号(20160000-20169999):"<<endl; //while(cin>>e.num){ // bool flag1=is_num(e.num);//,flag2=is_num_exisit(en,e.num);&&flag2{if(!flag1)}//if(!flag2)cout<<"请你检查输入编号是否唯一!"<<endl;node en; // if(flag1)break; // else cout<<"请你检查输入格式是否正确!"<<endl; //} cout<<"请输入员工姓名:"<<endl; cin>>e.name; cout<<"请输入员工性别:"<<endl; while(cin>>e.sex){ if(is_sex(e.sex))break; else cout<<"你输入的标志符无效!"<<endl; } cout<<"请输入员工出生年月:"<<endl; while(cin>>e.brith){ if(is_brithday(e.brith)) break; else cout<<"请检查你输入的年份是否正确!!!"<<endl; } cout<<"请输入员工学历(本科以下/本科/本科以上):"<<endl; while(cin>>e.eduction){ if(is_education(e.eduction))break; else cout<<"请按照格式输入!"<<endl; } cout<<"请输入员工职务(2-9):"<<endl; while(cin>>e.post){ if(e.post.length()>4&&e.post.length()<18)break; else cout<<"请输入正确的职务:"<<endl; } cout<<"请输入员工电话(3-11):"<<endl; while(cin>>e.telnum){ if(is_telnum(e.telnum))break; else cout<<"请输入正确的电话号码:"<<endl; } cout<<"请输入员工住址(2-10):"<<endl; while(cin>>e.address){ if(e.address.length()>4&&e.address.length()<20)break; else cout<<"请输入正确的住址:"<<endl; } return cin; } Status Addemployee(node &e,int n){ node p=e; while(p->next){p=p->next;} for(int i=0;i<n;i++){ cout<<"请输入第"<<i+1<<"位员工的信息:"<<endl; node temp=new enode; cout<<"请输入员工编号(20160000-20169999):"<<endl; while(cin>>temp->element.num){ bool flag1=is_num(temp->element.num),flag2=is_num_exisit(e,temp->element.num); if(flag1&&flag2)break; else{ if(!flag1)cout<<"请你检查输入格式是否正确!"<<endl; if(!flag2)cout<<"请你检查输入编号是否唯一!"<<endl; } } cin>>temp->element; temp->next=p->next;p->next=temp; } return OK; } /* delete employee to linktable */ Status Deletemployee_name(node&e,string name){ node temp=e,n_temp; while(temp->next&&temp->next->element.name!=name){ temp=temp->next; }if(!temp->next){ cout<<"Search by name isn't existed!"<<endl; return OK; } n_temp=temp->next; temp->next=n_temp->next; delete n_temp; cout<<"删除成功!"<<endl; return OK; } Status Deletemployee_num(node&e,string num){ node temp=e,n_temp; while(temp->next&&temp->next->element.num!=num){ temp=temp->next; }if(!temp->next){ cout<<"Delete by num isn't exisited!"<<endl; return ERROR; } n_temp=temp->next; temp->next=n_temp->next; delete n_temp; cout<<"删除成功!"<<endl; return OK; } Status Deletemployee_telnum(node&e,string telnum){ node temp=e,t_temp; while(temp->next&&temp->next->element.telnum.compare(telnum)!=0){ temp=temp->next; }if(!temp->next){ cout<<"Delete by telnum isn't exisited!"<<endl; return ERROR; } t_temp=temp->next; temp->next=t_temp->next; delete t_temp; cout<<"删除成功!"<<endl; return OK; } /* select all information of employee to show */ Status Selectemployee_name(node&e,string name){ node temp=e->next; while(temp&&temp->element.name.compare(name)!=0){ temp=temp->next; }if(!temp){ cout<<"Search by name isn't exisited!"<<endl; return ERROR; }cout<<"Search by name is exisited!the information are:"<<endl; Inputstew(); cout<<temp->element; return OK; } Status Selectemployee_num(node&e,string num){ node temp=e->next; while(temp&&temp->element.num!=num){ temp=temp->next; }if(!temp){ cout<<"Search by num isn't exisited!"<<endl; return ERROR; }cout<<"Search by num is exisited!the information are:"<<endl; Inputstew(); cout<<temp->element; return OK; } Status Selectemployee_telnum(node&e,string telnum){ node temp=e->next; while(temp&&temp->element.telnum!=telnum){ temp=temp->next; }if(!temp){ cout<<"Search by telnum isn't exisited!"<<endl; return ERROR; }cout<<"Search by telnum is exisited!the information are:"<<endl; Inputstew(); cout<<temp->element; return OK; } /* update the information of employee */ Status Updatemployee_name(node&e,string name){ node temp=e;//employee ptemp; while(temp&&temp->element.name!=name){ temp=temp->next; }if(!temp){ cout<<"Search by name isn't exisited!"<<endl; return ERROR; } cin>>temp->element; //temp->element=ptemp; cout<<"更新成功!"<<endl; cout<<"更新信息为:"<<endl; Inputstew(); cout<<temp->element; return OK; } Status Updatemployee_num(node&e,string num){ node temp=e->next;//employee ptemp; while(temp&&temp->element.num.compare(num)!=0){ temp=temp->next; }if(!temp){ cout<<"Search by num isn't exisited!"<<endl; return ERROR; } cin>>temp->element; //temp->element=ptemp; cout<<"更新成功!"<<endl; cout<<"更新信息为:"<<endl; Inputstew(); cout<<temp->element; return OK; } Status Updatemployee_telnum(node&e,string telnum){ node temp=e->next;//employee ptemp; while(temp&&temp->element.telnum!=telnum){ temp=temp->next; }if(!temp){ cout<<"Search by telnum isn't exisited!"<<endl; return ERROR; } cin>>temp->element; //temp->element=ptemp; cout<<"更新成功!"<<endl; cout<<"更新信息为:"<<endl; Inputstew(); cout<<temp->element; return OK; } /* sort employee to show rely on brithday or num */ Status Sort_num(node&e){ /* format:20160708 */ /* e1:遍历寻找合适的插入位置 e2:指向需要插入的结点 e3:指向e2的前一个结点 */ node e1,e2,e3; for(e3=e,e2=e->next;e2!=NULL;){ for(e1=e;e1!=e2;e1=e1->next){ if(e1->next->element.num > e2->element.num){ e3->next=e2->next; e2->next=e1->next; e1->next=e2; e2=e3->next; break; } } if(e1==e2){ e2=e2->next; e3=e3->next; } } //for(e3=e,e2=e->next;e2!=NULL;){ // for(e1=e;e1!=e2;e1=e1->next){ // if(e1->next->element.num>e2->element.num){ // e3->next=e2->next; // e2->next=e1->next; // e1->next=e2; // e2=e3->next;} // } // if(e1=e2){ // e2=e2->next; // e3=e3->next; // } //} return OK; } Status Sort_brithday(node&e){ node e1,e2,e3; for(e3=e,e2=e->next;e2!=NULL;){ for(e1=e;e1!=e2;e1=e1-> c8af ;next){ if(e1->next->element.brith > e2->element.brith){ e3->next=e2->next; e2->next=e1->next; e1->next=e2; e2=e3->next; break; } } if(e1==e2){ e2=e2->next; e3=e3->next; } } return OK; } /* travering link */ Status TraveringLink(node &e){ node p; p=e->next; Inputstew(); while(p){ cout<<p->element; p=p->next; }return OK; } /* operation of employee to show */ void HomeMenu(){ cout<<"|---------------------------------------------|"<<endl; cout<<"| 简易员工管理系统 |"<<endl; cout<<"| 0>退出 |"<<endl; cout<<"| 1>增加员工 |"<<endl; cout<<"| 2>删除员工 |"<<endl; cout<<"| 3>修改员工信息 |"<<endl; cout<<"| 4>查询 |"<<endl; cout<<"| 5>排序 |"<<endl; cout<<"|---------------------------------------------|"<<endl; cout<<"请输入你的选择(0-5):"<<endl; } /*sort*/ void SecondMenu1(){ cout<<"|---------------------------------------------|"<<endl; cout<<"| 0>退出 |"<<endl; cout<<"| 1>按编号 |"<<endl; cout<<"| 2>按年龄 |"<<endl; cout<<"|---------------------------------------------|"<<endl; cout<<"请输入你的选择(0-2):"<<endl; } /* */ void SecondMenu2(){ cout<<"|---------------------------------------------|"<<endl; cout<<"| 0>退出 |"<<endl; cout<<"| 1>按姓名 |"<<endl; cout<<"| 2>按编号 |"<<endl; cout<<"| 3>按电话 |"<<endl; cout<<"|---------------------------------------------|"<<endl; cout<<"请输入你的选择(0-3):"<<endl; } /* Display: |-----------|------------|----------|----------------|-----------|------------------------|-------------|------------------| | 编号 | 姓名 | 性别 | 出生日期 | 教育程度 | 职务 | 电话号码 | 住址 | |-----------|------------|----------|----------------|-----------|------------------------|-------------|------------------| | 20160001 | 欧阳飞燕 | 男 | 1996年05月12日 | 本科以下 | 网络安全工程师分析师 | 15227887557 | 广西壮族自治区 | |-----------|------------|----------|----------------|-----------|------------------------|-------------|------------------| */此程序的主要思想是利用链表实现每个元素的存储,并利用相应的查找算法实现基本 的增删改查功能。
思考:
1.面对程序中元素的查找,我们再深化一些可以实现sqlserver中的模糊查询;
2.对于元素的保存可以利用记事本的进行简单的保存即文件的输出输出;
3.还实现了对输出元素属性的判断,但是对于汉字的判断以及处理还需在进行掌握;
补上base.h的文件:
#pragma once #include<iostream> using namespace std; #define OK 1 #define ERROR 0 typedef int Status; /* information of employee */ struct brithday{ int year; int month; int day; }; struct employee{ string num; /*the number of everyone*/ string name; /*the name of everyon*/ string sex; /*'f'or'm'*/ brithday brith; /*brithday of every*/ string eduction; /*university/high school/specialty/junior middle school/primary school*/ string post; /*post:*/ string telnum; /*the common number's length is 11*/ string address; /*address of everyone*/ };
再贴一些简单的模板(可以进行大量的修改):
学生成绩管理:
stdmark.h:
#include "Stdmark.h" Stdmark::Stdmark(void) { } Stdmark::~Stdmark(void) { } void Stdmark::showMenu() { cout<<"\t\t==学生成绩管理系统=="<<endl; system("cls"); cout<<"\t\t请选择下面的一个项目:"<<endl; cout<<"\t\t1 创建"<<endl; cout<<"\t\t2 添加"<<endl; cout<<"\t\t3 汇总"<<endl; cout<<"\t\t4 排序"<<endl; cout<<"\t\t5 查询"<<endl; cout<<"\t\t6 显示"<<endl; cout<<"\t\t7 退出"<<endl; cout<<"\t\t请选择:"<<endl; } void Stdmark::Found(int v)//创建 { cout<<"学生成绩管理系统初始化!!"<<endl; for(nopeople=0;nopeople<v;nopeople++) { cout<<"这是第"<<nopeople+1<<"个学生的信息:"<<endl; cout<<"输入学生的学号:"<<endl; cin>>Volume[nopeople].studentnum; cout<<"输入学生的姓名:"<<endl; cin>>Volume[nopeople].name; cout<<"输入学生的数学成绩:"<<endl; cin>>Volume[nopeople].math; cout<<"输入学生的语文成绩:"<<endl; cin>>Volume[nopeople].chinese; cout<<"输入学生的英语:"<<endl; cin>>Volume[nopeople].english; } } void Stdmark::Inquery()//查询 { string stnum; int find=0; cout<<"输入你要查询学生的学号:"<<endl; cin>>stnum; for(int i=0;i<nopeople;i++) { if(stnum==Volume[i].studentnum) { //学号、姓名、性别、年龄、班级、学院 find=1; cout<<"你要查找的学生信息如下:"<<endl; cout<<"学生学号为:"<<Volume[i].studentnum<<endl; cout<<"学生姓名为:"<<Volume[i].name<<endl; cout<<"学生数学成绩为:"<<Volume[i].math<<endl; cout<<"学生语文成绩为:"<<Volume[i].chinese<<endl; cout<<"学生英语成绩为:"<<Volume[i].english<<endl; } } if(find==0) { cout<<"查找的学生信息不存在!!!"<<endl; } else { cout<<"查找成功!"<<endl; } } void Stdmark::Choice(int ch)// { switch(ch) { case 1: int v; cout<<"输入你要创建学生成绩管理系统的大小:"<<endl; cin>>v; Found(v);//创建 break; case 2: Insert();//添加 break; case 3: Deal(); Collect();//汇总 break; case 4: Deal(); Sort();//排序 break; case 5: Inquery();//查询 break; case 6: Outinfor();//显示 break; case 7: Quit(); break; } } int Stdmark::getChoice()//输入选择 { int choice; cout<<"输入你的选择:"<<endl; cin>>choice; return choice; } void Stdmark::Collect()//汇总 { //输出每门课的最高分和最低分 //输出每门课的平均成绩-排序 //附加判断课程成绩的优良差 cout<<"输出每门成绩的最高分:"<<endl; Store=Volume[0]; for(int i=1;i<nopeople;i++) { if(Volume[i].chinese>Store.chinese) Store=Volume[i]; } cout<<"语文最高分的学生信息为:"<<endl; cout<<"该学生的学号为: "<<Store.studentnum<<endl; cout<<"学生的姓名为: "<<Store.name<<endl; cout<<"学生的数学成绩为: "<<Store.math<<endl; cout<<"学生的语文成绩为: "<<Store.chinese<<endl; cout<<"学生的英语成绩为: "<<Store.english<<endl; cout<<"学生的平均成绩为: "<<Store.average<<endl; cout<<"学生的总成绩为: "<<Store.sum<<endl; cout<<endl; for(int i=1;i<nopeople;i++) { if(Volume[i].english>Store.english) Store=Volume[i]; } cout<<"英语最高分的学生信息为:"<<endl; cout<<"该学生的学号为"<<Store.studentnum<<endl; cout<<"学生的姓名为"<<Store.name<<endl; cout<<"学生的数学成绩为:"<<Store.math<<endl; cout<<"学生的语文成绩为:"<<Store.chinese<<endl; cout<<"学生的英语成绩为:"<<Store.english<<endl; cout<<"学生的平均成绩为:"<<Store.average<<endl; cout<<"学生的总成绩为:"<<Store.sum<<endl; cout<<endl; for(int i=1;i<nopeople;i++) { if(Volume[i].math>Store.math) Store=Volume[i]; } cout<<"数学最高分的学生信息为:"<<endl; cout<<"该学生的学号为"<<Store.studentnum<<endl; cout<<"学生的姓名为"<<Store.name<<endl; cout<<"学生的数学成绩为:"<<Store.math<<endl; cout<<"学生的语文成绩为:"<<Store.chinese<<endl; cout<<"学生的英语成绩为:"<<Store.english<<endl; cout<<"学生的平均成绩为:"<<Store.average<<endl; cout<<"学生的总成绩为:"<<Store.sum<<endl; cout<<endl; cout<<"输出每门的平均分:"<<endl; double averc=0,avere=0,averm=0; for(int i=0;i<nopeople;i++) { averc=Volume[i].chinese+averc; } cout<<"语文成绩的平均分为:"<<averc/(nopeople+1)<<endl; cout<<endl; for(int i=0;i<nopeople;i++) { avere=Volume[i].english+avere; } cout<<"英语成绩的平均分为:"<<avere/(nopeople+1)<<endl; cout<<endl; for(int i=0;i<nopeople;i++) { averm=Volume[i].math+averm; } cout<<"数学成绩的平均分为:"<<averm/(nopeople+1)<<endl; cout<<endl; } void Stdmark::Outinfor()//信息的显示 { for(int i=0;i<nopeople;i++) { cout<<"这是第"<<i+1<<"个学生的信息:"<<endl; cout<<"学生的学号:"<<Volume[i].studentnum<<endl; cout<<"学生的姓名:"<<Volume[i].name<<endl; cout<<"学生的数学成绩:"<<Volume[i].math<<endl; cout<<"学生的语文成绩:"<<Volume[i].chinese<<endl; cout<<"学生的英语成绩:"<<Volume[i].english<<endl; } } void Stdmark::Quit()//退出 { cout<<"~欢迎下次使用本程序~"<<endl; exit(0); } void Stdmark::Insert()//添加指定位置/最后追加 { cout<<"输入你要插入学生的信息:"<<endl; cout<<"输入学生的学号:"<<endl; cin>>Volume[nopeople].studentnum; cout<<"输入学生的姓名:"<<endl; cin>>Volume[nopeople].name; cout<<"输入学生的数学成绩:"<<endl; cin>>Volume[nopeople].math; cout<<"输入学生的语文成绩:"<<endl; cin>>Volume[nopeople].chinese; cout<<"输入学生的英语成绩:"<<endl; cin>>Volume[nopeople].english; nopeople++; } void Stdmark::Sort()//排序总分降序排序+平均分 { for(int i=0;i<N-1;i++) { for(int j=0;j<N-i-1;j++) if(Volume[j].sum<Volume[j+1].sum) { Store=Volume[j]; Volume[j]=Volume[j+1]; Volume[j+1]=Store; } } for(int i=0;i<nopeople;i++) { cout<<"这是总成绩第"<<i+1<<"名学生的信息:"<<endl; cout<<"学生的学号:"<<Volume[i].studentnum<<endl; cout<<"学生的姓名:"<<Volume[i].name<<endl; cout<<"学生的数学成绩:"<<Volume[i].math<<endl; cout<<"学生的语文成绩:"<<Volume[i].chinese<<endl; cout<<"学生的英语成绩:"<<Volume[i].english<<endl; cout<<"该学生的总成绩为"<<Volume[i].sum<<endl; cout<<"该学生的平均成绩为:"<<Volume[i].average<<endl; } } void Stdmark::Deal() { for(int i=0;i<nopeople;i++) { Volume[i].sum=Volume[i].chinese+Volume[i].english+Volume[i].math; Volume[i].average=(Volume[i].chinese+Volume[i].english+Volume[i].math)/3; } }结构文件:Stdmark.h
#pragma once #include<iostream> #include<string> #define N 100 using namespace std; struct Student { //学号、姓名、数学、语文、英语 string studentnum,name; double math,chinese,english; double average,sum; }; class Stdmark { public: Stdmark(void); ~Stdmark(void); void showMenu();//显示目录 void Insert();//添加指定位置/最后追加 int getChoice();//输入选择 void Outinfor();//信息的显示 void Quit();//退出 void Inquery();//查询按学号 void Collect();//汇总 void Sort();//排序总分降序排序+平均分 void Choice(int ch); void Found(int v);//创建 void Deal();//计算平均分和总分 private: int nopeople; Student Volume ,Store; };程序入口:main.cpp
#include"Stdmark.h" int main() { int choice; Stdmark a; while(1) { a.showMenu(); choice=a.getChoice(); a.Choice(choice); cout<<"按enter键进行!"<<endl; system("pause>nul");//暂停 } return 0; }这个例子的概念如同第一个,有点深化的就是对于数据的处理,这也正好体现了程序的意义:解决实际问题,可以简单进行一些数据处理---->再深化一些处理大数据Hadoop。
简单的管理类小系统可以体现出很多的知识,对于其中的不足点,都发展成为了相应的技术。
对于此类系统的学习,应对sqlserver进行参照。
相关文章推荐
- Log4j日志管理系统简单使用说明
- Log4j日志管理系统简单使用说明
- 简单的学生管理系统
- Log4j日志管理系统简单使用说明
- Log4j日志管理系统简单使用说明
- Log4j日志管理系统简单使用说明
- Log4j日志管理系统简单使用说明
- 简单工作流SWF----公文流转管理系统的数据库设计图
- Log4j日志管理系统简单使用说明
- java实现的简单文件管理系统
- Log4j日志管理系统简单使用说明
- C语言编写的简单的学生成绩管理系统
- Log4j日志管理系统简单使用说明
- 一个简单的物流管理系统
- Log4j日志管理系统简单使用说明
- Log4j日志管理系统简单使用说明(转)
- Log4j日志管理系统简单使用说明
- C语言编写的简单的学生成绩管理系统
- 简单的3T结构系统装号管理模块(未完)
- Log4j日志管理系统简单使用说明