刺客信条1 收集:自然数的分解(基于对话框的Windows应用程序)

来源:百度文库 编辑:高考问答 时间:2024/05/06 01:14:48
课程设计任务书

一. 题目:自然数的分解(基于对话框的Windows应用程序)

二. 基本要求:
(1)要求使用Visual C++中的MFC创建基于对话框的Windows应用程序;
(2)在VC++6.0环境中,学会查究错误、调试程序的方法,独立调试完成;
(3)掌握创建基于对话框的MFC应用程序的操作过程,明确程序是如何通过对话框与用户进行交互的。

三、设计方法和基本原理
1. 课题功能描述
自然数的分解,就是将大于1的自然数分解为素数的乘积和裴波那契数列的和。使用MFC,编写基于对话框的Windows应用程序,当用户输入一个自然数后,将其分解为素数的乘积和裴波那契数列的和,并显示出来。
2. 问题详细描述
自然数的分解是一个基于对话框的Windows应用程序。该程序包含两个对话框:主对话框和帮助对话框(由主对话框启动)。
在主对话框中,用户输入自然数,程序完成分解后,将结果显示出来。
帮助对话框中对本程序的使用方法进行说明,并由主对话框启动。
3. 问题的解决方案
根据问题描述,可以将问题解决分为三步:
1) 使用Visual C++中的MFC AppWizard创建基于对话框的应用程序。(特别提示:对AppWizard创建的应用程序,一定要先链接,然后再进行下面的操作。如果添加代码后进行编译,会因缺少临时文件tmp.pch而出错:“fatal error C1083: Cannot open precompiled header file: 'Debug/tmp.pch': No such file or directory”。所以创建项目后,马上进行链接。)
2) 使用Visual C++中的资源编辑器对程序中的对话框进行可视化编辑,实现程序所需的操作界面。照题目要求,设计友好方便的图形用户界面,以实现程序功能。
3) 使用Class Wizard编辑对话框所对应的对话框类,为对话框中的控件添加成员变量来操纵控件,为对话框中的控件建立消息映射和消息映射函数,最后编写函数代码实现其功能。
4. 参考资料:教材第8章
四、主要技术问题的描述
根据三的分析,主要问题在于:
1) 首先要自学并掌握教材第8章“使用Visual C++中的MFC创建基于对话框的Windows应用程序”的方法。
2) 整数分解唯一性定理:每个大于1的正整数a均可以分解成有限个素因数之积,并且若不计素因数的次序,其分解是唯一的(若正整数a有一因数b,而b又是素数,则称b为a的素因数)。将自然数n分解为素数的乘积时,n的素因数肯定在2~n范围内。
3) 将自然数分解为裴波那契数列的和,可参阅实验指导书。
4) 分解结果编辑框对应的变量类型为CString,分解的输出结果形式如下:45=3*3*5或13=1*13。数字到字符串的转换有两种方法
方法一:使用itoa函数,其函数声明为:char * itoa ( int value, char * buffer, int radix ).
其中的Parameters.
value :Value to be represented as a string.
buffer :Buffer where to store the resulting string.
radix :Numeral radix in which value has to be represented, between 2 and 36.
Return Value:A pointer to the string.
方法二:使用CEdit类的Format()函数。例如要将int型的变量m,n和字符数组s[30]中的内容,送入CString型的文本框控件对应的控件成员变量m_cresult,则可:
m_crerul.Format(“%d%s%d”,m,s,n);
来实现。
5) 可直接使用“+”运算符进行两个Cstring串对象的连接,例:
CString s1 = "This "; // Cascading concatenation
s1 += "is a "
CString s2 = "test";
CString message = s1 + "big " + s2;

简单的学生信息管理系统
关键字 简单的学生信息管理系统
出处

Name mis_sims.c
Author x-bit
Description 简单的学生信息管理系统
Date 07-11-2004

#i nclude stdio.h
#i nclude string.h
#i nclude conio.h
#i nclude process.h
#define MAX 500 定义存储容量

typedef struct
{
int month, day, year; 出生年月
}BT;
typedef struct
{
int number; 学号
char name[13]; 姓名
char sex[7]; 性别male or female
BT birth; 出生年月MM-DD-YY
char addr[35]; 家庭住址
}ST;

ST student[MAX]; 定义student[MAX]为全局变量

函数声明
void menu(); 显示菜单
void menu_done(); 菜单响应
char get_menu_choice(); 获取菜单选择信息
FILE file_operate(char mode); 文件操作模块
void inf_add(FILE fp); 添加学生信息
void inf_list(FILE fp); 显示学生信息
void inf_search(FILE fp); 查找学生信息
void inf_change(FILE fp); 修改学生信息
void inf_del(FILE fp); 删除学生信息
void file_backup(); 文件备份
void psw_check(); 密码验证机制
void set_psw(); 设置密码

-------------------------The main function-----------------------
int main()
{
system(cls);
psw_check();
menu_done();
return 0;
}
-------------------------The main function-----------------------

菜单

void menu()
{
printf(t n);
printf(t ~~ ~~ n);
printf(t ( @ @ ) n);
printf(t+-------oOOo---------(_)-----------oOOo-----+n);
printf(t MIS-----SMIS n);
printf(t Student Management Information System n);
printf(t-------------------------------------------n);
printf(t 1. Input data 5. Delete data n);
printf(t 2. Display data 6. Backup data n);
printf(t 3. Search data 7. Set password n);
printf(t 4. Change data 0. Exit n);
printf(t-------------------------------------------n);
printf(t x-bit (C) 2004. n);
printf(t+-------------------------------------------+n);
}

菜单响应模块

void menu_done()
{
while(1)
{
menu();
switch(get_menu_choice())
{
case '1'
inf_add(file_operate(a));
system(pause);
system(cls);
break;
case '2'
inf_list(file_operate(rb));
system(pause);
system(cls);
break;
case '3'
inf_search(file_operate(rb));
system(pause);
system(cls);
break;
case '4'
inf_change(file_operate(rb));
system(pause);
system(cls);
break;
case '5'
inf_del(file_operate(r));
system(pause);
system(cls);
break;
case '6'
file_backup();
system(pause);
system(cls);
break;
case '7'
set_psw();
system(pause);
system(cls);
break;
case '0'
printf(Thank you for use this program.n);
system(pause);
system(cls);
exit(1); 程序正常退出
}
}
}

接收菜单选择

char get_menu_choice()
{
char menu_choice;
do
{
fflush(stdin);
printf(Please choice );
scanf(%c, &menu_choice);
if(menu_choice'0' menu_choice'7')
puts(input error, try again.);
}while(menu_choice'0' menu_choice'7');
return menu_choice;
}

文件操作

FILE file_operate(char mode)
{
char choise;
FILE fp;
do
{
fflush(stdin);
if((fp=fopen(student.dat, mode))==NULL) 打开文件
{
puts(File operation failure);
puts(Try Again(yn));
scanf(%c, &choise);
}
}while(choise=='y' choise=='Y');
if(choise=='n' choise=='N')
exit(0); 出现异常而退出
return fp;
}

输入资料

void inf_add(FILE fp)
{
int i=0; 初始化索引值变量
char choice='y';

do
{
printf(No.(20040001) );
scanf(%d, &student[i].number);
printf(Name(less than 12 characters) );
scanf(%s, student[i].name);
printf(Sex(male or female) );
scanf(%s, student[i].sex);
printf(Birthdayn);
printf( year );
scanf(%d, &student[i].birth.year);
printf( month );
scanf(%d, &student[i].birth.month);
printf( day );
scanf(%d, &student[i].birth.day);
printf(Address );
scanf(%s, student[i].addr);

if(fwrite(&student[i], sizeof(ST), 1, fp)!=1)
puts(data write error.);
i++;
fflush(stdin);
printf(Continue(yn));
scanf(%c,&choice);
}while((choice=='y' choice=='Y'));
fclose(fp);
}

查找资料

void inf_search(FILE fp)
{
int i, m;
char search_name[20]; 查找姓名变量
char choice='y';
for(i=0; feof(fp)==0; i++) 读取文件
{
if(fread(&student[i], sizeof(ST), 1, fp)!=1 && feof(fp)==0)
puts(error);
}
m=i-1; m被赋值为数组非空数据最大索引值
do
{
fflush(stdin);
puts(Enter the name for searching );
gets(search_name);
for(i=0; im; i++) 遍历数组
{
if(strcmp(search_name, student[i].name)==0)
判断是否有要查找的学生姓名,有则显示数据
{
printf(No. %d Name %s Sex %s Birth %d-%d-%d

Address %sn,
student[i].number, student[i].name, student

[i].sex,
student[i].birth.month, student[i].birth.day,
student[i].birth.year, student[i].addr);
}
}
if(feof(fp)!= 0)
{
puts(searching done.);
}
puts(continue(yn));
scanf(%c,&choice);
}while(choice=='y' choice=='Y');
fclose(fp);
}

显示资料

void inf_list(FILE fp)
{
int i, m;
for(i=0; feof(fp)==0; i++)
{
if((fread(&student[i], sizeof(ST), 1, fp))!=1 && feof(fp)==0)
{
puts(error);
}
}
m=i-1;
printf(There %d Recordn, m);
printf(Number Name Sex Birth Addressn);
for(i=0; im; i++)
{
printf(%-8d %-12s %-6s %-2d-%-2d-%-4d %-35sn,
student[i].number, student[i].name, student[i].sex,
student[i].birth.month, student[i].birth.day, student

[i].birth.year,
student[i].addr);
}
if(feof(fp)!=0)
{
puts(Display Informtion Done.);
}
fclose(fp);
}

修改资料

void inf_change(FILE fp)
{
int number_temp;
char choice;
int i, m, j=0;
FILE fp_update;

for(i=0; feof(fp)==0; i++) 读取文件
if(fread(&student[i], sizeof(ST), 1, fp)!=1 && feof

(fp)==0)
puts(error);
m=i-1;
do
{
fflush(stdin);
printf(Enter number for change );
scanf(%d, &number_temp);
for(i=0; im; i++)
if(number_temp==student[i].number)
{
j=i;
printf(No. %d Name %s Sex %s Birth %d-%d-%d

Address %sn,
student[i].number, student[i].name, student

[i].sex,
student[i].birth.month, student[i].birth.day,
student[i].birth.year, student[i].addr);
}
if(j==0)
{
puts(No this record.);
break;
}
fflush(stdin);
printf(change data %d (yn), number_temp); 修改确认
scanf(%c,&choice);
if (choice=='n' choice=='N') 修改资料
continue;
printf(No. );
scanf(%d, &student[j].number);
printf(Name );
scanf(%s, student[j].name);
printf(Sex );
scanf(%s, student[j].sex);
printf(Birthdayn);
printf( Year );
scanf(%d, &student[j].birth.year);
printf( month );
scanf(%d, &student[j].birth.month);
printf( day );
scanf(%d, &student[j].birth.day);
printf(Address );
scanf(%s, student[j].addr);

fflush(stdin);
printf(continue(yn));
scanf(%c,&choice);
}while ( choice == 'y' choice == 'Y' );
fp_update=file_operate(w);
for(i=0; im; i++)
if(fwrite(&student[i], sizeof(ST), 1, fp_update)!=1)
puts(update error.);
puts(change done.);
fclose(fp_update);
}
【由于字数限制,请您下载下面文本】
附件:C++学生信息管理系统.txt
参考文献:http://www.52blog.net/user1/19509/archives/2005/222712.shtml