链表报告文档格式.docx
- 文档编号:19611082
- 上传时间:2023-01-08
- 格式:DOCX
- 页数:20
- 大小:78.65KB
链表报告文档格式.docx
《链表报告文档格式.docx》由会员分享,可在线阅读,更多相关《链表报告文档格式.docx(20页珍藏版)》请在冰豆网上搜索。
1、源文件:
#include<
iostream.h>
#include"
menu.h"
voidmain()
{
List<
Student>
ob1;
Studentob2;
Menuob3;
ob3.mean(ob1,ob2);
}
2、头文件:
1)、date类
classdate
{
public:
intyear,month,day;
date(void)
{
year=1980;
month=1;
day=1;
}
date(inty,intm,intd)
year=y;
month=m;
day=d;
voidset_date(inty,intm,intd)
{
intget_year(void)
returnyear;
intget_month(void)
returnmonth;
intget_day(void)
returnday;
intisleapyear();
voidinput();
voidoutput();
dateoperator=(date&
d);
};
datedate:
:
operator=(date&
d)
year=d.year;
month=d.month;
day=d.day;
return*this;
2)、student类
iomanip.h>
string.h>
date.h"
classStudent:
publicdate
private:
charname[11];
charsex[2];
charid[13];
datebirthday;
doublescore;
public:
Student();
Student(char*na,char*se,char*id_number,inty,intm,intd,doublesc):
date(y,m,d)
strcpy(name,na);
strcpy(sex,se);
strcpy(id,id_number);
score=sc;
}
voidset_Student(char*na,char*se,char*id_number,inty,intm,intd,doublesc);
friendistream&
operator>
(istream&
is,Student&
st);
friendostream&
operator<
(ostream&
os,Student&
Studentoperator=(Student&
st);
booloperator!
=(Student&
booloperator==(Student&
boolStudent:
operator==(Student&
st)
if(strcmp(id,st.id)==0)
returntrue;
else
returnfalse;
operator!
if(strcmp(id,st.id)==1)
returntrue;
StudentStudent:
operator=(Student&
strcpy(name,st.name);
strcpy(sex,st.sex);
strcpy(id,st.id);
birthday=st.birthday;
score=st.score;
}
Student:
Student()
strcpy(name,"
XX"
);
strcpy(sex,"
未知"
strcpy(id,"
63130605XXXX"
birthday.set_date(1980,1,1);
score=0;
voidStudent:
set_Student(char*na,char*se,char*id_number,inty,intm,intd,doublesc)
strcpy(name,na);
strcpy(sex,se);
strcpy(id,id_number);
birthday.set_date(y,m,d);
score=sc;
istream&
st)
cout<
"
姓名:
;
is>
st.name;
性别:
st.sex;
cout<
出生年:
st.birthday.year;
出生月:
st.birthday.month;
出生日:
st.birthday.day;
学号:
st.id;
成绩:
st.score;
st.set_Student(st.name,st.sex,st.id,st.birthday.year,st.birthday.month,st.birthday.day,st.score);
returnis;
ostream&
os<
st.name<
\t"
st.sex<
st.birthday.year<
."
st.birthday.month<
st.birthday.day<
st.id<
st.score<
endl;
returnos;
3)、list类
fstream.h>
stdlib.h>
student.h"
template<
classT>
classList;
classLinkNode
friendclassList<
T>
private:
Tdata;
LinkNode<
*link;
LinkNode(LinkNode<
*ptr=NULL)
{
link=ptr;
}
LinkNode(T&
item,LinkNode<
data=item;
link=ptr;
template<
classList
*first;
List()
first=newLinkNode<
List(constT&
x)
(x);
~List()
makeEmpty();
voidmakeEmpty();
//将链表置为空
intLength()const;
//得到链表的长度
*Search(Tx);
//搜索函数!
*Locate(inti);
//定位
*getHead()const
returnfirst;
boolgetDate(inti,T&
x)const;
//取出第i个元素的值
voidsetData(inti,T&
x);
//用x替换第i个元素!
boolInsert(inti,T&
//插入
boolRemove(inti,T&
//删除函数
boolIsEmpty()const//判断链表是否为空!
!
{returnfirst->
link==NULL?
true:
false;
voidinput(TendTag);
//输入函数
voidoutput();
List<
&
operator=(List<
L);
List(List<
voidsearch(inti);
boolbaocun();
boolread();
voidList<
search(inti)
Tval;
LinkNode<
*current=Locate(i-1);
if(current==NULL||current->
link==NULL)
输入的数值不合理"
return;
val=current->
data;
val;
List<
List(List<
L)
Tvalue;
*srcptr=L.getHead;
*destptr=first=newLinkNode<
while(srcptr->
link!
=NULL)
value=srcptr->
link->
data;
destptr->
link=newLinkNode<
(value);
destptr=destptr->
link;
srcptr=srcptr->
destptr->
link=NULL;
*srcptr=L.getHead();
*destptr=first=newLinkNode<
value=srcptr->
boolList<
save()
ofstreamfount1("
e:
\\Student.dat"
ios:
binary);
if(!
fount1)
cout<
文件打开失败!
*current=first->
while(current!
fount1.write((char*)&
current->
data,sizeof(T));
current=current->
read()
*newNode;
ifstreaminf("
inf)
while(!
inf.eof())
inf.read((char*)&
val,sizeof(val));
newNode=newLinkNode<
(val);
newNode->
link=first->
link;
first->
link=newNode;
output()//输出函数
Remove(inti,T&
x)//删除函数
*del=current->
current->
link=del->
deletedel;
Insert(inti,T&
x)//插入函数
*current=Locate(i);
if(current==NULL)
*newNode=newLinkNode<
if(newNode==NULL)
cerr<
储存分配错误!
exit
(1);
newNode->
link=current->
link=newNode;
setData(inti,T&
if(i<
=0)
*current=Locate(i);
if(current==NULL)
return;
current->
data=x;
getDate(inti,T&
x)const
returnNULL:
*current=Locate(i);
x=current->
LinkNode<
*List<
Locate(inti)//定位
if(i<
0)
returnNULL;
*current=first;
intk=0;
=NULL&
k<
i)
k++;
returncurrent;
intList<
Length()const//链表长度
*p=first->
intcount=0;
while(p!
p=p->
cout++
returncount;
input(TendTag)//输入函数
Tval;
makeEmpty();
cin>
while(val!
=endTag)
newNode=newLinkNode<
cin>
Search(Tx)//搜索函数
if(current->
data==x)
break;
makeEmpty()
*q;
while(first->
link!
=NULL)
q=first->
first->
link=q->
deleteq;
4)、menu类
list.h"
classMenu
voidmean(List<
l,Studentst)
intch;
while(ch!
=0)
|~~~~~~~~学生管理系统~~~~~~~~~~~|"
cout<
|~~~~~~~1.输入学生信息!
~~~~~~~~|"
|~~~~~~~2.输出学生信息!
|~~~~~~~3.插入学生信息!
cout<
|~~~~~~~4.删除学生信息!
|~~~~~~~5.搜索学生信息!
|~~~~~~~6.保存(文件形式)!
~~~~~~|"
|~~~~~~~7.读取(文件)!
~~~~~~~~~~|"
|~~~~~~~0.退出!
~~~~~~~~~~~~~~~~|"
请输入你的选择!
cin>
ch;
switch(ch)
{
case1:
Finput(l);
break;
case2:
OutPut(l);
case3:
Insert(l,st);
case4:
Remove(l);
case5:
Search(l);
case6:
save(l);
case7:
read(l);
}
}
voidread(List<
l)
if(l.read())
从“E:
\\student.dat!
”中成功读取文件"
else
文件读取失败!
voidsave(List<
if(l.baocun())
文件成功保存到“E:
”"
文件保存失败!
voidSearch(List<
inti;
请输入你要搜索的位置!
i;
l.search(i);
voidRemove(List<
请输入你要删除的位置:
Studentss;
if(l.Remove(i,ss))
删除成功"
ss;
删除失败!
voidFinput(List<
Studentst;
st.set_Student("
0"
"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 表报