ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

20200708 千锤百炼软工人第三天

2020-07-08 18:35:20  阅读:246  来源: 互联网

标签:ListNode cout sex 第三天 next phone 千锤百炼 20200708 name


今天是第三天

今天的任务完成不理想

今天的任务是完成一个通讯录程序

其储存方式就是需要应用链表来实现

其主要功能有

创建,显示,修改,插入,删除,文件的导入,文件的导出。

其中前五个功能基本完成,后两个功能还没实现。

但是前五个功能的程序设计基本完成但是具体实现阶段不理想

花费了很长时间来改错,但是最终虽然没有了错误但是实现起来还是有所偏差

#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
const int MAX_N = 100;
typedef struct user{
            unsigned m_id;
            string m_name;
            unsigned m_age;
            string m_sex;
            long m_Hphone;
            long m_phone;
}user;
typedef class User
{
    public:
         unsigned m_id;
            string m_name;
            unsigned m_age;
            string m_sex;
            long m_Hphone;
            long m_phone;
            class User *next;
}ListNode;
class List
{
    public:         List(struct user *a, int n)
        {
            ListNode *p, *s;
            int i;
            L = (ListNode *)malloc(sizeof(ListNode));
            p = L;
            for (i = 0; i < n; i++)
                {
                    s = (ListNode *)malloc(sizeof(ListNode));
                    s->m_id = a[i].m_id;
                    s->m_name = a[i].m_name;
                    s->m_age = a[i].m_age;
                    s->m_sex = a[i].m_sex;
                    s->m_Hphone = a[i].m_Hphone;
                    s->m_phone = a[i].m_phone;
                    p->next = s;
                    p = s;
                    cout<<"建立完成!"<<endl;
                }
            p->next = NULL;
            cout<<"建立完成!3"<<endl;         }
        ~List(){
                ListNode *pre = L, *p = L->next;
                while (p->next != NULL)
                {
                free(pre);
                pre = p;
                p = pre->next;
                }
                free(pre);
                }
        bool isEmpty()
        {
            return (L->next == NULL);
        }
        int getLength()
        {
            ListNode *p = L;
            int i = 0;
            while (p->next != NULL)
            {
                i++;
            p = p->next;
            }
            return i;
        }
        void DisplayList(){
        ListNode *p = L->next;
        while (p != NULL){
                cout << p->m_id<<" "<<p->m_name<<" "<<p->m_age<<" "<<p->m_sex<<" "<<p->m_Hphone<<" "<<p->m_phone<<endl;
        p = p->next;
                        }
         cout << endl;
            }
        bool getElem(string &N, unsigned &id,unsigned &age,string &name,string &sex,long &Hphone,long &phone){
              ListNode *p = L;
                    while (N.compare(p->m_name)&&p->next != NULL){
                    p = p->next;  }
                    if (N.compare(p->m_name)&&p->next == NULL){
                            return false;
                    }
                    else{
                                    id = p->m_id;
                                    age=p->m_age;
                                    name=p->m_name;
                                    sex=p->m_sex;
                                    Hphone=p->m_Hphone;
                                    phone=p->m_phone;
                                    return true;
                    }
                    }
        int LocateElem(long &elem){
                ListNode *p = L;
                int i = 0;
                while (elem == p->m_phone&&p->next != NULL){
                        i++;
                      p = p->next;
                        }
                if (elem==p->m_phone&&p->next == NULL){
                    return 0;
                    }
                else{
                    return i;
                    }
                    }
        private:
            ListNode *L;
    };
    int main()
    {         ListNode *m_node;
        int n,i;
        user a[MAX_N];
        string name,sex,N;
        long Hphone,phone,elem;
        string q;
        unsigned age,id;
        cout << "Input the length:" <<endl;
        cin >> n;
        for (i = 0; i < n; i++)
            {
                cin >> a[i].m_id;
                cin >> a[i].m_name;
                cin >> a[i].m_age;
                cin >> a[i].m_sex;
                cin >> a[i].m_Hphone;
                cin >> a[i].m_phone;
                cout<<"下一位用户信息:"<<endl;
            }
        List m_list(a, n);
        m_list.DisplayList();
        if (!m_list.isEmpty())
            {
                cout << "it is not empty." << endl;
                cout << "The length:" << m_list.getLength() << endl;
            }
        else{
                cout << "It is empty." << endl;
            }
        cout << "Input number:" << ends;
        cin >> q;
        if (m_list.getElem(q,id,age,name,sex,Hphone,phone))
        {
        cout << "NO. " << id <<" ,the name is"<<name<<" ,the age is"<<age<<" ,the sex is"<<sex<<" ,the Hphone is"<<Hphone<<" ,the phone is"<<phone<<endl;
        }
        else
        {
        cout << "error number or not contained." << endl;
        }
        cout << "Input the data:" << ends;
        cin >> elem;
        if (m_list.LocateElem(elem) == 0)
            {
                cout << "Not contained." << endl;
        }
        else
        {
            cout << "The location is No. " << m_list.LocateElem(elem) << endl;
        }
        } 具体的代码在此奉上 希望有位大佬可以稍微指点一二 今天的java学习稍微落后一点 学习的比较少 所以也就没办法在此详细记录 明天继续完成小学期任务,并赶上Java学习的进度  

标签:ListNode,cout,sex,第三天,next,phone,千锤百炼,20200708,name
来源: https://www.cnblogs.com/huangmouren233/p/13268526.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有