用C++容器vector实现通讯录功能

之前学习C语言的时候,用链表实现过通讯录的基本功能。最近写了一个C++版本的通讯录,参考代码如下所示。

main.cpp

/*****************************************************
Copyright (C): 2017-2018  
File name    : main.cpp
Author       : Zhengqijun
Date         : 2017年02月12日 星期日 16时47分52秒
Description  : 主函数
Funcion List : main()
*****************************************************/

#include "../../include/head.h"
	
personMessage pep;
vector<personMessage> person;
vector<personMessage>::iterator it;
	
int main()
{
	//personMessage pep;
	//vector<personMessage> person;

	char ch = 0;

	//system("clear");

	while(ch != 'q')
	{
		if((ch != 'a') && (ch != 'c') && (ch != 'd') && (ch != 'f'))
		{
			system("clear");
			ch = book_ui();
		}

		switch(ch)
		{
            case 'a':
			{
				ch = add_person();
				break;
			}
			case 'c':
			{
				ch = change_person();
				break;
			}
			case 'd':
			{
				ch = delete_person();
				break;
			}
			case 'e':
			{
				ch = display_person();
				break;
			}
			case 'f':
			{
				ch = find_person();
				break;
			}
			case 'q':
			{
				cout << "Byebye!" << endl;
				return 0;
				break;
			}
			default:
			{
				cout << "input error!" << endl;
				break;
			}
		}
	}

    return 0;
}

head.h

/*****************************************************
Copyright (C): 2017-2018  
File name    : head.h
Author       : Zhengqijun
Date         : 2017年02月12日 星期日 17时11分29秒
Description  : 
Funcion List : 
*****************************************************/

#ifndef __HEAD_H__
#define __HEAD_H__

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#include <stdio.h>
#include <string.h>

using namespace std;

class personMessage
{
public:
	personMessage();
	personMessage(string s);
	~personMessage();

	personMessage& operator=(string s);
	personMessage& operator=(personMessage& other);

	/* sort排序算法需要重载'<',注意加const! */
	bool operator<(const personMessage& p) const;
	bool operator>(const personMessage& p) const;
	bool operator<=(const personMessage& p) const;
	bool operator>=(const personMessage& p) const;
   	
	bool operator==(string s);

	friend istream& operator>>(istream& in, personMessage& p);
	friend ostream& operator<<(ostream& out, personMessage& p);

	int selectFla
  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值