第三阶段可视化编程中国矿业大学计算机学院软件课程设计.docx
- 文档编号:9221352
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:15
- 大小:59.25KB
第三阶段可视化编程中国矿业大学计算机学院软件课程设计.docx
《第三阶段可视化编程中国矿业大学计算机学院软件课程设计.docx》由会员分享,可在线阅读,更多相关《第三阶段可视化编程中国矿业大学计算机学院软件课程设计.docx(15页珍藏版)》请在冰豆网上搜索。
第三阶段可视化编程中国矿业大学计算机学院软件课程设计
第三阶段可视化编程
一.必做:
1.课堂观看可视化视频(自带耳机)并当堂写出纸质操作步骤,课下观看可视化视频,写出纸质操作步骤及学习笔记。
2.选取第一、二阶段已设计的任一题目,改写成可视化方法设计。
建议观看:
1.从Appwizard开始-----“HELLO”;
2.菜单和加速键;
3.对话框;
4.windows消息;
二.选作:
1.用你熟悉的一种可视化编程语言实现如下图所示的计算器。
该计算器需要实现基础的数学运算,如加,减,乘,除。
2.使用VisualC++6.0实现以下绘图程序(可以参考附件中的程序代码)。
要求:
(1)程序中包含图中所示菜单项和工具栏;
(2)先选择菜单项或单击工具栏上的命令按钮,然后在窗体空白区域单击鼠标后,绘制相应菜单项或命令按钮指定的图形、文字。
扩充:
1)能够选择、移动、删除、拷贝、剪切图元
2)完成图形文件的保存、打开、打印
3.用你熟悉的一种可视化编程语言实现以下汉诺塔演示程序(可以参考附件中的程序代码)。
程序代码:
//汉诺塔.cpp:
Definestheclassbehaviorsfortheapplication.
//
#include"stdafx.h"
#include"汉诺塔.h"
#include"汉诺塔Dlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CMyApp
BEGIN_MESSAGE_MAP(CMyApp,CWinApp)
//{{AFX_MSG_MAP(CMyApp)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG
ON_COMMAND(ID_HELP,CWinApp:
:
OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CMyAppconstruction
CMyApp:
:
CMyApp()
{
//TODO:
addconstructioncodehere,
//PlaceallsignificantinitializationinInitInstance
}
/////////////////////////////////////////////////////////////////////////////
//TheoneandonlyCMyAppobject
CMyApptheApp;
/////////////////////////////////////////////////////////////////////////////
//CMyAppinitialization
BOOLCMyApp:
:
InitInstance()
{
AfxEnableControlContainer();
//Standardinitialization
//Ifyouarenotusingthesefeaturesandwishtoreducethesize
//ofyourfinalexecutable,youshouldremovefromthefollowing
//thespecificinitializationroutinesyoudonotneed.
#ifdef_AFXDLL
Enable3dControls();//CallthiswhenusingMFCinasharedDLL
#else
Enable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically
#endif
CMyDlgdlg;
m_pMainWnd=&dlg;
intnResponse=dlg.DoModal();
if(nResponse==IDOK)
{
//TODO:
Placecodeheretohandlewhenthedialogis
//dismissedwithOK
}
elseif(nResponse==IDCANCEL)
{
//TODO:
Placecodeheretohandlewhenthedialogis
//dismissedwithCancel
}
//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe
//application,ratherthanstarttheapplication'smessagepump.
returnFALSE;
}
//汉诺塔Dlg.h:
headerfile
//
#if!
defined(AFX_DLG_H__6F346C11_76E2_42CA_ACB6_7040244805B5__INCLUDED_)
#defineAFX_DLG_H__6F346C11_76E2_42CA_ACB6_7040244805B5__INCLUDED_
#if_MSC_VER>1000
#pragmaonce
#endif//_MSC_VER>1000
/////////////////////////////////////////////////////////////////////////////
//CMyDlgdialog
classCMyDlg:
publicCDialog
{
//Construction
public:
CMyDlg(CWnd*pParent=NULL);//standardconstructor
//DialogData
//{{AFX_DATA(CMyDlg)
enum{IDD=IDD_MY_DIALOG};
//NOTE:
theClassWizardwilladddatamembershere
//}}AFX_DATA
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CMyDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
HICONm_hIcon;
intMoveDish(intn,inta,intb);//将a最上面的n个盘子移动到b
voidShowBg(CDC*dc);//显示函数
voidSetDishNumber(intn);//设置盘子个数
intnumber;//盘子数
intdish[7];//每个盘子所在位置
intopt[30][3];//操作栈,用于保存将要进行的操作,因为操作要分步进行,故采用栈模拟递归,从而将操作分解
intpn;//栈顶位置
//Generatedmessagemapfunctions
//{{AFX_MSG(CMyDlg)
virtualBOOLOnInitDialog();
afx_msgvoidOnSysCommand(UINTnID,LPARAMlParam);
afx_msgvoidOnPaint();
afx_msgHCURSOROnQueryDragIcon();
afx_msgvoidOnButton2();
afx_msgvoidOnButton1();
afx_msgvoidOnR3();
afx_msgvoidOnR4();
afx_msgvoidOnR5();
afx_msgvoidOnR6();
afx_msgvoidOnR7();
afx_msgvoidOnTimer(UINTnIDEvent);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.
#endif//!
defined(AFX_DLG_H__6F346C11_76E2_42CA_ACB6_7040244805B5__INCLUDED_)
//汉诺塔.h:
mainheaderfileforthe汉诺塔application
//
#if!
defined(AFX__H__427120C5_CCB4_46E4_B1DB_0E8AE6916A1E__INCLUDED_)
#defineAFX__H__427120C5_CCB4_46E4_B1DB_0E8AE6916A1E__INCLUDED_
#if_MSC_VER>1000
#pragmaonce
#endif//_MSC_VER>1000
#ifndef__AFXWIN_H__
#errorinclude'stdafx.h'beforeincludingthisfileforPCH
#endif
#include"resource.h"//mainsymbols
/////////////////////////////////////////////////////////////////////////////
//CMyApp:
//See汉诺塔.cppfortheimplementationofthisclass
//
classCMyApp:
publicCWinApp
{
public:
CMyApp();
//Overrides
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CMyApp)
public:
virtualBOOLInitInstance();
//}}AFX_VIRTUAL
//Implementation
//{{AFX_MSG(CMyApp)
//NOTE-theClassWizardwilladdandremovememberfunctionshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.
#endif//!
defined(AFX__H__427120C5_CCB4_46E4_B1DB_0E8AE6916A1E__INCLUDED_)
//stdafx.h:
includefileforstandardsystemincludefiles,
//orprojectspecificincludefilesthatareusedfrequently,but
//arechangedinfrequently
//
#if!
defined(AFX_STDAFX_H__952FDF2E_C208_4AD3_BBCD_F037E1E3AAE0__INCLUDED_)
#defineAFX_STDAFX_H__952FDF2E_C208_4AD3_BBCD_F037E1E3AAE0__INCLUDED_
#if_MSC_VER>1000
#pragmaonce
#endif//_MSC_VER>1000
#defineVC_EXTRALEAN//Excluderarely-usedstufffromWindowsheaders
#include
#include
#include
#include
#ifndef_AFX_NO_AFXCMN_SUPPORT
#include
#endif//_AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.
#endif//!
defined(AFX_STDAFX_H__952FDF2E_C208_4AD3_BBCD_F037E1E3AAE0__INCLUDED_)
4.单机版俄罗斯方块
游戏规则:
在方块从屏幕上方落下来时,玩家可以移动和旋转窗口内落下的方块,巧妙地安排布置,达到充分利用屏幕空间的目的。
每当屏幕的一整行被方块积木排满时,作为奖赏,整行从屏幕上消失,剩余的积木依次往下降一行。
当积木堆积达到屏幕顶端的时候,游戏结束。
方块效果如下图所示。
扩充:
多人联机游戏。
程序代码:
#include"stdafx.h"
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
#include"windows.h"
#include"time.h"
#definerandom(x)(rand()%x)
#defineN13
#defineM10
#defineK5
ints[N][M]={{0,0,0,2,2,2},{0,0,0,0,2},{0},{0},{0},{0},{0},{0},{0},{0},
{1},{1,0,0,1},{1,1,1,1,1,1,0,1,1,1}};/*当前状态*/
inta[K][3][3]={{0,2,0,2,2,2},{2,0,0,2,2,2},{2,0,0,2,0,0,2,2},{2,2,2,0,0,2},
{{2},{2},{2}}};
voidDisp()
{
inti,j;
for(i=0;i {for(j=0;j 48+s[i][j]: ''); printf("\n");} printf("\n\n操作说明: 按左移,按右移,按下移\n"); } voidDown() { inti,j,k; for(j=0;j if(j {for(i=0;i for(i=N-1;i>=0;i--) {for(j=0;j if(j==M)/*若第i行没空格消去第i行*/ for(k=i++-1;k>=0;k--)for(j=0;j } return;} for(i=0;i {for(j=0;j if(s[i][j]==2)if(s[i+1][j]! =0&&s[i+1][j]! =2)break;/*方块下方不空退出内循环*/ if(j } if(i {for(i=0;i for(i=0;i for(i=N-1;i>=0;i--) {for(j=0;j if(j==M)/*若第i行没空格消去第i行*/ for(k=i++-1;k>=0;k--)for(j=0;j } return;} for(i=N-1;i>=0;i--) for(j=0;j if(s[i][j]==2)s[i+1][j]=s[i][j],s[i][j]=0;/*方块下移*/ } voidRight() { inti,j; for(i=0;i for(i=0;i for(j=0;j if(s[i][j]==2)if(s[i][j+1]! =0&&s[i][j+1]! =2)return;/*方块右方不空退出*/ for(j=M-2;j>=0;j--) for(i=0;i if(s[i][j]==2)s[i][j+1]=s[i][j],s[i][j]=0;/*方块右移*/ } voidLeft() { inti,j; for(i=0;i for(i=0;i for(j=1;j if(s[i][j]==2)if(s[i][j-1]! =0&&s[i][j-1]! =2)return;/*方块左方不空退出*/ for(j=1;j for(i=0;i if(s[i][j]==2)s[i][j-1]=s[i][j],s[i][j]=0;/*方块左移*/ } intHave()/*判断是否有可移动方块,没有返回,否则返回*/ { inti,j; for(i=0;i return1; } voidAdd()/*随机生成方块*/ { intt=random(K),x=random(M-3);/*生成两随机数t和x分别作为第t种方块和第x位置出现*/ inti,j;if(x<0)x=-x%(M-3); for(i=0;i<3;i++)for(j=x;j } voidmain() { charc='A'; while (1)/*判断是否有按键,没有循环输出i,否则停,conio.h*/ { if(! kbhit())c='2';elsec=getch(); if(c=='p')getch(); system("CLS");/*清屏,TC用clrscr();,VC用system("CLS");*/ switch(c) { case'4': Left();break;/*左移*/ case'6': Right();break;/*右移*/ case'9': case27: return;/*按或Esc(=27)另存后退出*/ case'2': ;/*下移*/ default: Down(); } c='2';if(Have())Add();Disp();Sleep(600);/*睡眠ms,windows.h*/ } } 5.五子棋 实现人与机对下的功能。 要求: 1、要有棋盘; 2、设计输、赢判断规则函数; 3、给出下棋过程 五子棋: 程序代码见附件
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 第三 阶段 可视化 编程 中国矿业 大学计算机 学院 软件 课程设计