zoukankan      html  css  js  c++  java
  • 20200708 千锤百炼软工人第三天

    今天是第三天

    今天的任务完成不理想

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

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

    其主要功能有

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

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

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

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

    #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学习的进度
     
  • 相关阅读:
    ajax 笔记--调用WebService实现求两数之和
    多数据之间的连接操作集中几个.NET常用的方法(不完整)
    判断用户是否存在(通过参数来实现)
    我的机子放到公司了
    给同事过生日,我弄菜,给同事买饭,我值班。
    多数据之间的连接操作MSSQL(不完整)
    TreeView连接数据
    字符编码
    计算机基础
    python入门
  • 原文地址:https://www.cnblogs.com/huangmouren233/p/13268526.html
Copyright © 2011-2022 走看看