软件设计 实验报告.docx

上传人:b****6 文档编号:13554156 上传时间:2023-06-15 格式:DOCX 页数:57 大小:220.63KB
下载 相关 举报
软件设计 实验报告.docx_第1页
第1页 / 共57页
软件设计 实验报告.docx_第2页
第2页 / 共57页
软件设计 实验报告.docx_第3页
第3页 / 共57页
软件设计 实验报告.docx_第4页
第4页 / 共57页
软件设计 实验报告.docx_第5页
第5页 / 共57页
软件设计 实验报告.docx_第6页
第6页 / 共57页
软件设计 实验报告.docx_第7页
第7页 / 共57页
软件设计 实验报告.docx_第8页
第8页 / 共57页
软件设计 实验报告.docx_第9页
第9页 / 共57页
软件设计 实验报告.docx_第10页
第10页 / 共57页
软件设计 实验报告.docx_第11页
第11页 / 共57页
软件设计 实验报告.docx_第12页
第12页 / 共57页
软件设计 实验报告.docx_第13页
第13页 / 共57页
软件设计 实验报告.docx_第14页
第14页 / 共57页
软件设计 实验报告.docx_第15页
第15页 / 共57页
软件设计 实验报告.docx_第16页
第16页 / 共57页
软件设计 实验报告.docx_第17页
第17页 / 共57页
软件设计 实验报告.docx_第18页
第18页 / 共57页
软件设计 实验报告.docx_第19页
第19页 / 共57页
软件设计 实验报告.docx_第20页
第20页 / 共57页
亲,该文档总共57页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

软件设计 实验报告.docx

《软件设计 实验报告.docx》由会员分享,可在线阅读,更多相关《软件设计 实验报告.docx(57页珍藏版)》请在冰点文库上搜索。

软件设计 实验报告.docx

软件设计实验报告

 

通信与信息工程学院

2011/2012学年第2学期

课程设计实验报告

 

模块名称VC++软件设计

专业电子信息工程

学生班级10

学生学号B09011027

学生姓名颜泽鑫

指导教师董恒

日期2012年5月24日

实验内容

前言:

本课程设计分成自测题和综合题两部分。

两部分都列入验收。

共11道。

内容覆盖主要基本技术:

基本的开发环境(调试技术),文件操作,动态链接库,图形图像编程,多线程编程,控件开发等。

每个学生选择5个完成,要求如下:

必做:

1;

2,3选择其一;

4,5选择其一;

6-11选择其二;

一、练习题:

1、基本环境调试

将例程1用VC++打开,修改错误使程序能够运行。

理解编译错误,运行错误等。

2、数据库操作

通过ODBC数据源访问数据库(ACCESS),数据库中保存以下内容:

学生姓名,性别,年龄,家庭住址,电话,电子邮件,爱好等。

再以上基础上进行该记录的读出并可编辑浏览显示。

3、图形编程

提供一个图形工具界面,让用户能够画出直线,椭圆,多边形等几何元素,结果可以保存并可读出。

4、字符串操作

能够从磁盘上选择打开文本文档,读入所有内容并显示,统计所有的字符数目,单词数目,中文字符串的数目。

5、动态链接库

目的:

了解MFC支持的三种动态链接库:

Win32DLL,MFC常规DLL,MFC扩展库。

掌握封装DLL的基本方法。

二、综合题:

个人简历

创建一个个人简历程序,能够编辑自己的个人资料,添加自己的相片集进行浏览,具有保存,打印等功能。

基本步骤:

实验环境

VC++6.0,ACCESS

实验步骤

基础题

设计一:

基本环境调试

程序说明:

本题是一道改错题,根据已经给出的例程1进行改错及完善的操作。

关键问题在于需要素数的存储,该题所给是数组,属于静态分配,最好改为动态的。

本题的主要目的是熟悉VC的编译环境,为下面的题目做铺垫。

程序修改如下:

//Fund1Dlg.cpp:

implementationfile

//

#include"stdafx.h"

#include"Fund1.h"

#include"Fund1Dlg.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

//

//CAboutDlgdialogusedforAppAbout

classCAboutDlg:

publicCDialog

{

public:

CAboutDlg();

//DialogData

//{{AFX_DATA(CAboutDlg)

enum{IDD=IDD_ABOUTBOX};

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg:

:

CAboutDlg():

CDialog(CAboutDlg:

:

IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

voidCAboutDlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

//Nomessagehandlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//

//CFund1Dlgdialog

CFund1Dlg:

:

CFund1Dlg(CWnd*pParent/*=NULL*/)

:

CDialog(CFund1Dlg:

:

IDD,pParent)

{

//{{AFX_DATA_INIT(CFund1Dlg)

m_limit=100;

//}}AFX_DATA_INIT

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32

m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

voidCFund1Dlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CFund1Dlg)

DDX_Text(pDX,IDC_EDIT1,m_limit);

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CFund1Dlg,CDialog)

//{{AFX_MSG_MAP(CFund1Dlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BUTTON1,OnButton1)

ON_BN_CLICKED(IDC_BUTTON2,OnButton2)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//

//CFund1Dlgmessagehandlers

BOOLCFund1Dlg:

:

OnInitDialog()

{

CDialog:

:

OnInitDialog();

//Add"About..."menuitemtosystemmenu.

//IDM_ABOUTBOXmustbeinthesystemcommandrange.

ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX<0xF000);

CMenu*pSysMenu=GetSystemMenu(FALSE);

if(pSysMenu!

=NULL)

{

CStringstrAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if(!

strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}

}

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);//Setbigicon

SetIcon(m_hIcon,FALSE);//Setsmallicon

//TODO:

Addextrainitializationhere

returnTRUE;//returnTRUEunlessyousetthefocustoacontrol

}

voidCFund1Dlg:

:

OnSysCommand(UINTnID,LPARAMlParam)

{

if((nID&0xFFF0)==IDM_ABOUTBOX)

{

CAboutDlgdlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog:

:

OnSysCommand(nID,lParam);

}

}

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow

//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,

//thisisautomaticallydoneforyoubytheframework.

voidCFund1Dlg:

:

OnPaint()

{

if(IsIconic())

{

CPaintDCdc(this);//devicecontextforpainting

SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(&rect);

intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

}

else

{

CDialog:

:

OnPaint();

}

}

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCFund1Dlg:

:

OnQueryDragIcon()

{

return(HCURSOR)m_hIcon;

}

voidCFund1Dlg:

:

OnButton1()

{

UpdateData();

intPrimes[2000];//存放素数的数组.

intindex=0;

//简单的求素数算法.

boolflag=true;

for(intm=2;m<=m_limit;m++)

{

for(inti=2;i

{

if(m%i==0)

{

flag=false;

break;

}

else

flag=true;

}

if(flag==true)

Primes[index++]=m;

}

CWnd*pWnd=GetDlgItem(IDC_STATICOUTPUT);

CStringstr;

str.Format("%d以内的素数有%d个:

\n\n",m_limit,index);

for(inti=0;i

charbuf[10];

sprintf(buf,"%d",Primes[i]);

str+=buf;

}

pWnd->SetWindowText(str);

}

voidCFund1Dlg:

:

OnButton2()

{

OnOK();

}

调试结果如下:

设计二:

数据库系统

程序说明:

本题是使用ACCESS数据库存储学生信息,利用ODBC将MFC界面与ACCESS数据库连接起来,从而可以在可视化界面上显示数据内容并完成查询、添加、编辑和删除的功能。

查询功能是通过将用户输入的文本信息取出,并在数据库中检索对应字段的信息,若检索成功,则在界面上显示相对应的学生信息,否则提示无此学生信息。

添加和编辑都需要使用新的对话框,通过将新对话框中文本框的内容存入数据库学生表中,以实现添加或对现有数据的编辑功能。

删除功能和显示功能大致相同,由于数据是绑定的,无需全表字段检索,很容易实现对指定记录的删除操作。

设计流程图:

调试结果:

程序(查询,添加,删除):

//UseAdoDlg.cpp:

implementationfile

//

#include"stdafx.h"

#include"UseAdo.h"

#include"UseAdoDlg.h"

#include"ADO.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

//CAboutDlgdialogusedforAppAbout

classCAboutDlg:

publicCDialog

{

public:

CAboutDlg();

//DialogData

//{{AFX_DATA(CAboutDlg)

enum{IDD=IDD_ABOUTBOX};

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg:

:

CAboutDlg():

CDialog(CAboutDlg:

:

IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

voidCAboutDlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

//Nomessagehandlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//CUseAdoDlgdialog

CUseAdoDlg:

:

CUseAdoDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CUseAdoDlg:

:

IDD,pParent)

{

//{{AFX_DATA_INIT(CUseAdoDlg)

m_ID=_T("");

m_Name=_T("");

m_Culture=_T("");

//}}AFX_DATA_INIT

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32

m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

voidCUseAdoDlg:

:

DoDataExchange(CDataExchange*pDX)

{

CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CUseAdoDlg)

DDX_Control(pDX,IDC_LIST1,m_Grid);

DDX_Text(pDX,IDC_EDIT1,m_ID);

DDX_Text(pDX,IDC_EDIT2,m_Name);

DDX_Text(pDX,IDC_EDIT3,m_Culture);

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CUseAdoDlg,CDialog)

//{{AFX_MSG_MAP(CUseAdoDlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BUTADD,OnButadd)

ON_NOTIFY(NM_CLICK,IDC_LIST1,OnClickList1)

ON_BN_CLICKED(IDC_BUTMOD,OnButmod)

ON_BN_CLICKED(IDC_BUTDEL,OnButdel)

ON_BN_CLICKED(IDC_BUTCLEAR,OnButclear)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//CUseAdoDlgmessagehandlers

BOOLCUseAdoDlg:

:

OnInitDialog()

{

CDialog:

:

OnInitDialog();

//Add"About..."menuitemtosystemmenu.

//IDM_ABOUTBOXmustbeinthesystemcommandrange.

ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX<0xF000);

CMenu*pSysMenu=GetSystemMenu(FALSE);

if(pSysMenu!

=NULL)

{

CStringstrAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if(!

strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}

}

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);//Setbigicon

SetIcon(m_hIcon,FALSE);//Setsmallicon

//TODO:

Addextrainitializationhere

m_Grid.SetExtendedStyle(LVS_EX_FLATSB

|LVS_EX_FULLROWSELECT

|LVS_EX_HEADERDRAGDROP

|LVS_EX_ONECLICKACTIVATE

|LVS_EX_GRIDLINES);

m_Grid.InsertColumn(0,"编号",LVCFMT_LEFT,110,0);

m_Grid.InsertColumn(1,"姓名",LVCFMT_LEFT,110,1);

m_Grid.InsertColumn(2,"学历",LVCFMT_LEFT,110,2);

AddToGrid();

returnTRUE;//returnTRUEunlessyousetthefocustoacontrol

}

voidCUseAdoDlg:

:

OnSysCommand(UINTnID,LPARAMlParam)

{

if((nID&0xFFF0)==IDM_ABOUTBOX)

{

CAboutDlgdlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog:

:

OnSysCommand(nID,lParam);

}

}

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow

//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,

//thisisautomaticallydoneforyoubytheframework.

voidCUseAdoDlg:

:

OnPaint()

{

if(IsIconic())

{

CPaintDCdc(this);//devicecontextforpainting

SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(&rect);

intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

}

else

{

CDialog:

:

OnPaint();

}

}

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCUs

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

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2