博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据结构课程设计(题目4)
阅读量:4155 次
发布时间:2019-05-26

本文共 5990 字,大约阅读时间需要 19 分钟。

                                     数据结构程序设计

 

一、实训目的

通过课程设计,学会运用数据结构知识,针对具体应用,自己设计合理数据结构,确定存储结构,并能设计具体操作算法,

选择使用具体语言进行实现。掌握C++较复杂程序的组织和设计过程,调试技巧。学习解决实际问题的能力。

 

二、问题描述

     赵斌是一个信管专业的学生,大学四年顺利毕业了。在毕业季,他也像其他学子一样,投身于求职大军,投出一份又一份求职简历,在苦苦地等待之后,他接到了中国移动通信公司广东分司的面试通知书,通知他于本月1号10点到公司面试。当天,晴空万里,艳阳高照,他身着西装,高兴地早早来到公司楼下等待。10点钟整,他和其他新人一起,坐到公司的面试现场。他领取的一一份程序设计题:假如你是我公司一名客服技术人员,现请你选择自己熟悉的语言,来设计一个程序,管理客户向公司打进来的咨询电话。

 

三、要求

  1.请事行分析析使用方法和工具,说明自己的思路方法;

  2.写一份完整的程序,并实例测试。

 

四、分析

1.使用方法:题目要求使用数据结构的知识来设计一个程序管理客户打进公司的电话,那么管理就应该包括客户信息的输入、查找、删除、清空输入记录等功能。而单链表可以实现上述的功能,因此可以使用从单链表中学到的知识、结合结构体与类来设计一个程序,完成对客户打进公司的电话的管理。

2.实训环境:计算机Windows 8系统,编程软件Microsoft Visual Studio Express 2013 for Windows Desktop

五、实现代码

1.新建工程与头文件:在编程软件VC++ 6.0中新建一个空的工程,将其命名为“yangy”,然后再在该工程里新建一个头文件

“link_number.h”,该头文件包含以下代码:

#ifndef Number_H   #define Number_H   #include 
#include
using namespace std;template
struct Node{ char name[20]; T data; Node
*next;};template
class Number{private: int m_length; Node
*head;public: Number(); void m_Init(); //输入n个学生数据 void m_Insert(); //在表中s的位置插入x void m_Find_Loc(); //在表中查找序号为i的元素 void m_Find_Val(); //在表中查找值与x相等的元素 void m_Del(); //在表中删除序号为s的元素 void m_Destroy(); //删除成绩表 void m_Show(); //把表中所有元素打印出来 void Choice_menu();};#endif template
Number
::Number(){ head = new Node
; head->next = NULL; m_length = 0;}template
void Number
::m_Init(){ cout << "\n欢迎来到输入记录界面\n" << endl; int n = 0; Node
*p, *q; q = head; if (head->next != NULL) head->next = NULL; cout << "请设置你要输入客户记录的数目:"; cin >> n; for (int i = 0; i < n; i++) { p = new Node
; cout << "\n请输入第" << i + 1 << "位客户的名字和号码(用空格号隔开):"; cin >> p->name >> p->data; q->next = p; q = p; q->next = NULL; m_length++; } cout << "\n客户信息输入完毕." << endl; cout << "\n"; this->m_Show(); system("pause"); //暂停 system("cls"); //清屏 }template
void Number
::m_Insert(){ cout << "\n欢迎来到插入记录界面\n" << endl; this->m_Show(); int s; Node
*p, *t; p = head; cout << "请输入你想要插入客户记录的位置:"; cin >> s; while (s <= 0 || s > m_length + 1) { cout << "\n插入的位置不正确,请重新输入一个正确的位置:"; cin >> s; } for (int i = 0; i < s - 1; i++) p = p->next; t = new Node
; cout << "\n请输入你想插入的客户名和号码(用空格号隔开):"; cin >> t->name >> t->data; t->next = p->next; p->next = t; m_length++; cout << "\n客户记录插入完毕." << endl; cout << "\n"; this->m_Show(); system("pause"); system("cls");}template
void Number
::m_Find_Loc(){ cout << "\n欢迎来到按系统默认编号查找界面\n" << endl; this->m_Show(); int s; Node
*p; p = head; cout << "请输入你想要查找的客户记录的位置:"; cin >> s; while (s <= 0 || s > m_length) { cout << "\n你输入的编号有误,请重新输入一个正确的编号:"; cin >> s; } for (int i = 0; i < s; i++) p = p->next; cout << "\n你想要查找的客户和号码为:"; cout << p->name << setw(6) << p->data << endl; cout << "查找完毕." << endl; system("pause"); system("cls");}template
void Number
::m_Find_Val(){ cout << "\n欢迎来到按客户号码查找界面\n" << endl; // this->m_Show(); //加了这句话,将在按号查找中显示出客户的名字与号码. bool t = false; int i = 1; Node
*p; p = head->next; T x; cout << "请输入想要查找的号码:"; cin >> x; while (p != NULL) { if (x == p->data) { cout << "\n你查找的号码的客户名为:" << p->name << endl; t = true; } p = p->next; i++; } if (t == false) cout << "\n没有符合条件的客户记录." << endl; system("pause"); system("cls");}template
void Number
::m_Del(){ cout << "\n欢迎来到删除记录界面\n" << endl; this->m_Show(); int s; Node
*p, *q; p = head; cout << "请输入你想要删除的客户的位置为:"; cin >> s; while (s <= 0 || s > m_length) { cout << "\n你输入的客户位置有误,请重新输入一个正确的客户位置:"; cin >> s; } for (int i = 0; i < s - 1; i++) p = p->next; q = p->next; p->next = q->next; cout << "\n你删除的客户和号码为:"; cout << q->name << setw(6) << q->data << endl; delete q; m_length--; cout << "\n删除完毕." << endl; cout << "\n"; this->m_Show(); system("pause"); system("cls");}template
void Number
::m_Destroy(){ Node
*p, *q; p = head; q = p; for (int i = 0; i < m_length; i++) { q = q->next; delete p; p = q; } m_length = 0; cout << "\n记录表清空完毕.\n" << endl;}template
void Number
::m_Show(){ if (head->next == NULL) { cout << "\n记录表里数据为空,显示操作失败!!"; return; } Node
*p; p = head->next; cout << "\n记录表中所有客户和号码为:" << endl; while (p != NULL) { cout << "客户姓名:" << p->name << setw(20) << "客户号码:" << p->data << endl; p = p->next; } cout << endl; cout << "\n\n";}template
void Number
::Choice_menu(){ int ch; cout << "┏----------------------------------------------------------------------------┓"; cout << "┃ ┃"; cout << "┃ ┏---------------------------客户通话管理-------------------------------┓ ┃"; cout << "┃ ┃ ┃ ┃"; cout << "┃ ┃ ┃ ┃"; cout << "┃ ┃ 1. 输 入 记 录 ┃ ┃"; cout << "┃ ┃ 2. 插 入 记 录 ┃ ┃"; cout << "┃ ┃ 3. 按系统默认编号查找 ┃ ┃"; cout << "┃ ┃ 4. 按客户号码查找 ┃ ┃"; cout << "┃ ┃ 5. 删 除 记 录 ┃ ┃"; cout << "┃ ┃ 6. 清 空 记 录 ┃ ┃"; cout << "┃ ┃ 0. 退 出 ┃ ┃"; cout << "┃ ┃ ┃ ┃"; cout << "┃ ┗----------------------------------------------------------------------┛ ┃"; cout << "┗----------------------------------------------------------------------------┛"; cout << " "; cout << " "; cout << "请选择你要执行的选项:"; cin >> ch; while (ch != 1 && ch != 2 && ch != 3 && ch != 4 && ch != 5 && ch != 6 && ch != 0){ cout << "\n没有该选项,请重新选择." << endl; cout << "\n请选择你要执行的选项:"; cin >> ch; } switch (ch){ case 1: system("cls"); this->m_Init(); break; case 2: system("cls"); this->m_Insert(); break; case 3: system("cls"); this->m_Find_Loc(); break; case 4: system("cls"); this->m_Find_Val(); break; case 5: system("cls"); this->m_Del(); break; case 6: system("cls"); this->m_Destroy(); break; case 0: cout << "\n 感谢您的使用!\n" << endl; exit(EXIT_FAILURE); //用于退出操作 }}
 

2.创建源文件:在工程“yangy”中新建一个源文件“link_main.cpp”,该源文件包含以下代码:

#include "link_number.h"    #include 
using namespace std;int main(){ Number
ss; while (1) ss.Choice_menu(); return 0; }

3.程序运行结果

6,心得体会

通过一段时间的学习与总结,我对数据结构的概念已经有了一个大体上的认识,但是实践能力还比较薄弱。看到这个题目后我想到了运用C++中的选择结构,类模板以及构造函数。还有数据结构里面的线性表来储存数据。但是由于在C++和数据结构之间的衔接不够紧密。导致自己无法完整的编写代码。以上代码都是转载的同学的(转载于HK315的专栏,涉及侵权问题定会私下协商)。我认真研究了以上代码,并实际运行了几遍,代码能够很好的实现以上几个功能,我也深切体会到了线性表在实际应用中的便利性,但我也发现了代码中的一点小漏洞,在按照号码查找人员的操作中如果用户错误的进行了非数字输入,例如输入了一个人名,此程序没有与之对应的纠错输出。在其他查找中也存在这个问题,计算机无法识别下一步操作就会进入死循环。感觉自己在操作实践上花费的时间太少,这个假期要好好敲代码。争取能够做到脱离课本。还请老师多多照顾,已经尽力了大哭奋斗

你可能感兴趣的文章
LOCAL_PRELINK_MODULE和prelink-linux-arm.map
查看>>
Simple Guide to use the gdb tool in Android environment
查看>>
Netconsole to capture the log
查看>>
Build GingerBread on 32 bit machine.
查看>>
How to make SD Card world wide writable
查看>>
Detecting Memory Leaks in Kernel
查看>>
Linux initial RAM disk (initrd) overview
查看>>
Timestamping Linux kernel printk output in dmesg for fun and profit
查看>>
There's Much More than Intel/AMD Inside
查看>>
CentOS7 安装MySQL 5.6.43
查看>>
使用Java 导入/导出 Excel ----Jakarta POI
查看>>
本地tomcat 服务器内存不足
查看>>
IntelliJ IDAE 2018.2 汉化
查看>>
Openwrt源码下载与编译
查看>>
我和ip_conntrack不得不说的一些事
查看>>
Linux 查看端口使用情况
查看>>
文件隐藏
查看>>
两个linux内核rootkit--之二:adore-ng
查看>>
两个linux内核rootkit--之一:enyelkm
查看>>
关于linux栈的一个深层次的问题
查看>>