我的学习记录36

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 = new Node;

                          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;

}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值