面向对象C++实验报告.docx

上传人:b****4 文档编号:27494347 上传时间:2023-07-02 格式:DOCX 页数:38 大小:236.18KB
下载 相关 举报
面向对象C++实验报告.docx_第1页
第1页 / 共38页
面向对象C++实验报告.docx_第2页
第2页 / 共38页
面向对象C++实验报告.docx_第3页
第3页 / 共38页
面向对象C++实验报告.docx_第4页
第4页 / 共38页
面向对象C++实验报告.docx_第5页
第5页 / 共38页
点击查看更多>>
下载资源
资源描述

面向对象C++实验报告.docx

《面向对象C++实验报告.docx》由会员分享,可在线阅读,更多相关《面向对象C++实验报告.docx(38页珍藏版)》请在冰豆网上搜索。

面向对象C++实验报告.docx

面向对象C++实验报告

基于多态性的人员信息管理系统

C++程序设计

实验报告

C++ExperimentReport

(燕山大学信息科学与工程学院)

学生姓名:

孙佳艺郭秋君许静静房甜甜

课题组分工及贡献:

全组合作完成源代码编写

程序调试与修改:

许静静25%

PPT制作:

郭秋君25%

PPT讲演:

孙佳艺25%

实验报告:

房甜甜25%

课程名称:

面向对象程序设计

指导教师:

周军锋、陈琦

2015年4月

 

基于多态性的人员信息管理系统

摘要:

本系统是一个学生成绩管理系统,输入内容包括:

姓名,性别,分数,学号等。

本项目用双向链表来实现添加结点、删除结点、输出、查询、修改等功能。

添加结点用new动态分配内存,结点数据以数组形式存放。

链表数据的初始化用new动态分配内存,链表元素用指针来指向动态分配的内存空间。

链表中包含2个类——Node类和CList类,Node类的构造函数负责结点本身的初始化,CList类构造函数负责整个链表的初始化。

从CList类派生出Stack和Queue,用派生类的知识实现正逆序的输出。

从CList类派生Set类,来实现差“—”,并”+”union,交and三种操作,用运算符的重载来实现对两个链表的操作,从而得知并、交、差操作并不影响参与操作的集合。

前言:

到本学期为止,在老师们的讲解下,学生已经学习了C、C++两门计算机语言和数据结构,具备用计算机解决一定难度问题的本领,但自主、系统地编写代码解决某个问题,还缺乏实战练习,本项目的进行是学生对已学知识的有效巩固与练习。

项目是以小组为单位上交成果,本形式可以增强学生团队分工、协作能力,创造学生相互学习的机会。

学生管理系统也是一个教育单位不可缺少的部分,它的内容对于学校管理者来说是至关重要的,能有效的帮助学校和老师掌握学生的情况。

所以练习这个题目的项目也有实在意义。

 

1研究报告正文

1.1实现思路:

本系统采用VC++6.0编译器作为开发环境,这个环境是我们在学习C++的平台。

用户可以自行输入数据,在输入学生数据时要保证输入数据格式的正确性,系统不会自动检测输入数据是否正确,可用。

输出形式与输出形式类似,根据需要可以选择显示输入的各项内容。

 

1.1.1程序流程图:

 

 

 

1.2模块实现

1.2.1建立双向链表

classNode{…};

classCList{…};

1.2.2建立双向链表的派生类

classStack:

publicCList{…};

classQueue:

publicCList{…};

classSet:

publicCList

{

public:

friendCListoperator+(CLista,CListb);

friendCListoperator-(CLista,CListb);

friendCListoperator&(CLista,CListb);

};

1.2.3构造函数

Node():

Constructsannewnode.

   CList():

Constructsanemptyorderedlist.

1.2.4获得头/尾指针

GetHead:

Returnstheheadelementofthelist

GetTail:

Returnsthetailelementofthelist

1.2.5链表操作

creat_head(Node*s);:

Addsanelementtotheheadofthelist(makesanewhead).

creat_CList();

show_CList(CListL);

1.2.6遍历操作

GetNext:

Getsthenextelementforiterating.

GetPrev:

Getsthepreviouselementforiterating.

1.2.7检索/修改操作

GetAt:

Getstheelementatagivenposition.

SetAt:

Setstheelementatagivenposition.

RemoveAtRemovesanelementfromthislist,specifiedbyposition.

1.2.8插入操作

InsertAfter:

Insertsanewelementafteragivenposition.

1.2.9查询操作

Find:

Getsthepositionofanelementspecifiedbypointervalue.

FindIndex:

Getsthepositionofanelementspecifiedbyazero-basedIndex.

1.2.10建立主菜单

intmain()

{

CListL;

CListL1,L2;

QueueQ1;

StackS1;

while

(1)

{

cin>>i;

switch(i)

{

case1:

(建立学生记录)

case2:

(插入学生记录)

case3:

(查询学生记录)

case4:

(删除学生记录)

case5:

(输出学生记录)

case6:

(修改学生记录)

case7:

(学生记录并集)

case8:

(学生记录差集)

case9:

(学生记录交集)

case10:

(队列式查询)

case11:

(栈式查询)

case12:

(退出管理系统)

}

}

}

1.3源代码:

#include//定义活动文本模式窗口,刷新功能system("cls")清屏函数;

#include

#include

#include//跟时间日期有关

usingnamespacestd;

classNode

{

public:

charname[10];

charsex[10];

intnum;

intscore;

Node*pre;

Node*next;

Node();

voidinit_node();

~Node();

};

//***********************************

Node:

:

Node()

{

pre=NULL;

next=NULL;

};

Node:

:

~Node()

{

}

//***********************************

voidNode:

:

init_node()

{

cout<<"请输入学生的学号:

"<<"\t";

cin>>num;

cout<<"请输入学生的姓名:

"<<"\t";

cin>>name;

cout<<"请输入学生的性别:

"<<"\t";

cin>>sex;

cout<<"请输入学生的分数:

"<<"\t";

cin>>score;

};

//***********************************

classCList

{

public:

intlength;

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,intn);

voidcreat_head(Node*s);

voidcreat_CList();

voidshow_CList(CListL);

voidSetAt(Node*head,intn);

voidRemoveAt(Node*head,intn);

voidInsertAfter(Node*head,intn);

intFind(Node*head,Node*s);

intFindIndex(Node*head,inte);

~CList();

};

//************************************

CList:

:

CList(Node*head,Node*tail)

{

PHead=head;

PTail=tail;

}

CList:

:

~CList()

{

}

//************************************

Node*CList:

:

get_head()

{

returnPHead;

}

//************************************

Node*CList:

:

get_tail()

{

returnPTail;

}

Node*CList:

:

GetPrev(Node*p)

{

Node*q=p;

q=q->pre;

returnq;

}

Node*CList:

:

GetNext(Node*p)

{

Node*q=p;

q=q->next;

returnq;

}

//************************************

Node*CList:

:

GetAt(Node*head,intn)

{

Node*p=head;

inti=1;

while(i

{

p=p->next;

i++;

}

returnp;

}

//************************************

voidCList:

:

creat_head(Node*s)

{

PHead=s;

}

voidCList:

:

creat_CList()

{

cout<<"请输入链表长度(结点数):

";

cin>>length;

PHead=newNode;

Node*p,*q;

p=q=PHead;

p->init_node();

for(inti=1;i

{

q=newNode;

q->init_node();

p->next=q;

q->pre=p;

p=q;

}

PTail=q;

}

//**************************************

voidCList:

:

show_CList(CListL)

{

Node*head;

head=L.get_head();

while(head)

{

cout<<""<<"学号:

"<num<<"\t"<<"姓名:

"<name<<"\t"<<"性别:

"<sex<<"\t"<<"分数:

"<score<

head=head->next;

}

}

//**************************************

voidCList:

:

SetAt(Node*head,intn)

{

Node*p=head;

inti=1;

Node*q=newNode;

q->init_node();

while(i

{

p=p->next;

i++;

}

q->next=p->next;

p->next->pre=q;

q->pre=p;

p->next=q;

}

//******************************************

voidCList:

:

RemoveAt(Node*head,intn)

{

Node*p=head;

Node*q;

inti=1;

while(i

{

p=p->next;

i++;

}

q=p->next;

q->next->pre=p;

p->next=q->next;

}

//*********************************************

voidCList:

:

InsertAfter(Node*head,intn)

{

Node*p=head;

inti=1;

Node*q=newNode;

q->init_node();

while(i

{

p=p->next;

i++;

}

q->next=p->next;

p->next->pre=q;

q->pre=p;

p->next=q;

}

//*********************************************

intCList:

:

Find(Node*head,Node*s)

{

Node*p=head;

while(p!

=s)

p=p->next;

returnp->num;

}

//********************************************

intCList:

:

FindIndex(Node*head,inte)

{

Node*p=head;

while(p->num!

=e)

{

p=p->next;

}

returnp->num;

}

//*******************************************

classStack:

publicCList

{

public:

Stack();

Node*get_top();

voidpush();

voidshow_Stack(Node*top);

Node*top;

};

//********************************

Stack:

:

Stack()

{

top=get_tail();

}

//********************************

Node*Stack:

:

get_top()

{

returntop;

}

//*******************************

voidStack:

:

push()

{inti,m;

cout<<"【入栈】请输入入栈长度(结点数):

"<

cin>>m;

for(i=0;i

{Node*p=newNode;

p->init_node();

p->next=top;

top=p;

}

}

//*******************************

voidStack:

:

show_Stack(Node*top)

{cout<<"【出栈】栈内全部信息:

"<

Node*p=top;

while(p)

{

cout<<""<<"学号:

"<num<<"\t"<<"姓名:

"<name<<"\t"<<"性别:

"<sex<<"\t"<<"分数:

"<score<

p=p->next;

}

}

//***************************************

classQueue:

publicCList

{

private:

Node*front;

Node*rear;

public:

Queue();

voidEnQueue();

voidDeQueue();

};

//***************************************

Queue:

:

Queue()

{

front=get_head();

rear=get_tail();

}

//***************************************

voidQueue:

:

EnQueue()

{inti,m;

cout<<"【入队】请输入队列长度(结点数):

"<

cin>>m;

for(i=0;i

{

if(rear)

{

Node*p=newNode;

p->init_node();

p->next=NULL;

rear->next=p;

rear=p;

}

else

{

Node*p=newNode;

p->init_node();

p->next=NULL;

front=rear=p;

}

}

//*************************************

voidQueue:

:

DeQueue()//头出队

{

inti,m;

cout<<"【出队】请输入输出队列长度(结点数)"<

cin>>m;

for(i=0;i

{

if(front)

{

cout<<""<<"学号:

"<num<<"\t"<<"姓名:

"<name<<"\t"<<"性别:

"<sex<<"\t"<<"分数:

"<score<

front=front->next;

}

else

cout<<"队为空!

"<

}

}

//***************************************

classSet:

publicCList

{

public:

friendCListoperator+(CLista,CListb);

friendCListoperator-(CLista,CListb);

friendCListoperator&(CLista,CListb);

};

//***************************************

CListoperator+(CLista,CListb)

{

CListLa;

Node*s;

inti=0;

Node*p=a.get_head();

Node*q=b.get_head();

while(p)

{

Node*r=newNode;

strcpy(r->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;

}

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

returnLa;

}

else

p=p->next;

}

Node*r=newNode;

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=a.get_head();

}

returnLa;

}

//******************************************

CListoperator-(CLista,CListb)

{

CListLa;

Node*s;

inti=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;

returnLa;

}

}

else

q=q->next;

}

Node*r=newNode;

strcpy(r->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;

}

returnLa;

}

//*************************************************

CListoperator&(CLista,CListb)

{

CListLa;inti=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