码迷,mamicode.com
首页 > 其他好文 > 详细

本科生导师制 问题

时间:2014-06-11 07:56:59      阅读:2165      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   ext   color   

①问题描述

在高校的教学改革中,有很多学校实行了本科生导师制。一个班级的学生被分给几个老师,每个老师带n个学生,如果该老师还带研究生,那么研究生也可直接带本科生。本科生导师制问题中的数据元素具有如下形式:

  • 导师带研究生
    (老师,((研究生1,(本科生1,…,本科生m1)),(研究生2,(本科生1,…,本科生m2))…))

  • 导师不带研究生
    (老师,(本科生1,…,本科生m))

导师的自然情况只包括姓名、职称;研究生的自然情况只包括姓名、班级;本科生的自然情况只包括姓名、班级。

②基本要求

要求完成以下功能:

  • 建立:建立导师广义表。

  • 插入:将某位本科生或研究生插入到广义表的相应位置。

  • 删除:将某本科生或研究生从广义表中删除。

  • 查询:查询导师、本科生(研究生)的情况。

  • 统计:某导师带了多少个研究生和本科生。

  • 输出:将某导师所带学生情况输出。

  • 退出:程序结束。

③设计提示

本实验使用的数据结构是广义表,广义表采用头尾链表存储结构来实现。

定义教师、学生结点结构体如下:

typedef struct GLNode

{

char name[100]; /*教师或学生的姓名*/

char prof[100]; /*教师结点表示职称,学生结点表示班级*/

int type; /*结点类型:0-教师,1-研究生,2-本科生*/

struct {struct GLNode *hp, *tp;} ptr;

/*hp指向同级的下一结点,tp指向下级的首结点*/

}GList;

人员信息的表示形式为:高老师-教授-0、李刚-二班-1、李明-二班-2.

人员信息中的姓名、职称、班级、人员类型用“-隔开,如高老师-教授-0,“高老师”表示姓名,“教师”表示职称,“0表示人员的类型是教师;李刚-二班-1,“李刚”表示姓名,“二班”表示班级,“1表示人员的类型是研究生;李明-二班-2,“李明”表示姓名,“二班”表示班级,“2表示人员的类型是本科生。

广义表((高老师-教授-0,(李明-一班-2,王平-二班-2)),(李老师-副教授-0,(白梅-二班-1,(李刚-一班-2)))可以用图3表示。

 

3 导师制用广义表实现示例

④思考

可以考虑对程序做如下完善:

  • 可以将学生从一个导师组转到另一个导师组。

  • 可以在同一个导师组内修改本科生的研究生负责人。

  • 当研究生带本科生时,如果要删除该研究生,可根据情况,将本科生平均分配给该导师的其他研究生,如果没有其他研究生,则由导师直接负责。

  • 增加删除导师的功能。

  • 查询时,如果待查人员是导师,除了输出本人信息外,还输出他所指导的学生信息;如果待查人员是研究生,除了输出其导师和本人信息外,还输出他所负责的本科生信息。

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include<iostream>
#include<string.h>
using namespace std;
class LS
{
private:
    struct Node//建立结点
    {
        string name;
        string prof;
        int type;
        Node * right,*down;//每个节点有向右和向下的指针
        Node():right(NULL),down(NULL) {}
        Node(string name1 , string prof1 , int a)
        {
            name = name1;
            prof = prof1;
            type = a;
            right = NULL;
            down = NULL;
        }
    };
    Node * head;
    Node * cur;
public:
    int number0 = 0 ,number1 = 0,number2 = 0;//教授人数、导师人数、学生人数
    int nameflag = 0;//名字标记
    LS()
    {
        Node * p = new Node();//建立头节点
        head = p;
    }
    void dfs(Node * cur)//dfs
    {
            if(cur->type==0)
            {
            number0++;
            cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
            }
            if(cur->type==1)
            {
            number1++;
            cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
            }
            if(cur->type==2)
            {
            number2++;
            cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
            }
            if(cur->right)dfs(cur->right);
            if(cur->down)dfs(cur->down);
    }
    Node *findname(Node * cur,string name)//查询姓名
    {
        if(cur->name==name){cout<<"find"<<endl;
        cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
        nameflag = 1;
        return cur;}
        if(cur->right)findname(cur->right,name);
        if(cur->down)findname(cur->down,name);
        if(nameflag == 0)return 0;
    }
    void all_function()
    {
        cout<<"please input boss‘s name prof type"<<endl;
        string Name,Prof;
        int Type;
        cin>>Name>>Prof>>Type;
        Node * p = new Node(Name,Prof,Type);//输入第一个节点
        head -> down = p;
        cur = p;
        while(1)
        {
            cout<<"please input:"<<endl;
            cout<<"1 show now node"<<endl;//打印当前节点信息
            cout<<"2 insert right"<<endl;//在当前节点往右插入
            cout<<"3 insert down"<<endl;//在当前节点往下插入
            cout<<"4 return boss"<<endl;//返回头节点
            cout<<"5 moveright"<<endl;//当前节点往右移动
            cout<<"6 movedown"<<endl;//当前节点往下移动
            cout<<"7 delete now Node"<<endl;//删除当前节点
            cout<<"8 tongji now node renshu"<<endl;//统计所有结点
            cout<<"9 chaxun xingming"<<endl;//查询姓名
            cout<<"10 print all student"<<endl;//打印当前节点的所有学生
            cout<<"0 break"<<endl;//结束循环
            int n;
            cin>>n;
            if(n==0)break;
            string Name,Prof;
            int Type;
            switch (n)
            {
            case 1://打印当前节点信息
            {
                cout<<"now Node is:"<<endl;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                break;
            }
            case 2://在当前节点往右插入
            {
                cout<<"now Node is:"<<endl;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                cout<<"please input right numbers"<<endl;//插入几个
                int insertright;
                cin>>insertright;
                for(int i = 0 ; i < insertright ; i++)
                {
                    cout<<"please input Node name prof type"<<endl;
                    cin>>Name>>Prof>>Type;
                    Node * p = new Node(Name,Prof,Type);
                    cur->right = p;
                    cur = cur -> right;
                }
                cur = head -> down;
                break;
            }
            case 3://在当前节点往下插入
            {
                cout<<"now Node is:"<<endl;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                cout<<"please input down numbers"<<endl;//插入几个
                int insertdown;
                cin>>insertdown;
                for(int i = 0 ; i < insertdown ; i++)
                {
                    cout<<"please input Node name prof type"<<endl;
                    cin>>Name>>Prof>>Type;
                    Node * p = new Node(Name,Prof,Type);
                    cur->down = p;
                    cur = cur -> down;
                }
                cur = head -> down;
                break;
            }
            case 4://返回头节点
            {
                cur = head->down;
                break;
            }
            case 5://当前节点往右移动
            {
                cout<<"now Node is:"<<endl;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                cout<<"after movedown Node is:"<<endl;
                cur = cur -> right;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                break;
            }
            case 6://当前节点往下移动
            {
                cout<<"now Node is:"<<endl;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                cout<<"after movedown Node is:"<<endl;
                cur = cur -> down;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                break;
            }
            case 7://删除当前节点
            {
                cout<<"the Node will be delete is:"<<endl;
                cout<<cur->name<<" "<<cur->prof<<" "<<cur->type<<endl;
                int flag1 = 0,flag2 = 0;
                Node * p1;
                Node * p2;
                if(cur -> right !=NULL)
                {
                    p1 = cur -> right;
                    flag1 = 1;
                }
                if(cur -> down != NULL)
                {
                    p2 = cur ->down;
                    flag2 = 1;
                }
                if(flag1&&flag2)//右边和下边都有元素的话,把右边的节点赋值给当前要删除的节点,并且把下面的元素连接到当前节点
                {
                    cur -> name = p1 -> name;
                    cur -> prof = p1 -> prof;
                    cur -> type = p1 -> type;
                    delete p1;
                    cur ->down = p2;
                }
                else if(flag1)//只有右边有元素,把右边的节点赋值给当前要删除的节点
                {
                    cur -> name = p1 -> name;
                    cur -> prof = p1 -> prof;
                    cur -> type = p1 -> type;
                    delete p1;
                }
                else if(flag2)//只有下边有元素,把下边的节点赋值给当前要删除的节点
                {
                    cur -> name = p2 -> name;
                    cur -> prof = p2 -> prof;
                    cur -> type = p2 -> type;
                    delete p2;
                }
                break;
            }
            case 8://统计所有结点
            {   number0 = 0;number1 = 0;number2 = 0;
                dfs(cur);
                cout<<"jiaoshou yanjiusheng xuesheng number:"<<number0<<" "<<number1<<" "<<number2<<endl;
                break;
            }
            case 9://查询姓名(dfs)
            {
                string name;
                cout<<"please chaxun name"<<endl;
                cin>>name;
                if(!findname(cur,name))
                {
                   cout<<"can not find"<<endl;
                }
                nameflag = 0;
                break;
            }
            case 10://打印当前节点的所有学生
            {
                dfs(cur);
                break;
            }
 
            }
        }
 
    }
 
};
int main()
{
    LS dusk;
    dusk.all_function();
}

  

本科生导师制 问题,布布扣,bubuko.com

本科生导师制 问题

标签:style   class   blog   code   ext   color   

原文地址:http://www.cnblogs.com/Duskcl/p/3773580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!