一、实训目的
通过课程设计,学会运用数据结构知识,针对具体应用,自己设计合理数据结构,确定存储结构,并能设计具体操作算法,选择使用具体语言进行实现。掌握C++较复杂程序的组织和设计过程,调试技巧。学习解决实际问题的能力。
二、实训环境
计算机windows xp或其它版本,VC6.0或更高版本,或其它语言环境。
三、实习题目
赵斌是一个信管专业的学生,大学四年顺利毕业了。在毕业季,他也像其他学子一样,投身于求职大军,投出一份又一份求职简历,在苦苦地等待之后,他接到了中国移动通信公司广东分司的面试通知书,通知他于本月1号10点到公司面试。当天,晴空万里,艳阳高照,他身着西装,高兴地早早来到公司楼下等待。10点钟整,他和其他新人一起,坐到公司的面试现场。他领取的一一份程序设计题: 假如你是我公司一名客服技术人员,现请你选择自己熟悉的语言,来设计一个程序,管理客户向公司打进来的咨询电话。请事行分析析使用方法和工具,说明自己的思路方法,写一份完整的程序,并实例测试。
分析:
由题目得知是管理客户打进来的咨询电话,那么必须要的功能有储存、修改、查询、删除、显示。我加了一个可有可无的功能便是排序——对于电话号码的排序。对于每样操作的详细分析就不多说了,下面直接上代码。
//MCAT.h
#include <string>
#include <iostream>
using std::string;
#ifndef MCAT_H_
#define MCAT_H_
struct Client{
string Name; //姓名
string Sex; //性别
unsigned long long int Phone; //电话
string Birth_Place; //籍贯
string Time; //来电时间
string Consuling_Items; //咨询内容
string Evaluate; //对于本次服务的评价
Client *next;
};
class MCAT{
public:
MCAT();
~MCAT(){}
void Save(); //储存客户信息
void Seek_Name(); //按名字查找查找
void Seek_Phone_Num(); //按电话号码查找
void Seek_Birth_Place(); //按籍贯查找
void Seek_Sex(); //按性别查找
void Modify(); //修改客户信息
void Delete(); //删除客户信息
void All_Printf(); //打印全部客户信息
void Specify_Printf(); //打印指定客户信息
void Queue_Phone_Num(); //按电话号码大小排序
void Menu(); //菜单
void Seek_Menu(); //查询菜单
void Procsee_Menu(); //记录处理菜单
private:
Client *m_head;
Client *m_pre_p[20];
Client *m_p[20]; //查找找到的指针的数组
int m_seek_num; //查找找到指针的数目
int m_Client_Num; //客户总个数
};
#endif
//MCADT.cpp
#include <iostream>
#include <string>
#include <conio.h>
#include "MCAT.h"
MCAT::MCAT(){
Client *p = new Client;
m_head = p;
m_head->next = NULL;
m_seek_num = 0;
m_Client_Num = 0;
}
void MCAT::Save(){
system("cls");
using std::cout;
using std::cin;
using std::endl;
using std::string;
int n; //客户信息的数目n
string t_Name = ""; //姓名
string t_Sex = ""; //性别
unsigned long long int t_Phone; //电话
string t_Birth_Place = ""; //籍贯
string t_Time = ""; //来电时间
string t_Consuling_Items; //咨询内容
string t_Evaluate; //对于本次服务的评价
cout << "\n请设置你要储存的客户信息的数目( n>0 ):";
cin >> n;
while (n <= 0){
cout << "\n你设置的数目不符合,请重新设置:";
cin >> n;
}
for (int i = 0; i < n; i++){
system("cls");
cout << "\n输入客户数据注意事项:" << endl;
cout << "性别(男/女)" << endl;
cout << "咨询内容(查询余额/查询流量/查询套餐)" << endl;
cout << "服务评价(不满意/一般/满意)" << endl;
cout << "\n请按要求输入,本系统还没有纠错功能!!请见谅!!" << endl;
cout << "\n请输入第"<< i + 1 <<"个客户的信息:" << endl;
cout << " 姓 名:";
cin >> t_Name;
cout << " 性 别:";
cin >> t_Sex;
cout << " 电 话:";
cin >> t_Phone;
cout << " 籍 贯:";
cin >> t_Birth_Place;
cout << " 来电时间:";
cin >> t_Time;
cout << " 咨询内容:";
cin >> t_Consuling_Items;
cout << " 服务评价:";
cin >> t_Evaluate;
Client *s = new Client;
s->Name = t_Name;
s->Sex = t_Sex;
s->Phone = t_Phone;
s->Birth_Place = t_Birth_Place;
s->Time = t_Time;
s->Consuling_Items = t_Consuling_Items;
s->Evaluate = t_Evaluate;
s->next = m_head->next;
m_head->next = s;
m_Client_Num++;
}
cout << "\n储存成功!" << endl;
system("pause");
system("cls");
this->Menu();
}
void MCAT::All_Printf(){
using std::cout;
using std::endl;
system("cls");
int n = 0;
Client *p = m_head->next;
if (m_Client_Num <= 0){
cout << "\n没有客户信息!" << endl;
system("pause");
system("cls");
this->Menu();
}
else{
cout << "\n客户的信息为:" << endl;
while (p != NULL){
cout << "\n第" << n + 1 << "位客户的信息为:" << endl;
cout << " 姓 名:" << p->Name << endl;
cout << " 性 别:" << p->Sex << endl;
cout << " 电 话:" << p->Phone << endl;
cout << " 籍 贯:" << p->Birth_Place << endl;
cout << " 来电时间:" << p->Time << endl;
cout << " 咨询内容:" << p->Consuling_Items << endl;
cout << " 服务评价:" << p->Evaluate << endl;
cout << "\n\n";
p = p->next;
n++;
}
}
char ch;
cout << "\n按任意键回到主菜单:";
ch = _getch();
system("cls");
this->Menu();
}
void MCAT::Specify_Printf(){
using std::cout;
using std::cin;
using std::endl;
system("cls");
char t = 'n';
cout << "\n你查找的客户的信息为:" << endl;
for (int i = 0; i < m_seek_num; i++){
cout << " 姓 名:" << m_p[i]->Name << endl;
cout << " 性 别:" << m_p[i]->Sex << endl;
cout << " 电 话:" << m_p[i]->Phone << endl;
cout << " 籍 贯:" << m_p[i]->Birth_Place << endl;
cout << " 来电时间:" << m_p[i]->Time << endl;
cout << " 咨询内容:" << m_p[i]->Consuling_Items << endl;
cout << " 服务评价:" << m_p[i]->Evaluate << endl;
cout << "\n\n";
}
m_seek_num = 0;
system("pause");
cout << "是否要对该客户进行操作(y/n):";
t = _getch();
if (t == 'y')
this->Procsee_Menu();
else{
system("cls");
this->Seek_Menu();
}
}
void MCAT::Seek_Name(){
system("cls");
using std::cout;
using std::cin;
using std::endl;
using std::string;
int i = 0;
Client *p, *q;
p = m_head->next;
q = m_head;
string Name = "";
cout << "\n请输入你要查找客户的姓名:";
cin >> Name;
while (p != NULL){
if (p->Name == Name){
m_p[i] = p;
m_pre_p[i] = q;
i++;
m_seek_num++;
}
p = p->next;
q = q->next;
}
if (i == 0){
cout << "\n不好意思,查找失败,没有该客户." << endl;
system("pause");
system("cls");
this->Seek_Menu();
}
else{
this->Specify_Printf();
}
}
void MCAT::Seek_Sex(){
system("cls");
using std::cout;
using std::cin;
using std::endl;
using std::string;
int i = 0;
Client *p, *q;
p = m_head->next;
q = m_head;
string Sex = "";
cout << "\n请输入你要查找客户的性别:";
cin >> Sex;
while (p != NULL){
if (p->Sex == Sex){
m_p[i] = p;
m_pre_p[i] = q;
i++;
m_seek_num++;
}
p = p->next;
q = q->next;
}
if (i == 0){
cout << "\n不好意思,查找失败,没有该客户." << endl;
system("pause");
system("cls");
this->Seek_Menu();
}
else{
system("cls");
this->Specify_Printf();
}
}
void MCAT::Seek_Phone_Num(){
system("cls");
using std::cout;
using std::cin;
using std::endl;
int i = 0;
Client *p, *q;
p = m_head->next;
q = m_head;
unsigned long long Phone;
cout << "\n请输入你要查找客户的电话号码:";
cin >> Phone;
while (p != NULL){
if (p->Phone == Phone){
m_p[i] = p;
m_pre_p[i] = q;
i++;
m_seek_num++;
}
p = p->next;
q = q->next;
}
if (i == 0){
cout << "\n不好意思,查找失败,没有该客户." << endl;
system("pause");
system("cls");
this->Seek_Menu();
}
else{
system("cls");
this->Specify_Printf();
}
}
void MCAT::Seek_Birth_Place(){
system("cls");
using std::cout;
using std::cin;
using std::endl;
int i = 0;
Client *p, *q;
p = m_head->next;
q = m_head;
string Birth_Place;
cout << "\n请输入你要查找客户的籍贯:";
cin >> Birth_Place;
while (p != NULL){
if (p->Birth_Place == Birth_Place){
m_p[i] = p;
m_pre_p[i] = q;
i++;
m_seek_num++;
}
p = p->next;
q = q->next;
}
if (i == 0){
cout << "\n不好意思,查找失败,没有该客户." << endl;
system("pause");
system("cls");
this->Seek_Menu();
}
else{
system("cls");
this->Specify_Printf();
}
}
void MCAT::Modify(){
using std::cout;
using std::cin;
using std::endl;
using std::string;
string str;
char t = 'y';
int n = 0; //选择修改几个客户信息
int m = -1; //选择修改第几个客户信息
cout << "\n修改注意事项:" << endl;
cout << "首先设置你想要修改多少个客户(上限为查找到的客户的全体)" << endl;
cout << "按查找到的顺序来选择你要修改哪一个客户(上限为查找到的客户的全体)" << endl;
cout << "修改内容为 姓名、性别等等客户数据" << endl;
cout << "\n请设置需要修改的客户的数目:";
cin >> n;
while (n <= 0){
cout << "你设置的数目不符,请重新设置:";
cin >> n;
}
for (int i = 0; i < n; i++){
cout << "第"<< i + 1 <<"位修改客户的序号为:";
cin >> m;
m = m - 1;
t = 'y';
while (t == 'y'){
cout << "你要修改该客户的信息为:";
cin >> str;
if (str == "姓名"){
cout << " 姓名:";
cin >> m_p[m]->Name;
}
else if (str == "性别"){
cout << " 性别:";
cin >> m_p[m]->Sex;
}
else if (str == "电话"){
cout << " 电话:";
cin >> m_p[m]->Phone;
}
else if (str == "籍贯"){
cout << " 籍贯:";
cin >> m_p[m]->Birth_Place;
}
else if (str == "咨询内容"){
cout << " 咨询内容:";
cin >> m_p[m]->Consuling_Items;
}
else if (str == "服务评价"){
cout << " 服务评价:";
cin >> m_p[m]->Evaluate;
}
cout << "\n你是否要继续修改该客户的信息(y/n):";
t = _getch();
cout << endl;
}
system("cls");
cout << "\n修改后的客户信息为:" << endl;
cout << " 姓 名:" << m_p[m]->Name << endl;
cout << " 性 别:" << m_p[m]->Sex << endl;
cout << " 电 话:" << m_p[m]->Phone << endl;
cout << " 籍 贯:" << m_p[m]->Birth_Place << endl;
cout << " 来电时间:" << m_p[m]->Time << endl;
cout << " 咨询内容:" << m_p[m]->Consuling_Items << endl;
cout << " 服务评价:" << m_p[m]->Evaluate << endl;
cout << "\n\n";
}
char ch;
cout << "\n按任意键回到查找菜单:";
ch = _getch();
system("cls");
this->Seek_Menu();
}
void MCAT::Delete(){
using std::cout;
using std::cin;
using std::endl;
using std::string;
Client *p, *q;
string str;
char t = 'y';
int n = 0; //选择修改几个客户信息
int m = -1; //选择修改第几个客户信息
cout << "\n删除注意事项:" << endl;
cout << "首先设置你想要删除多少个客户(上限为查找到的客户的全体)" << endl;
cout << "按查找到的客户顺序来选择你要删除哪一个客户(上限为查找到的客户的全体)" << endl;
cout << "\n请设置需要删除的客户的数目:";
cin >> n;
while (n <= 0){
cout << "你设置的数目不符,请重新设置:";
cin >> n;
}
for (int i = 0; i < n; i++){
cout << "第" << i + 1 << "位删除客户的序号为:";
cin >> m;
m = m - 1;
p = m_p[m];
q = m_pre_p[m];
q->next = p->next;
delete p;
}
cout << "\n删除完毕." << endl;
char ch;
cout << "\n按任意键回到查找菜单:";
ch = _getch();
system("cls");
this->Seek_Menu();
}
void MCAT::Queue_Phone_Num(){
using std::cout;
using std::cin;
using std::endl;
system("cls");
string t_Name; //姓名
string t_Sex; //性别
unsigned long long int t_Phone; //电话
string t_Birth_Place; //籍贯
string t_Time; //来电时间
string t_Consuling_Items; //咨询内容
string t_Evaluate; //对于本次服务的评价
Client *p, *q;
if (m_Client_Num == 1)
cout << "\n排序完成!" << endl;
else if (m_Client_Num > 1){
for (int j = 1; j < m_Client_Num; j++){
p = m_head->next->next;
q = m_head->next;
for (int i = 0; i < m_Client_Num - j; i++){
if (q->Phone > p->Phone){
t_Name = p->Name;
p->Name = q->Name;
q->Name = t_Name;
t_Sex = p->Sex;
p->Sex = q->Sex;
q->Sex = t_Sex;
t_Phone = p->Phone;
p->Phone = q->Phone;
q->Phone = t_Phone;
t_Birth_Place = p->Birth_Place;
p->Birth_Place = q->Birth_Place;
q->Birth_Place = t_Birth_Place;
t_Time = p->Time;
p->Time = q->Time;
q->Time = t_Time;
t_Consuling_Items = p->Consuling_Items;
p->Consuling_Items = q->Consuling_Items;
q->Consuling_Items = t_Consuling_Items;
t_Evaluate = p->Evaluate;
p->Evaluate = q->Evaluate;
q->Evaluate = t_Evaluate;
p = p->next;
q = q->next;
}
else{
p = p->next;
q = q->next;
}
}
}
cout << "\n排序完成!" << endl;
}
else {
cout << "\n没有客户记录可排序." << endl;
char ch;
cout << "\n按任意键回到主菜单:";
ch = _getch();
this->Menu();
}
char ch;
cout << "\n按任意键回到主菜单:";
ch = _getch();
system("cls");
this->Menu();
}
void MCAT::Menu(){
using std::cout;
using std::cin;
using std::endl;
char ch = '0';
cout << "┏----------------------------------------------------------------------------┓";
cout << "┃ 客户记录管理系统 ┃";
cout << "┃ ----试玩版Hp19┃";
cout << "┃----------------------------------------------------------------------------┃";
cout << "┃ ┃";
cout << "┃ ┃";
cout << "┃ 1. 储存客户信息 ┃";
cout << "┃ 2. 查询客户信息 ┃";
cout << "┃ 3. 打印客户信息 ┃";
cout << "┃ 4. 手机号码排序 ┃";
cout << "┃ 0. 退 出 ┃";
cout << "┃ ┃";
cout << "┃ ┃";
cout << "┠----------------------------------------------------------------------------┃";
cout << "\n请选择你要执行的操作:";
ch = _getch();
switch (ch){
case '1':
this->Save();
break;
case '2':
this->Seek_Menu();
break;
case '3':
this->All_Printf();
break;
case '4':
this->Queue_Phone_Num();
break;
case '0':
cout << "\n 感谢你的使用!!" << endl;
exit(EXIT_FAILURE);
break;
default:
cout << "没有该选项,抱歉!" << endl;
system("pause");
system("cls");
this->Menu();
break;
}
}
void MCAT::Seek_Menu(){
system("cls");
using std::cout;
using std::cin;
using std::endl;
char ch = '0';
cout << "┏----------------------------------------------------------------------------┓";
cout << "┃ 查 找 系 统 ┃";
cout << "┃----------------------------------------------------------------------------┃";
cout << "┃ ┃";
cout << "┃ 1. 按 姓名 查找 ┃";
cout << "┃ 2. 按 性别 查找 ┃";
cout << "┃ 3. 按 电话 查找 ┃";
cout << "┃ 4. 按 籍贯 查找 ┃";
cout << "┃ 0. 返 回 ┃";
cout << "┃ ┃";
cout << "┠----------------------------------------------------------------------------┃";
cout << "\n请选择你要执行的操作:";
ch = _getch();
switch (ch){
case '1':
this->Seek_Name();
break;
case '2':
this->Seek_Sex();
break;
case '3':
this->Seek_Phone_Num();
break;
case '4':
this->Seek_Birth_Place();
break;
case '0':
system("cls");
this->Menu();
break;
default:
cout << "没有该选项,抱歉!" << endl;
system("pause");
system("cls");
this->Seek_Menu();
break;
}
}
void MCAT::Procsee_Menu(){
system("cls");
using std::cout;
using std::cin;
using std::endl;
char ch = 0;
cout << "┏----------------------------------------------------------------------------┓";
cout << "┃ 记 录 处 理 ┃";
cout << "┃----------------------------------------------------------------------------┃";
cout << "┃ ┃";
cout << "┃ 1. 删 除 记 录 ┃";
cout << "┃ 2. 修 改 记 录 ┃";
cout << "┃ 0. 返 回 ┃";
cout << "┃ ┃";
cout << "┠----------------------------------------------------------------------------┃";
cout << "\n请选择你要执行的操作:";
ch = _getch();
switch (ch){
case '1':
system("cls");
this->Delete();
break;
case '2':
system("cls");
this->Modify();
break;
case '0':
system("cls");
this->Menu();
break;
}
}
//MCAT_Main.cpp
#include "MCAT.h"
int main(){
MCAT mc;
mc.Menu();
return 0;
}
实验结果图:
首先主菜单
储存操作:
查询菜单:
实验其中一个
按性别查找:
选择y
修改操作:
选择n
打印客户信息操作
按电话号码从小到大排序
排序完再次打印客户信息
删除操作
删除后打印客户信息
退出:
做的时间不多,所以做的比较粗糙,漏洞想必还是有不少的。可改进的地方也有很多。还有一些想法在我现在的技术层面上暂时无法实现。无论怎样,这个程序到此为止了。
体会:
数据结构这门课程就到此就算圆满结束,但是回想一下这门课程,却发现课程后面的内容我并没有掌握多少。这并不是老师的问题,完完全全就是我自己的问题。老师讲课很认真,也很详细,没有什么可以挑剔的。是因为我后期的时候上课的态度不是很认真,也没有完成老师博客上布置的任务。正因为课程的后面没掌握什么,这也是为什么这次的课程设计我没有用到后面的知识的原因。我想用,但是我没把握,而且我还很懒没有认真的对待这次的课程设计,这次的课程设计是赶出来的,前前后后都不到一天。真的感觉挺对不起老师的。
无论如何,这段数据结构之旅结束了,下一段也该启程了。
THE END