鱼C论坛

 找回密码
 立即注册
查看: 1989|回复: 4

c++编写通讯录

[复制链接]
发表于 2014-12-4 22:49:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<iostream>     
  2. #include<windows.h>
  3. #include<fstream>
  4. #include<iomanip>
  5. #include<string>
  6. #include<conio.h>

  7. //常量定义
  8. #define userNameLen 10
  9. #define LEN 20
  10. #define passwordLen 10
  11. const int M=16;

  12. //函数声明
  13. using namespace std;
  14. bool Login();   //登陆
  15. void inputPSW(char *password);  //输入口令
  16. void Start();
  17. void sysQuit();
  18. void print1();
  19. int main();

  20. //定义信息类
  21. class Hospital
  22. {
  23.   private:
  24.           string name;  //姓名
  25.         string grades;  //班级
  26.         string id;  //学号
  27.         string gender;  //性别
  28.         string address;  //宿舍号
  29.         string phone;  //电话号码
  30.         string card;  //通知书号
  31.         string vaccine;  //疫苗型号
  32.   public:
  33.         Hospital(){}
  34.         Hospital(string name,string grades,string id,string gender,string address,string phone,string card,string vaccine)
  35.                         {
  36.                           this->name=name;  this->grades=grades;  this->id=id;
  37.                           this->gender=gender;  this->address=address;  
  38.                           this->phone=phone;  this->card=card;
  39.                           this->vaccine=vaccine;
  40.                         }
  41.   string getName()          {        return this->name;            }
  42.   string getgrades()        {        return this->grades;        }
  43.   string getId()              {        return this->id;                }
  44.   string getgender()        {        return this->gender;        }
  45.   string getaddress()        {        return this->address;        }
  46.   string getphone()     {        return this->phone;            }       
  47.   string getcard()            {        return this->card;            }
  48.   string getvaccine()        {        return this->vaccine;        }
  49.   void print()
  50.   {
  51.     cout<<setw(14)<<name<<setw(10)<<grades<<setw(10)<<id<<setw(5)<<gender<<setw(7)
  52.     <<address<<setw(12)<<phone<<setw(10)<<card<<setw(7)<<vaccine<<endl;
  53.   }
  54.         friend class Hospital;
  55. };

  56. //定义信息管理类
  57. class HospitalManage
  58. {
  59.   Hospital Arb[M];
  60.   public:
  61.         void input(int N);  //录入信息方法,n为实际录入人数
  62.         void show();  //显示信息方法
  63.         int seek();  //查找信息方法
  64.         void sorting();  //排序信息方法
  65.         void del();  //删除信息方法
  66.         void del(int S);
  67.         void save(int N);  //保存到文件方法,n为实际写入人数
  68.         int read();  // 从文件读出数据方法,返回值为读出的记录数
  69.         void add();  //添加信息的方法
  70.         void compile();  //编辑信息方法
  71.         void amend();  //修改信息方法
  72.        
  73. };

  74. //函数定义
  75. void print1()
  76. {
  77.   cout<<setw(14)<<"姓名"<<setw(10)<<"班级"<<setw(10)<<"学号"<<setw(5)<<"性别"<<setw(7)
  78.   <<"宿舍号"<<setw(12)<<"电话号码"<<setw(10)<<"录取通知书号"<<setw(7)<<"疫苗编号"<<endl;
  79. }
复制代码
  1. void HospitalManage::input(int N)
  2. {
  3.   HospitalManage ip;  system("cls");
  4.   string name,grades,id,gender,address,phone,card,vaccine;
  5.   for(int i=0;i<N;i++)
  6.   {
  7.     cout<<"\n\t\t 输入第"<<i+1<<"个系统信息: \n";
  8.     cout<<"\t\t 姓名: ";                cin>>name;
  9.     cout<<"\t\t 班级: ";                cin>>grades;
  10.     cout<<"\t\t 学号: ";                cin>>id;
  11.     cout<<"\t\t 性别(F/M): ";                cin>>gender;
  12.     cout<<"\t\t 宿舍号(X-XXX): ";            cin>>address;
  13.     cout<<"\t\t 电话号码: ";        cin>>phone;
  14.     cout<<"\t\t 录取通知书号: "; cin>>card;
  15.     cout<<"\t\t11.出血热第一针; 12.出血热第二针; 13.出血热第三针; \n2.麻腮风疫苗; 3.乙肝疫苗;"<<"\n\t\t 疫苗编号: ";        cin>>vaccine;
  16.    Arb[i]=Hospital(name,grades,id,gender,address,phone,card,vaccine);
  17.   }
  18. }


  19. void HospitalManage::add()
  20. {
  21.   system("cls");
  22.   int N=read(); int k=0; HospitalManage ad;
  23.   cout<<"\n\t\t\t\t 信息系统人数: "<<N<<"\n\t\t 输入第 "<<N+1<<"个系统信息: \n";
  24.   string name,grades,id,gender,address,phone,card,vaccine;
  25.   cout<<"\t\t 姓名:  ";                cin>>name;
  26.   cout<<"\t\t 班级:  ";                cin>>grades;
  27.   cout<<"\t\t 学号:  ";                cin>>id;
  28.   cout<<"\t\t 性别(F/M): ";                cin>>gender;
  29.   cout<<"\t\t 宿舍号(X-XXX): "        ;        cin>>address;
  30.   cout<<"\t\t 电话号码: ";        cin>>phone;
  31.   cout<<"\t\t 录取通知书号: ";  cin>>card;
  32.   cout<<"\t\t11.出血热第一针; 12.出血热第二针; 13.出血热第三针; \n 2.疫苗; 3.乙肝疫苗;"<<"\n\t\t 疫苗编号: ";        cin>>vaccine;
  33.   if(N>1)
  34.   {
  35.     for(int j=0;j<N;j++)
  36.         {
  37.           if((Arb[j].getId()==id)&&(Arb[j].getvaccine()==vaccine)&&(Arb[j].getcard()==card))
  38.                 {
  39.                   print1();     Arb[j].print();
  40.                   cout<<"\t\t 该同学已接种过该疫苗! ";
  41.                   k++; break;
  42.                 }
  43.         }
  44.   }
  45.   if(!k)
  46.   {
  47.     Arb[N]=Hospital(name,grades,id,gender,address,phone,card,vaccine);
  48.     N++; ad.save(N);
  49.   }
  50. }
复制代码
  1. int HospitalManage::read()
  2. {
  3.   string name,grades,id,gender,address,phone,card,vaccine;
  4.   const char *file="Hospital.txt";
  5.   ifstream fin(file,ios_base::in);
  6.   if(!fin.is_open())  {cerr<<"\n\\n\t 无法打开 "<<file<<endl; exit(EXIT_FAILURE); }
  7.   int i=0;
  8.   while(!fin.eof())
  9.   {
  10.     fin>>name>>grades>>id>>gender>>address>>phone>>card>>vaccine;
  11.     Arb[i]=Hospital(name,grades,id,gender,address,phone,card,vaccine); i++;
  12.   }fin.close();  return i-1;
  13. }

  14. void HospitalManage::save(int N)
  15. {
  16.   const char *file="Hospital.txt";
  17.   ofstream fout(file,ios_base::out);
  18.   if(!fout.is_open()) {cerr<<"\\n\n\t 无法打开 "<<file<<endl; exit(EXIT_FAILURE); }
  19.   for(int i=0;i<N;i++)
  20.         fout<<setw(16)<<Arb[i].getName()<<setw(9)<<Arb[i].getgrades()
  21.         <<setw(12)<<Arb[i].getId()<<setw(9)<<Arb[i].getgender()<<setw(11)
  22.         <<Arb[i].getaddress()<<setw(15)<<Arb[i].getphone()<<setw(12)<<
  23.         Arb[i].getcard()<<setw(9)<<Arb[i].getvaccine()<<endl;
  24.   cout<<"\t\t 保存数据成功 ";  fout.flush();  fout.close();
  25. }
复制代码




小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-12-4 22:55:01 | 显示全部楼层
我靠,你这预防针跟我们打的一模一样啊,,,该不会你是我们学校的吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-12-4 23:09:26 | 显示全部楼层
Mr.屎壳螂 发表于 2014-12-4 22:55
我靠,你这预防针跟我们打的一模一样啊,,,该不会你是我们学校的吧

每个大学都是一样的把?都是防疫吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-12-4 23:14:29 | 显示全部楼层
lixuelin00 发表于 2014-12-4 23:09
每个大学都是一样的把?都是防疫吧

这样么,,,,,没了解过....感觉写的不错啊~~结构思路很清晰,~加油~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-15 20:56:32 | 显示全部楼层
666
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-9 07:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表