#include<iostream>
#include<string>
using namespace std;
// 显示菜单函数
void q()
{
cout << "------------------------" << endl;
cout << "----- 1 添加上机人 -----" << endl;
cout << "----- 2 剩余网费-------- " << endl;
cout << "----- 3 下机 ----------- " << endl;
cout << "----- 4 查找人员 ------- " << endl;
cout << "----- 5 充值 ----------- " << endl;
cout << "----- 0 退出系统 ------- " << endl;
cout << "------------------------" << endl;
}
// 人员结构体
struct person
{
string m_Name; // 姓名
int m_Sex; // 性别
int m_Age; // 年龄
string m_phone; // 电话
string m_Addr; // 地址
};
#define Max 1000
struct Addressbooks
{
struct person personArray[Max]; // 人员数组
int m_Size = 0;
};
// 添加人员函数
void a(Addressbooks* abs)
{
if (abs->m_Size == Max)
{
cout << "机器已满" << endl;
}
else
{
// 输入人员信息
string name;
cout << "请输入姓名: " << endl;
cin >> name;
abs->personArray[abs->m_Size].m_Name = name;
cout << "请输入上机器时间:分钟" << endl;
int sex = 0;
// 这里应该是输入时间,但变量名为sex,可能有误
cin >> sex;
cout << "请输入年龄:" << endl;
int age = 0;
cin >> age;
abs->personArray[abs->m_Size].m_Age = age;
cout << "请输入身份证号: " << endl;
string phone;
cin >> phone;
abs->personArray[abs->m_Size].m_phone = phone;
cout << "请输入机器位置: " << endl;
string address;
cin >> address;
abs->personArray[abs->m_Size].m_Addr = address;
abs->m_Size++;
cout << "添加成功" << endl;
system("pause");
// 暂停程序
system("cls");
// 清空屏幕
}
}
void b(Addressbooks* abs)
{
if (abs->m_Size == 0)
{
cout << "姓名 剩余网费 " << endl;
}
else
{
for (int i = 0; i < abs->m_Size; i++)
{
cout << "姓名:" << abs->personArray[i].m_Name << "\t";
cout << "剩余时间:" << abs->personArray[i].m_Addr << endl;
}
}
system("pause");
// 暂停程序
system("cls");
// 清空屏幕
}
int f(Addressbooks* abs, string name)
{
for (int i = 0; i < abs->m_Size; i++)
{
if (abs->personArray[i].m_Name == name)
{
return i;
// 返回该人员在数组中的索引
}
}
return -1;
}
void c(Addressbooks* abs)
{
cout << "请输入下机人:" << endl;
string name;
cin >> name;
int ret = f(abs, name);
// 检查是否存在该人员
if (ret != -1)
{
for (int i = ret; i < abs->m_Size; i++)
{
abs->personArray[i] = abs->personArray[i + 1];
}
abs->m_Size--;
cout << "删除成功" << endl;
}
else
{
cout << "查无此人" << endl;
}
system("pause");
// 暂停程序
system("cls");
// 清空屏幕
}
// 查找人员函数
void d(Addressbooks* abs)
{
cout << "请输入您要查找的上网人" << endl;
string name;
cin >> name;
int ret = f(abs, name);
// 检查是否存在该人员
if (ret != -1)
{
cout << "姓名:" << abs->personArray[ret].m_Name << "\t";
cout << "上机时间:" << abs->personArray[ret].m_Sex << "\t";
cout << "年龄:" << abs->personArray[ret].m_Age << "\t";
cout << "身份证号码:" << abs->personArray[ret].m_phone << "\t";
cout << "机器位置:" << abs->personArray[ret].m_Addr << endl;
}
else
{
cout << "查无此人" << endl;
}
system("pause");
// 暂停程序
system("cls");
// 清空屏幕
}
void e(Addressbooks* abs)
{
// 提示用户输入姓名
cout << "充值金额" << endl;
string name;
cin >> name;
// 检查是否存在该姓名
int ret = f(abs, name);
if (ret != -1)
{
// 修改姓名
string name;
cout << "请输入姓名" << endl;
cin >> name;
abs->personArray[ret].m_Name = name;
// 输入机器号
cout << "输入机器号" << endl;
int sex = 0;
while (true)
{
cin >> sex;
if (sex == 1 || sex == 2)
{
abs->personArray[abs->m_Size].m_Sex = sex;
break;
}
cout << "输出有错误请重新输入" << endl;
}
// 输入年龄
cout << " 请输入年龄" << endl;
int age;
cin >> age;
abs->personArray[ret].m_Age = age;
// 输入电话
cout << " 请输入电话" << endl;
string phone;
cin >> phone;
abs->personArray[ret].m_phone = phone;
// 输入住址
cout << " 请输入身份证" << endl;
string address;
cin >> address;
cout << "充值成功" << endl;
}
system("pause");
system("cls");
}
// 主函数
int main()
{
Addressbooks abs;
abs.m_Size = 0;
int select = 0;
while (true)
{
q();
// 显示菜单
cin >> select;
// 获取用户选择
switch (select)
{
case 1:
a(&abs);
// 添加人员
break;
case 2:
b(&abs);
// 显示人员信息
break;
case 3:
{
c(&abs);
// 删除人员
break;
}
case 4:
d(&abs);
// 查找人员
break;
case 5://5 充值
e(&abs);
break;
case 0:
cout << "欢迎下次使用" << endl;
// 退出程序
break;
default:
break;
}
}
return 0;
}