c++通讯录

欢迎见证大家的成长

主函数

#include<iostream>
#include<fstream>
#include<Windows.h>
#include"function.h"
using namespace std;
int main()
{
	date D;
	int choice;
	while (1)
	{		
		show_Menu(&D);		
		cin >> choice;//Your choice
		switch (choice)
		{
		case 1://Add
			system("cls");
			add_Person(&D);
			save(&D);
			break;
		case 2://Show
			system("cls");
			list_ALL_Person(&D);
			break;
		case 3://Delete
			system("cls");
			delte_Person(&D);
			break;
		case 4://find
			system("cls");
			find_Person(&D);
			break;
		case 5://revise
			system("cls");
			revise(&D);
			break; 
		case 6://Empty
			system("cls");
			empty(&D);
			break;
		case 7://quit
			cout << "Welcome all next" << endl;
			Sleep(1000);
			return 0;
			break;
		}
		

	}
	return 0;
}


          函数

#include"function.h"
#include<iostream>
#include<string>
#include<fstream>
#include<Windows.h>
#include<conio.h>
#include<iomanip>
using namespace std;
person person:: operator =(person d)
{
	this->name = d.name;
	this->number = d.number;
	return *this;
}
void show_Menu(date*d)
{
	cout << endl<<"-------------------------------------------------------------" << endl;
	cout << "Correct num: " << d->corrent_Num << endl<<endl;
	cout << "\t\tAddress Books" << endl;
	cout << "\t1.Add new contact person" << endl;
	cout << "\t2.Show all the contact persons" << endl;
	cout << "\t3.Delete contact persons" << endl;
	cout << "\t4.Find contact persons" << endl;
	cout << "\t5.Revise contact persons" << endl;
	cout << "\t6.Clear contact persons" << endl;
	cout << "\t7.Quit system" << endl;
	cout << endl<<"Please enter your choice: ";
}
void save(date*d)
{
	ofstream ofs("Address_Book.txt", ios::out);
	for (int i = 0; i < d->corrent_Num; i++)
	{
		ofs << d->array[i].name << " " << d->array[i].number<<endl;
	}
	ofs.close();
}
void add_Person(date* d)
{
	if (d->corrent_Num <= MAX)
	{
		cout << "Now please enter the name and the number " << endl;
		cin >> d->array[d->corrent_Num].name;
		cin >> d->array[d->corrent_Num].number;
		cout << "Add successfully" << endl;
		d->corrent_Num++;	
	}
	else
		cout << "Researchers have full" << endl;
	Sleep(500);
	system("cls");
}
void list_ALL_Person(date* d)
{
	cout << "Press any key to quit" << endl;
	cout << "--------------------------------" << endl;
	int i = 1;
	ifstream ifs("Address_Book.txt", ios::in);
	string name, number;	
	while (ifs>>name>>number)
	{
		cout  << i++  << ". " << setw(8) <<setiosflags(ios::left) << name << setw(11) << setiosflags(ios::left)<<number<< endl;
	}
	ifs.close();
	
	while (!_kbhit());//Esc
	Sleep(500);
	system("cls");
}
int date:: get_Correct_Num()
{
	int n = 0;
	ifstream ifs("Address_Book.txt", ios::in);
	string name, number;
	while (ifs >> name >> number)
	{
		n++;
	}
	ifs.close();
	return n;
}
void date:: date_Initivate(date* d)
{
	ifstream ifs("Address_Book.txt", ios::in);
	int i = 0;
	string name, number;
	while (i < d->corrent_Num)
	{
		ifs >> name >> number;
		d->array[i].name = name;
		d->array[i++].number = number;
	}
	ifs.close();
}
void find_Person(date* d)
{
	string name;
	int i = 0;
	cout << "Enter the number: ";
	cin >> name;
	for ( i = 0; i < d->corrent_Num; i++)
	{
		if (d->array[i].name == name)
			break;
	}
	if (i == d->corrent_Num)
	{
		cout << "No one is found" << endl;
	}
	else
	{
		cout << setw(5) << setiosflags(ios::left) << d->array[i].name << setw(11) << setiosflags(ios::left) << d->array[i].number;
	}	
	while (!_kbhit());//Esc
	Sleep(500);
	system("cls");
}
void delte_Person(date* d)
{
	string name;
	cout << "Please enter the name: ";
	cin >> name;
	int i = 0;
	for (i = 0; i < d->corrent_Num; i++)
	{
		if (d->array[i].name == name)
			break;
	}
	if (i == d->corrent_Num)
	{
		cout << "No one is found" << endl;
	}
	else
	{
		for (int j = i; j < d->corrent_Num - 1; j++)
		{
			d->array[i] = d->array[i + 1];
		}
		d->corrent_Num--;
		save(d);
		cout << "Delete successfully" << endl;
	}
	
	
	Sleep(500);
	system("cls");

}
void revise(date* d)
{
	string name,number;
	cout << "Please enter the name: ";
	cin >> name;
	int i = 0;
	for (i = 0; i < d->corrent_Num; i++)
	{
		if (d->array[i].name == name)
			break;
	}
	if (i == d->corrent_Num)
	{
		cout << "No one is found" << endl;
	}
	else
	{
		cout << "Please enter tne new name and number" << endl;
		cin >> name >> number;
		d->array[i].name = name;
		d->array[i].number = number;
		save(d);
	}
	
	cout << "Revise successfully" << endl;
	Sleep(500);
	system("cls");
}
void empty(date* d)
{
	ofstream ofs("Address_Book.txt", ios::trunc);
	ofs.close();
	d->corrent_Num = 0;
	cout << "Empty successfully" << endl;
	Sleep(500);
	system("cls");
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值