课程设计报告 题目4

<p align="center" style="margin: 3pt 0cm; text-align: center; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><strong>数据结构程序设计</strong><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"> <o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-size: 9pt;">一、实训目的</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-size: 9pt;">通过课程设计,学会运用数据结构知识,针对具体应用,自己设计合理数据结构,确定存储结构,并能设计具体操作算法,选择使用具体语言进行实现。掌握</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">C++</span><span style="font-size: 9pt;">较复杂程序的组织和设计过程,调试技巧。学习解决实际问题的能力。</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"> <o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-size: 9pt;">二、问题描述</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">    </span><span style="font-size: 9pt;">赵斌是一个信管专业的学生,大学四年顺利毕业了。在毕业季,他也像其他学子一样,投身于求职大军,投出一份又一份求职简历,在苦苦地等待之后,他接到了中国移动通信公司广东分司的面试通知书,通知他于本月</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">1</span><span style="font-size: 9pt;">号</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">10</span><span style="font-size: 9pt;">点到公司面试。当天,晴空万里,艳阳高照,他身着西装,高兴地早早来到公司楼下等待。</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">10</span><span style="font-size: 9pt;">点钟整,他和其他新人一起,坐到公司的面试现场。他领取的一一份程序设计题:假如你是我公司一名客服技术人员,现请你选择自己熟悉的语言,来设计一个程序,管理客户向公司打进来的咨询电话。</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"> <o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-size: 9pt;">三、要求</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">  1.</span><span style="font-size: 9pt;">请事行分析析使用方法和工具,说明自己的思路方法;</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">  2.</span><span style="font-size: 9pt;">写一份完整的程序,并实例测试。</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"> <o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-size: 9pt;">四、分析</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">1.</span><span style="font-size: 9pt;">使用方法:题目要求使用数据结构的知识来设计一个程序管理客户打进公司的电话,那么管理就应该包括客户信息的输入、查找、删除、清空输入记录等功能。而单链表可以实现上述的功能,因此可以使用从单链表中学到的知识、结合结构体与类来设计一个程序,完成对客户打进公司的电话的管理。</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">2.</span><span style="font-size: 9pt;">实训环境:计算机</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">Windows7</span><span style="font-size: 9pt;">系统,编程软件</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;">MicrosoftVisual C++ 6.0</span><span style="font-size: 9pt;">。</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"> </span></p><p style="margin: 3pt 0cm; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-size: 9pt;">五、实现代码</span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
#include "link_number.h"  
#include <iostream>  
using namespace std;  
  
int main()  
{  
   Number<int> ss;
   while(1)
	   ss.Choice_menu();  
    return 0;  
}  
#ifndef Number_H 
#define Number_H 
#include <iostream>  
#include <iomanip>  
using namespace std;  
  
template <typename T>  
struct Node  
{  
    char name[20];
	T data;  
    Node<T> *next;  
};  
  
template <typename T>  
class Number  
{  
private:  
    int m_length;  
    Node<T> *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 <typename T>  
Number<T>::Number()  
{  
    head = new Node<T>;  
    head->next = NULL;  
    m_length = 0;  
}  
  
template <typename T>  
void Number<T>::m_Init()  
{  
    cout << "\n欢迎来到输入记录界面\n" << endl;  
    int n = 0;  
    Node<T> *p, *q;  
    q = head;  
    if (head->next != NULL)  
        head->next = NULL;  
    cout << "请设置你要输入客户记录的数目:";  
    cin >> n;  
    for (int i = 0; i < n; i++)  
    {  
		
        p = new Node<T>;  
        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 <typename T>  
void Number<T>::m_Insert()  
{  
    cout << "\n欢迎来到插入记录界面\n" << endl;  
    this->m_Show();  
    int s;  
    Node<T> *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<T>;  
    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 <typename T>  
void Number<T>::m_Find_Loc()  
{  
    cout << "\n欢迎来到按系统默认编号查找界面\n" << endl;  
    this->m_Show();  
    int s;  
    Node<T> *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 <typename T>  
void Number<T>::m_Find_Val()  
{  
    cout << "\n欢迎来到按客户号码查找界面\n" << endl;  
   // this->m_Show();        //加了这句话,将在按号查找中显示出客户的名字与号码.
    bool t = false;  
    int i = 1;  
    Node<T> *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 <typename T>  
void Number<T>::m_Del()  
{  
    cout << "\n欢迎来到删除记录界面\n" << endl;  
    this->m_Show();  
    int s;  
    Node<T> *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 <typename T>  
void Number<T>::m_Destroy()  
{  
    Node<T> *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 <typename T>  
void Number<T>::m_Show()  
{  
    if (head->next == NULL)  
    {  
        cout << "\n记录表里数据为空,显示操作失败!!";  
        return;  
    }  
      
    
	Node<T> *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 <typename T>  
void Number<T>::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);                          //用于退出操作
    }  
}  

六、收获和体会及不足

1.收获和体会:我是一个惰性比较强的学生,对于代码方面的学习总是感觉有心无力,无从下手,但是在这次的实践中找到了学习C++、数据结构的信心。在调试的过程里出现过一连串的错误,我通过找书本、百度、问同学一一解决,最后竟然成功地运行了自己编制的代码;不仅仅如此,在这次实验中,我学会了许多我之前不曾掌握的C++知识,也加深巩固了这个学习学的东西,例如单链表等,经过这一次实验,我找到了学习C++的信心,相信在以后的学习中会有更好的动力,希望有更大的突破。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值