1、面向对象C+实验报告 基于多态性的人员信息管理系统C+ 程序设计实验报告C+ Experiment Report(燕山大学 信息科学与工程学院)学 生 姓 名 :孙佳艺 郭秋君 许静静 房甜甜 课题组分工及贡献:全组合作完成源代码编写 程序调试与修改:许静静 25% PPT制作:郭秋君 25% PPT讲演:孙佳艺 25% 实验报告:房甜甜 25% 课 程 名 称 : 面向对象程序设计 指 导 教 师 : 周军锋、陈琦 2015年 4 月 基于多态性的人员信息管理系统摘要:本系统是一个学生成绩管理系统,输入内容包括:姓名,性别,分数,学号等。本项目用双向链表来实现添加结点、删除结点、输出、查询、
2、修改等功能。添加结点用new动态分配内存,结点数据以数组形式存放。链表数据的初始化用new动态分配内存,链表元素用指针来指向动态分配的内存空间。链表中包含2个类Node类和CList类,Node类的构造函数负责结点本身的初始化,CList类构造函数负责整个链表的初始化。从CList类派生出Stack和Queue,用派生类的知识实现正逆序的输出。从CList类派生Set类,来实现差“”,并”+”union,交and三种操作,用运算符的重载来实现对两个链表的操作,从而得知并、交、差操作并不影响参与操作的集合。前言:到本学期为止,在老师们的讲解下,学生已经学习了C、C+两门计算机语言和数据结构,具备
3、用计算机解决一定难度问题的本领,但自主、系统地编写代码解决某个问题,还缺乏实战练习,本项目的进行是学生对已学知识的有效巩固与练习。项目是以小组为单位上交成果,本形式可以增强学生团队分工、协作能力,创造学生相互学习的机会。学生管理系统也是一个教育单位不可缺少的部分,它的内容对于学校管理者来说是至关重要的,能有效的帮助学校和老师掌握学生的情况。所以练习这个题目的项目也有实在意义。1 研究报告正文1.1 实现思路:本系统采用VC+6.0编译器作为开发环境,这个环境是我们在学习C+的平台。用户可以自行输入数据,在输入学生数据时要保证输入数据格式的正确性,系统不会自动检测输入数据是否正确,可用。输出形式
4、与输出形式类似,根据需要可以选择显示输入的各项内容。1.1.1 程序流程图:1.2 模块实现1.2.1 建立双向链表class Node; class CList;1.2.2 建立双向链表的派生类 class Stack:public CList; class Queue:public CList; class Set:public CList public: friend CList operator+(CList a,CList b); friend CList operator-(CList a,CList b); friend CList operator&(CList a,CList
5、 b); ;1.2.3 构造函数 Node():Constructs an new node. CList():Constructs an empty ordered list.1.2.4 获得头/尾指针 GetHead:Returns the head element of the list GetTail:Returns the tail element of the list1.2.5 链表操作 creat_head(Node *s); :Adds an element to the head of the list (makes a new head). creat_CList();
6、show_CList(CList L);1.2.6 遍历操作 GetNext: Gets the next element for iterating. GetPrev:Gets the previous element for iterating.1.2.7 检索/修改操作 GetAt: Gets the element at a given position. SetAt: Sets the element at a given position. RemoveAt Removes an element from this list, specified by position.1.2.8
7、 插入操作 InsertAfter:Inserts a new element after a given position.1.2.9 查询操作 Find:Gets the position of an element specified by pointer value. FindIndex:Gets the position of an element specified by a zero-based Index.1.2.10 建立主菜单 int main() CList L; CList L1,L2; Queue Q1; Stack S1; while(1) cini; switch
8、(i) case 1:(建立学生记录) case 2:(插入学生记录 ) case 3:(查询学生记录) case 4:(删除学生记录) case 5:(输出学生记录 ) case 6:(修改学生记录) case 7:(学生记录并集) case 8:(学生记录差集) case 9:(学生记录交集) case 10:(队列式查询) case 11:(栈式查询) case 12:(退出管理系统) 1.3 源代码:#include /定义活动文本模式窗口,刷新功能system(cls)清屏函数 ;#include #include#include /跟时间日期有关using namespace st
9、d;class Node public: char name10; char sex10; int num; int score; Node *pre; Node *next; Node(); void init_node(); Node();/*Node :Node() pre=NULL; next=NULL;Node:Node()/*void Node:init_node() cout 请输入学生的学号:num; cout 请输入学生的姓名:name; cout 请输入学生的性别:sex; cout 请输入学生的分数:score;/* class CList public: int len
10、gth; Node* PHead; Node* PTail; CList(Node *head=NULL,Node *tail=NULL); Node *get_head(); Node *get_tail(); Node *GetPrev(Node *p); Node *GetNext(Node *p); Node *GetAt(Node *head,int n); void creat_head(Node *s); void creat_CList(); void show_CList(CList L); void SetAt(Node *head,int n); void RemoveA
11、t(Node *head,int n); void InsertAfter(Node *head,int n); int Find(Node *head,Node *s); int FindIndex(Node *head,int e); CList();/*CList:CList(Node* head,Node *tail) PHead=head; PTail=tail; CList:CList()/*Node* CList:get_head() return PHead;/*Node* CList:get_tail() return PTail;Node* CList:GetPrev(No
12、de *p) Node *q=p; q=q-pre; return q;Node* CList:GetNext(Node *p) Node *q=p; q=q-next; return q;/*Node * CList:GetAt(Node *head,int n) Node *p=head; int i=1; while(inext; i+; return p;/*void CList:creat_head(Node *s) PHead=s;void CList:creat_CList() coutlength; PHead=new Node; Node *p,*q; p=q=PHead;
13、p-init_node(); for(int i=1;iinit_node(); p-next=q; q-pre=p; p=q; PTail=q; /*void CList:show_CList(CList L) Node *head; head=L.get_head(); while(head) cout 学号:numt姓名:namet性别:sext分数:scorenext; /*void CList:SetAt(Node *head,int n) Node *p=head; int i=1; Node *q=new Node; q-init_node(); while(inext; i+;
14、 q-next=p-next; p-next-pre=q; q-pre=p; p-next=q;/*void CList:RemoveAt(Node *head,int n) Node *p=head; Node *q; int i=1; while(inext; i+; q=p-next; q-next-pre=p; p-next=q-next;/*void CList:InsertAfter(Node *head,int n) Node *p=head; int i=1; Node *q=new Node; q-init_node(); while(inext; i+; q-next=p-
15、next; p-next-pre=q; q-pre=p; p-next=q;/*int CList:Find(Node *head,Node *s) Node *p=head; while(p!=s) p=p-next; return p-num;/*int CList:FindIndex(Node *head,int e) Node *p=head; while(p-num!=e) p=p-next; return p-num;/*class Stack:public CListpublic: Stack(); Node *get_top(); void push(); void show_
16、Stack(Node *top); Node *top; ;/*Stack:Stack() top=get_tail(); /*Node *Stack:get_top() return top;/* void Stack:push() int i,m; cout 【入栈】请输入入栈长度(结点数):m; for(i=0;iinit_node(); p-next=top; top=p; /*void Stack:show_Stack(Node *top) cout 【出栈】栈内全部信息:endl; Node *p=top; while(p) cout 学号:numt姓名:namet性别:sext分
17、数:scorenext; /*class Queue:public CList private: Node *front; Node *rear; public: Queue(); void EnQueue(); void DeQueue(); /*Queue:Queue() front=get_head(); rear=get_tail(); /*void Queue:EnQueue() int i,m; cout 【入队】请输入队列长度(结点数):m; for(i=0;iinit_node(); p-next=NULL; rear-next=p; rear=p; else Node *p=
18、new Node; p-init_node(); p-next=NULL; front=rear=p; /*void Queue:DeQueue() /头出队 int i,m; cout 【出队】请输入输出队列长度(结点数)m; for(i=0;im;i+) if(front) cout 学号:numt姓名:namet性别:sext分数:scorenext; else cout队为空!name,p-name); strcpy(r-sex,p-sex); r-num=p-num; r-score=p-score; if(i=0) La.creat_head(r); s=r; i+; else s
19、-next=r; s=r; p=p-next; p=a.get_head(); while(q) while(p) if(p-num=q-num) if(q-next) q=q-next; p=a.get_head(); else return La; else p=p-next; Node *r=new Node; strcpy(r-name,q-name); strcpy(r-sex,q-sex); r-num=q-num; r-score=q-score; if(i=0) La.creat_head(r); s=r; i+; else s-next=r; s=r; q=q-next; p
20、=a.get_head(); return La;/*CList operator-(CList a,CList b) CList La; Node *s; int i=0; Node *p=a.get_head(); Node *q=b.get_head(); if(p-num=q-num) p=p-next; while(p) while(q) if(p-num=q-num) if(p-next) p=p-next; q=b.get_head(); else s-next=NULL; return La; else q=q-next; Node *r=new Node; strcpy(r-
21、name,p-name); strcpy(r-sex,p-sex); r-num=p-num; r-score=p-score; if(i=0) La.creat_head(r); s=r; i+; else s-next=r; s=r; q=b.get_head(); p=p-next; return La; /*CList operator&(CList a,CList b) CList La; int i=0; Node *r=NULL; Node *p=a.get_head(); Node *q=b.get_head(); while(p) while(q) if(p-num=q-num) if(i=0) La=p; r=p; i+;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1