一个小程序--初学者笔记

#include <iostream>
#include <string>
#include <windows.h>
//#include <bits/stdc++.h>
using namespace std;
#define max 1001

struct ren {
	string name;
	int xin;
	int age;
	string phone;
	string go;
};

struct T {
	ren as[max];
	int size;
};

//添加
void tj(T *abs) {
	//判断人数是否已满
	if (abs->size == max - 1) {
		cout << "人数已满,无法添加!" << endl;
		return;
	}
	//姓名
	string Name;
	Sleep(100);
	cout << "请";
	Sleep(100);
	cout << "输";
	Sleep(100);
	cout << "入";
	Sleep(100);
	cout << "用";
	Sleep(100);
	cout << "户";
	Sleep(100);
	cout << "姓";
	Sleep(100);
	cout << "名";
	Sleep(100);
	cout << ":";
	Sleep(100);
	cin >> Name;
	abs->as[abs->size].name = Name;
	//性别
	Sleep(100);
	cout << "请";
	Sleep(100);
	cout << "输";
	Sleep(100);
	cout << "入";
	Sleep(100);
	cout << "用";
	Sleep(100);
	cout << "户";
	Sleep(100);
	cout << "性";
	Sleep(100);
	cout << "别";
	Sleep(100);
	cout << "(";
	Sleep(100);
	cout << "1";
	Sleep(100);
	cout << "=";
	Sleep(100);
	cout << "=";
	Sleep(100);
	cout << "女";
	Sleep(100);
	cout << ",";
	Sleep(100);
	cout << "2";
	Sleep(100);
	cout << "=";
	Sleep(100);
	cout << "=";
	Sleep(100);
	cout << "男";
	Sleep(100);
	cout << ")";
	Sleep(100);
	cout << ":";
	Sleep(100);
	int sex = 0;
	while (true) {
		cin >> sex;
		if (sex == 1 || sex == 2) {
			abs->as[abs->size].xin = sex;
			break;
		} else {
			Sleep(100);
			cout << "错";
			Sleep(100);
			cout << "误";
			Sleep(100);
			cout << "!";
			Sleep(100);
			cout << "请";
			Sleep(100);
			cout << "重";
			Sleep(100);
			cout << "新";
			Sleep(100);
			cout << "输";
			Sleep(100);
			cout << "入";
			Sleep(100);
			cout << ":";
			Sleep(100);
		}
	}
	//年龄
	Sleep(100);
	cout << "请";
	Sleep(100);
	cout << "输";
	Sleep(100);
	cout << "入";
	Sleep(100);
	cout << "用";
	Sleep(100);
	cout << "户";
	Sleep(100);
	cout << "年";
	Sleep(100);
	cout << "龄";
	Sleep(100);
	cout << ":";
	Sleep(100);
	int aGe = 0;
ANT:
	cin >> aGe;
	if (aGe <= 150 && aGe >= 0) {
		abs->as[abs->size].age = aGe;
	} else {
		Sleep(100);
		cout << "错";
		Sleep(85);
		cout << "误";
		Sleep(85);
		cout << "!";
		Sleep(100);
		cout << "请";
		Sleep(100);
		cout << "重";
		Sleep(100);
		Sleep(100);
		cout << "新";
		Sleep(100);
		cout << "输";
		Sleep(100);
		cout << "入";
		Sleep(100);
		cout << ":";
		Sleep(100);
		goto ANT;
	}
	//电话
	Sleep(125);
	cout << "请";
	Sleep(125);
	cout << "输";
	Sleep(125);
	cout << "入";
	Sleep(125);
	cout << "用";
	Sleep(125);
	cout << "户";
	Sleep(125);
	cout << "的";
	Sleep(125);
	cout << "联";
	Sleep(125);
	cout << "系";
	Sleep(125);
	cout << "电";
	Sleep(125);
	cout << "话";
	Sleep(125);
	cout << ":";
	Sleep(100);
	string ssss;
	cin >> ssss;
	abs->as[abs->size].phone = ssss;
	//住址
	Sleep(100);
	cout << "请";
	Sleep(100);
	cout << "输";
	Sleep(100);
	cout << "入";
	Sleep(100);
	cout << "用";
	Sleep(100);
	cout << "户";
	Sleep(100);
	cout << "的";
	Sleep(100);
	cout << "住";
	Sleep(100);
	cout << "址";
	Sleep(100);
	cout << ":";
	Sleep(100);
	string zhuzhi;
	cin >> zhuzhi;
	abs->as[abs->size].go = zhuzhi;
	abs->size++;
	Sleep(100);
	cout << "添";
	Sleep(100);
	cout << "加";
	Sleep(100);
	cout << "成";
	Sleep(100);
	cout << "功";
	Sleep(100);
	cout << "!" << endl;
	system("pause");
	system("cls");
}

//删除联系人--判断联系人是否存在
int shanchu(T *abs, string name) {
	for (int i = 0; i < abs->size; i++) {
		if (abs->as[i].name == name) {
			return i;
		}
	}
	return -1;
}

//删除联系人--删除
void shan(T *abs) {
	Sleep(110);
	cout << "请";
	Sleep(110);
	cout << "输";
	Sleep(110);
	cout << "入";
	Sleep(110);
	cout << "要";
	Sleep(110);
	cout << "删";
	Sleep(110);
	cout << "除";
	Sleep(110);
	cout << "的";
	Sleep(110);
	cout << "联";
	Sleep(110);
	cout << "系";
	Sleep(110);
	cout << "人";
	Sleep(110);
	cout << ":";
	string Name;
	cin >> Name;
	int ret = shanchu(abs, Name);
	if (ret != -1) {
		for (int i = ret; i < abs->size; i++) {
			abs->as[i] = abs->as[i + 1];
		}
		abs->size--;
		Sleep(100);
		cout << "删";
		Sleep(100);
		cout << "除";
		Sleep(100);
		cout << "成";
		Sleep(100);
		cout << "功";
		Sleep(100);
		cout << "!" << endl;
	} else {
		cout << "查无此人(解决方案:1、去添加一个 2、查看自己是否输入错了)" << endl;
	}
}

void QWE() {
	Sleep(25);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-';
	Sleep(50);
	cout << '-' << endl;
	Sleep(50);
}

//显示
void xianshi(T *abs) {
	//判断人数是否为0
	if (abs->size == 0) {
		cout << "你没有记录联系人,快去记录吧~" << endl;
		system("pause");
		system("cls");
		return;
	} else {
		QWE();
		for (int i = 0; i < abs->size; i++) {
			Sleep(100);
			cout << "姓";
			Sleep(100);
			cout << "名";
			Sleep(100);
			cout << ":";
			Sleep(100);
			cout << abs->as[i].name << "\t";
			if (abs->as[i].xin == 1) {
				cout << "	";
				Sleep(100);
				cout << "性";
				Sleep(100);
				cout << "别";
				Sleep(100);
				cout << ":";
				Sleep(100);
				cout << "女" << "\t";
			} else {
				cout << "	";
				Sleep(100);
				cout << "性";
				Sleep(100);
				cout << "别";
				Sleep(100);
				cout << ":";
				Sleep(100);
				cout << "男" << "\t";
			}
			cout << "年";
			Sleep(100);
			cout << "龄";
			Sleep(100);
			cout << ":" << abs->as[i].age ;
			cout << "\t联系电话:" << abs->as[i].phone  << "\t住址:" << abs->as[i].go << endl;
			QWE();
		}
		system("pause");
		system("cls");
	}
}

//查找联系人
void findren(T *abs) {
	cout << "请输入您要查找的联系人:";
	string Name;
	cin >> Name;
	int ret = shanchu(abs, Name);
	if (ret == -1) {
		cout << "查无此人(解决方案:1、去添加一个 2、查看自己是否输入错了)" << endl;
	} else {
		QWE();
		cout << "找到了!信息如下:" << endl;
		Sleep(200);
		cout << "姓名:" << abs->as[ret].name << "\t";
		Sleep(200);
		if (abs->as[ret].xin == 1) {
			cout << "	性别:女" << "\t";
			Sleep(200);
		} else {
			cout << "	性别:男" << "\t";
			Sleep(200);
		}
		cout << "年龄:" << abs->as[ret].age ;
		Sleep(200);
		cout << "\t联系电话:" << abs->as[ret].phone ;
		Sleep(200);
		cout << "\t住址:" << abs->as[ret].go << endl;
		Sleep(100);
		QWE();
	}
	system("pause");
	system("cls");
}

//修改联系人
void xiougai(T *abs) {
	cout << "请输入您要修改的联系人的名称:";
	string Name;
	cin >> Name;
	int ret = shanchu(abs, Name);
	if (ret == -1) {
		cout << "查无此人(解决方案:1、去添加一个 2、查看自己是否输入错了)" << endl;
	} else {
		string name1;
		cout << "请输入用户姓名:";
		cin >> name1;
		abs->as[ret].name = name1;
		cout << "请输入性别(2男1女):";
		int sex = 0;
		while (true) {
			cin >> sex;
			if (sex == 1 || sex == 2) {
				abs->as[ret].xin = sex;
				break;
			} else {
				cout << "错误!请重新输入:";
			}
		}
		cout << "请输入用户年龄:";
		int aGe = 0;
ATT:
		cin >> aGe;
		if (aGe <= 150 && aGe >= 0) {
			abs->as[ret].age = aGe;
		} else {
			cout << "错误!请重新输入:";
			goto ATT;
		}
		cout << "请输入用户的联系电话:";
		string ssss;
		cin >> ssss;
		abs->as[ret].phone = ssss;
		cout << "请输入用户的住址:";
		string zhuzhi;
		cin >> zhuzhi;
		abs->as[ret].go = zhuzhi;
		cout << "修改成功!" << endl;
	}
	system("pause");
}

//清空通讯录
void qingkong(T *abs) {
	abs->size = 0;
	cout << "清空成功!" << endl;
	system("pause");
}

//菜单
void caidan() {
	cout << "***************************" << endl;
	Sleep(250);
	cout << "*****  1:添加联系人  *****" << endl;
	Sleep(250);
	cout << "*****  2:显示联系人  *****" << endl;
	Sleep(250);
	cout << "*****  3:删除联系人  *****" << endl;
	Sleep(250);
	cout << "*****  4:查找联系人  *****" << endl;
	Sleep(250);
	cout << "*****  5:修改联系人  *****" << endl;
	Sleep(250);
	cout << "*****  6:清空通讯录  *****" << endl;
	Sleep(250);
	cout << "*****  0:退出通讯录  *****" << endl;
	Sleep(250);
	cout << "***************************" << endl;
}
int a = 0;

void aq() {
	cout << "注意事项:请等待文字加载成功后再输入,否则出现问题请自行处理!" << endl;
	system("pause");
	system("cls");
	T abs;
	abs.size = 0;
	while (true) {
		caidan();
		Sleep(100);
		cout << "请";
		Sleep(100);
		cout << "选";
		Sleep(100);
		cout << "择";
		Sleep(100);
		cout << ":";
		Sleep(100);
ABB:
		cin >> a;
		system("cls");
		switch (a) {
			case 0://0:退出通讯录
				goto ABS;
				break;
			case 1://1:添加联系人
				system("cls");
				tj(&abs);
				break;
			case 2://2:显示联系人
				system("cls");
				xianshi(&abs);
				break;
			case 3: //3:删除联系人
				shan(&abs);
				system("pause");
				system("cls");
				break;
			case 4://4:查找联系人
				findren(&abs);
				system("cls");
				break;
			case 5://5:修改联系人
				xiougai(&abs);
				system("cls");
				break;
			case 6://6:清空通讯录
				qingkong(&abs);
				system("cls");
				break;
			default:
				cout << "没有这个选项!请重新选择:";
				goto ABB;
		}
	}
ABS:
	system("cls");
	cout << "感谢使用~欢迎下次使用!" << endl;
	system("pause");
}

//极简主函数
int main() {
	aq();
	return 0;
}

以上是我写的通讯录管理系统......也许写的不大好,因为我是新手,请大神多指教!!!

这也就算我对我自己的练习吧

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值