我的学习记录36

来源:互联网 发布:手机相片日期软件 编辑:程序博客网 时间:2024/06/06 00:17

2017.11.15李锦浩【第36天】

今天完成了前天未完成的程序,由于时间原因没能挑食完成,可能还存在着一部分编译问题,需要进一步找寻bug。另外今天学习了关于类的定义和知识。

附:职工统计表:

//luru.h

#pragma once

#include<iostream>

using namespace std;

struct Node

{

         char name[64];

         unsigned int id;

         int age;

         int sex;

         Node*next;

};

void CreateList(Node*&head)

{

         cout << "请输入总人数:";

         int n;

         cin >> n;

         Node*s,*p;

         s = new Node;

         p = new Node;

         cout << "请输入姓名:";

         cin >> s->name;

         cout << "请输入工号:";

         cin >> s->id;

         cout << "请输入年龄:";

         cin >> s->age;

         cout << "请输入性别,1表示男,2表示女:";

         cin >> s->sex;

         for(int o=1;o<=n;)

         {

                  if (head ==NULL)

                          head = s;

                  else

                  {

                          p->next = s;

                          p = s;

                          s = newNode;

                          cout <<"请输入姓名:";

                          cin >> s->name;

                          cout <<"请输入工号:";

                          cin >> s->id;

                          cout <<"请输入年龄:";

                          cin >> s->age;

                          cout <<"请输入性别,1表示男,2表示女:";

                          cin >> s->sex;

                  }

         }

         p->next = NULL;

         delete s;

         delete p;

}

void ShowList(Node*head)

{

         while (head->next)

         {

                  cout << head->name << endl << head->id << endl<< head->age << endl << head->sex;

                  head = head->next;

         }

         cout << endl;

}

void insert(Node*head)

{

         Node*s;

         s = new Node;

         cout << "请输入姓名:";

         cin >> s->name;

         cout << "请输入工号:";

         cin >> s->id;

         cout << "请输入年龄:";

         cin >> s->age;

         cout << "请输入性别,1表示男,2表示女:";

         cin >> s->sex;

         while (!head->next)

         {

                  head = head->next;

         }

         head->next = s;

         delete s;

}

void statustics(Node*head)

{

         int man = 0, woman = 0;

         while (!head->next)

         {

                  if (head->sex == 1)

                          man++;

                  if (head->sex == 2)

                          woman++;

                  head = head->next;

         }

         cout << "男员工人数为"<< man << endl << "女员工人数为"<< woman<<endl;

}

void deleteid(Node*head)

{

         cout << "请输入想要删除的工人ID编号:";

         unsigned int i;

         cin >> i;

         while (head->next)

         {

                  Node*s;

                  if (head->id == i)

                  {

                          s = head->next;continue;

                  }

                  s = head;

                  head = head->next;

         }

         head = head->next;

}

void deletex(Node*head,Node*p)

{

         while (head->next)

         {

                  Node*s;

                  s = head;

                  head = head->next;

            if (head->sex == 1)

                  {

                          if (head->age >60)

                          {

                                   p->next =head;

                                   p =head;

                                   s = head->next;

                          }

                  }

                  if (head->sex == 2)

                  {

                          if (head->age >55)

                          {

                                   p->next =head;

                                   p =head;

                                   s = head->next;

                          }

                  }

         }

}

void ShowListx(Node*p)

{

         while (p)

         {

                  cout << p->name << endl <<p->id<< endl << p->age << endl <<p->sex;

                  p = p->next;

         }

         cout << endl;

}

//yuan.cpp

#include<iostream>

#include"录入.h"

using namespace std;

int main()

{

         Node*head=NULL, *p=NULL;

         CreateList(head);

         ShowList(head);

         insert(head);

         deleteid(head);

         deletex(head, p);

         ShowListx(p);

         system("pause");

         return 0;

}

明日任务:继续编写关于集合的程序,学习类的知识。

原创粉丝点击