cpp 复习之前学习的指针学习新的内容和内存的引用,淘宝话术快捷查询
本帖最后由 zds212 于 2021-5-7 22:33 编辑#include<iostream>
using namespace std;
#include <string >
#define max 500
//定义属性
struct content
{
string seek;
string ct;
};
struct huashu
{
content arr;
int size;
};
//菜单
void caidan()
{
cout << "----------------------------------" << endl;
cout << "----- 1.添加淘宝话术内容 -----" << endl;
cout << "----- 2.显示所有话术内容 -----" << endl;
cout << "----- 3.查找单条话术内容 -----" << endl;
cout << "----- 4.修改单条话术内容 -----" << endl;
cout << "----- 5.清空所有话术内容 -----" << endl;
cout << "----- 0.退出 (或者其他)-----" << endl;
cout << "----------------------------------" << endl;
}
// 1.添加淘宝话术内容
void addhs(huashu& abs)
{
string seek;
cout << "输入查找关键字\n";
cin >> seek;
abs.arr.seek = seek;
string ct;
cout << "输入话术\n";
cin >> ct;
abs.arr.ct = ct;
system("pause");
system("cls");
abs.size++;
}
// 2.显示所有话术内容
void disply(huashu* abs)
{
if (abs->size != 0)
{
for (int i = 0; i < abs->size; i++)
{
cout << "查找关键字:" << abs->arr.seek << " 话术内容为:" << abs->arr.ct << endl;
}
system("pause");
system("cls");
}
else
{
cout << "当前内存内无话术!"<<endl;
system("pause");
system("cls");
}
}
// 3.查找单条话术内容
// 3.1查找内容所在下标位置
int seek1(huashu &abs)
{
string ct;
cout << "请输入查找的关键字!"<<endl;
cin >> ct;
if (abs.size != 0)
{
for (int i = 0; i < abs.size; i++)
{
if (abs.arr.seek == ct)
{
return i;
}
}
}
else
{
cout << "话术内容为空,请先添加话术!" << endl;
system("pause");
system("cls");
}
return -1;
}
// 3.2打印出内容
void seek2(huashu *abs,int xb)
{
if (xb == -1)
{
if (abs->size != 0)
{
cout << "查无此关键字,请先添加话术!\n";
system("pause");
system("cls");
}
}
else
{
cout << "查找关键字:" << abs->arr.seek << "话术内容为:" << abs->arr.ct << endl;
system("pause");
system("cls");
}
}
// 4.修改单条话术内容
void xg(huashu &abs)
{
int xb=seek1(abs);
if (xb != -1)
{
string seek;
cout << "请输入修改的关键字!\n";
cin >> seek;
abs.arr.seek = seek;
string ct;
cout << "请输入修改的话术!\n";
cin >> ct;
abs.arr.ct = ct;
cout << "修改成功!";
system("pause");
system("cls");
}
}
// 5.清空所有话术内容
void qk(huashu *abs)
{
int select;
cout << "请确认是否情况所有话术内容!\n\t1.取消操作2.继续执行情况 (输入其他取消清空)"<<endl;
cin >> select;
if (select == 2 )
{
abs->size = 0;
cout << "清空成功!" << endl;
}
else
{
cout << "取消清空操作!" << endl;
}
system("pause");
system("cls");
}
// 0.退出 (或者其他)
int main()
{
huashu abs;
abs.size = 0;
while (true)
{
caidan();
int select;
int xb;
cin >> select;
switch (select)
{
case 1://添加淘宝话术内容
addhs(abs);//引用法 const *abs=&abs
break;
case 2://显示所有话术内容
disply(&abs);//指针
break;
case 3://查找单条话术内容
xb=seek1(abs);
seek2(&abs, xb);
break;
case 4://修改单条话术内容
xg(abs);
break;
case 5://清空所有话术内容
qk(&abs);
break;
default://退出 (或者其他)
cout << "欢迎下次使用本程序!\n";
system("pause");
return 0;
break;
}
}
system("pause");
return 0;
} 感觉很像大学的作业,哈哈哈,谢谢楼主复习下知识 aristan 发表于 2021-4-28 13:59
感觉很像大学的作业,哈哈哈,谢谢楼主复习下知识
:loveliness: 没上过大学。 就当上一次大学做一次作业吧。 嘿嘿!
页:
[1]