C++报告.docx
- 文档编号:30155342
- 上传时间:2023-08-05
- 格式:DOCX
- 页数:61
- 大小:657.44KB
C++报告.docx
《C++报告.docx》由会员分享,可在线阅读,更多相关《C++报告.docx(61页珍藏版)》请在冰豆网上搜索。
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< p=p->next; }while(p! =NULL); } cout<<"排序后的学生信息为(安照学号号由小到大排列)"< stud.inorder(head); p=head; if(p! =NULL) { cout<<"你输入的学生信息如下: "< cout<<"学号\t分数"< do { cout< 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<<"你输入学生的成绩为: "< } 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->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->num { 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() {
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)