C++报告.docx

上传人:b****5 文档编号:30155342 上传时间:2023-08-05 格式:DOCX 页数:61 大小:657.44KB
下载 相关 举报
C++报告.docx_第1页
第1页 / 共61页
C++报告.docx_第2页
第2页 / 共61页
C++报告.docx_第3页
第3页 / 共61页
C++报告.docx_第4页
第4页 / 共61页
C++报告.docx_第5页
第5页 / 共61页
点击查看更多>>
下载资源
资源描述

C++报告.docx

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

C++报告.docx

C++报告

C++实验报告

姓名:

学号:

专业班级:

自动化133

版权所有,翻版必究

实验一:

堆栈--------------------------------------------------------5

工程说明--------------------------------------------------5

工程架构--------------------------------------------------5

main.c文件代码-----------------------------------------5

class.cpp文件代码--------------------------------------6

class.hpp文件代码-------------------------------------6

运行结果--------------------------------------------------7

实验二:

liaobiao1------------------------------------------------7

工程说明--------------------------------------------------8

工程架构--------------------------------------------------8

main.c文件代码-----------------------------------------8

innclude.hpp文件代码--------------------------------9

class.hpp文件代码-------------------------------------9

class.cpp文件代码------------------------------------10

运行结果-------------------------------------------------14

实验三:

九宫格------------------------------------------------16

工程说明-------------------------------------------------16

工程架构-------------------------------------------------16

main.c文件代码---------------------------------------16

class.cpp文件代码------------------------------------17

class.hpp文件代码-----------------------------------17

运行结果-------------------------------------------------21

实验四:

playcard-----------------------------------------------22

工程说明-------------------------------------------------22

工程架构-------------------------------------------------22

main.c文件代码---------------------------------------23

class.cpp文件代码------------------------------------23

class.hpp文件代码-----------------------------------24

运行结果------------------------------------------------28

实验五:

虚基类--------------------------------------------------28

工程说明------------------------------------------------28

工程架构------------------------------------------------28

main.c文件代码---------------------------------------28

运行结果-------------------------------------------------32

实验六:

INHERTANCE-------------------------------------------32

工程说明-------------------------------------------------32

工程架构------------------------------------------------32

main.c文件代码---------------------------------------32

运行结果-------------------------------------------------34

实验七:

运算符重载--------------------------------------------34

工程1:

成员函数运算符重载--------------------34

工程说明-------------------------------------------------34

工程架构------------------------------------------------34

main.c文件代码--------------------------------------34

运行结果------------------------------------------------37

工程2:

友元函数运算符重载-------------------37

工程说明------------------------------------------------37

工程架构-----------------------------------------------37

main.c文件代码-------------------------------------37

运行结果-----------------------------------------------39

实验八:

动态联编---------------------------------------------40

工程说明------------------------------------------------40

工程架构------------------------------------------------40

main.c文件代码---------------------------------------40

运行结果-------------------------------------------------43

实验九:

构造函数与析构函数-------------------------------44

工程说明-------------------------------------------------44

工程架构-------------------------------------------------44

main.c文件代码---------------------------------------44

运行结果-------------------------------------------------45

结语:

--------------------------------------------------------------45

实验一:

堆栈

工程说明:

此c++实验在codeblocks编程环境下实现:

工程架构:

main.c文件代码如下:

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

*工程名:

duizhan1

*实验目的:

c++学习实践

*copyright:

WMH

*地点:

南昌大学

*时间:

2015-5-26

*版权声明:

此代码可以应用于非商业领域。

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

#include

#include"stack.hpp"

usingnamespacestd;

intmain()

{

IStackstack;

cout<<"Helloworld!

"<

stack.Push

(1);

stack.Push

(2);

stack.Push(3);

stack.Push(4);

cout<<"Popped"<

cout<<"Popped"<

cout<<"Popped"<

cout<<"Popped"<

stack.Push(5);

stack.Push(6);

stack.Push(7);

stack.Push(8);

stack.display();

cout<<"\nTheendingoftheprogramm!

\n"<

return0;

}

stack.hpp代码如下:

#ifndefSTACK_HPP

#defineSTACK_HPP

constintmaxStack=16;

classIStack

{

public:

IStack():

_top(0)

{}

voidPush(inti);

intPop();

voiddisplay();

private:

int_arr[maxStack];

int_top;

};

#endif//STACK_HPP

stack.cpp文件代码如下:

#include"stack.hpp"

#include

#include

usingstd:

:

cout;

usingstd:

:

endl;

voidIStack:

:

Push(inti)

{

assert(_top

_arr[_top]=i;

++_top;

}

intIStack:

:

Pop()

{

assert(_top>0);//断言是否到达栈低

--_top;

return_arr[_top];

}

voidIStack:

:

display()

{

unsignedinti;

for(i=0;i<_top;i++)

{

cout<<_arr[i]<

}

}

运行结果:

实验二:

学习成绩管理

工程说明:

此c++实验在codeblocks编程环境下实现,是基于单向链表的学生成绩管理实验:

工程架构:

main.c文件代码如下:

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

*工程名:

lianbiao

*实验目的:

c++学习实践

*copyright:

WMH

*地点:

南昌大学

*时间:

2015-4-21

*版权声明:

此代码可以应用于非商业领域。

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

#include"include.hpp"

intmain()

{

Stud*head,*p;

studentstud;

head=stud.creat();

p=head;

if(p!

=NULL)

{

cout<<"你输入的学生信息如下:

"<

cout<<"学号\t分数"<

do

{

cout<num<<"\t"<score<

p=p->next;

}while(p!

=NULL);

}

cout<<"排序后的学生信息为(安照学号号由小到大排列)"<

stud.inorder(head);

p=head;

if(p!

=NULL)

{

cout<<"你输入的学生信息如下:

"<

cout<<"学号\t分数"<

do

{

cout<num<<"\t"<score<

p=p->next;

}while(p!

=NULL);

}

intcinnum=0;

cout<<"输入要查询学生的学号:

\n";

cin>>cinnum;

p=stud.look_for(cinnum,head);

if(p==NULL)

{

cout<<"你输入的学生序号不存在!

\n";

}

else

{

cout<<"你输入学生的成绩为:

"<score<

}

cout<<"Helloworld!

"<

return0;

}

include.hpp代码如下:

#include

#include"class.hpp"

usingnamespacestd;

class.hpp代码如下:

#ifndefCLASS_H

#defineCLASS_H

structStud

{

intnum;

floatscore;

structStud*next;

};

structStud*creat();

structStud*inser(structStud*ins,Stud*head);

voidinorder(structStud*head);

classstudent

{

public:

voidPrint();

structStud*creat();

structStud*inser(structStud*ins,Stud*head);

structStud*look_for(intnum,Stud*head);

voidinorder(structStud*head);

};

#endif//CLASS_H

class.cpp文件代码如下:

#include"include.hpp"

voidstudent:

:

Print()

{

cout<<"逗你玩呢!

c++很好玩吧!

"<

}

structStud*student:

:

creat()

{

shortinttong=0;

Stud*p1=NULL,*p2=NULL,*p3=NULL,*head=NULL;

head=NULL;

p1=new(Stud);

cout<<"请输入学生的序号,序号非零,当输入零时,结束录入。

\n"<

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

"<

cin>>p1->num;

if(p1->num==0)

{

cout<<"你输入了学生序号为0,结束了信息的录入。

\n"<

delete(p1);

//head=NULL;

return(head);

}

else

{

head=p1;

while(p1->num!

=0)

{

p3=head;

if(tong==1)

{

cout<<"你输入的学生序号与前面相同,请重新输入"<

cout<<"\n请输入学生的序号:

"<

tong=0;

cin>>p1->num;

}

else

{

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

";

cin>>p1->score;

p2=p1;

p1=new(Stud);

p2->next=p1;

cout<<"\n请输入学生的序号:

"<

cin>>p1->num;

}

while(p3!

=p2)

{

if(p3->num==p1->num)

{

tong=1;

break;

}

p3=p3->next;

}

if(p2->num==p1->num)

{

tong=1;

}

}

}

cout<

//cout<<"运行到这里1"<

p2->next=NULL;

delete(p1);

return(head);

}

structStud*student:

:

inser(structStud*ins,structStud*head)

{

structStud*p1=NULL,*p2=NULL;

if(ins->numnum||head==NULL)//如果ins->num小于首结点序号,或者头结点为空,直接插入

{

ins->next=head;

return(ins);

}

elseif(head->next==NULL)//如果只有一个结点

{

head->next=ins;

ins->next=NULL;

return(head);

}

else

{

unsignedcharflag='N';

p2=head;

p1=head->next;

//while(p1->next!

=NULL)//p1不是最后一个结点

do

{

if(ins->numnum)

{

p2->next=ins;

ins->next=p1;

flag='Y';

}

p2=p1;

p1++;

}while(p1->next!

=NULL);//p1不是最后一个结点

if(flag=='N')

{

p1=NULL;

p2->next=ins;

ins->next=NULL;

}

returnhead;

}

}

voidstudent:

:

inorder(structStud*head)

{

structStud*p1=NULL,*p2=NULL;

intnum;

floatscore;

p1=head;

if(head!

=NULL)

p2=p1->next;

while(p1->next!

=NULL)

{

while(p2!

=NULL)

{

if(p1->num>p2->num)

{

num=p1->num;

score=p1->score;

p1->num=p2->num;

p1->score=p2->score;

p2->num=num;

p2->score=score;

num=0;

score=0;

}

p2=p2->next;

}

p1=p1->next;

p2=p1->next;

}

};

structStud*student:

:

look_for(intnum,Stud*head)

{

if(head==NULL)

{

returnNULL;

}

else

{

Stud*p1;

p1=head;

do

{

if(p1->num==num)

returnp1;

}while(p1++->next!

=NULL);

}

returnNULL;

}

运行结果:

实验三:

九宫格

工程说明:

此c++实验在codeblocks编程环境下实现:

工程架构:

main.c文件代码如下:

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

*工程名:

九宫格

*实验目的:

c++学习实践

*copyright:

WMH

*地点:

南昌大学

*时间:

2015-6-1

*版权声明:

此代码可以应用于非商业领域。

*编程环境:

codeblocks13.12

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

#include

usingnamespacestd;

#include

#include"class.hpp"

intmain()

{

jiugongge*JGG;

charch='C';

cout<<"适度游戏,拒绝沉迷!

\n"<

while(ch=='C')

{

JGG=new(jiugongge);

(*JGG).display();

(*JGG).yidong();

deleteJGG;

cout<<"继续游戏输入'C',结束游戏输入‘C’以外任意键\n";

cin>>ch;

}

cout<<"谢谢您玩“九宫格游戏”,希望您玩的尽兴!

"<

return0;

}

class.hpp文件代码:

#ifndefCLASS_HPP

#defineCLASS_HPP

#include

classjiugongge

{

public:

jiugongge();

voidyidong();

boolcheck();

voiddisplay();

private:

unsignedshortintjgg[3][3];

boolnumalready[9];

};

#endif//CLASS_HPP

class.cpp文件代码:

#include

usingnamespacestd;

#include"class.hpp"

#include"time.h"

#defineusintunsignedshortint

#defineucharunsignedchar

jiugongge:

:

jiugongge()

{

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 机械仪表

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1