chulu的个人空间 https://blog.eetop.cn/chulu [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

C语言课程设计报告

已有 1419 次阅读| 2008-8-14 13:32 |个人分类:技术文章

  


C语言课程设计报告

 一:摘要

1—中文摘要

1.1—多级菜单:

本程序采用图形界面,并由三大模块构成:各级菜单参数加载模块、基础作图模块、各级菜单控制管理模块。其中,各级菜单控制管理模块是本程序实现菜单功能的核心,该模块提供了菜单激活、交替、指令执行、图形管理等复杂操作。另外,本程序二级子菜单具有一定的可扩展性,可随意改变二级子菜单的个数、位置、功能。所有的菜单都采用相同的结构数组,便于管理和扩展。

1.2—加密解密文本文件:

采用把文件中分为二,交替排列的加密算法,打乱了源文件的字符数据顺序,提供了对单个字符以外加密算法,且本算法可以和常见的对单个字符与、或、异或等操作相结合,提高加密等级。在对加密后的文件进行解密时,对原加密算法进行逆推,从而还原源文件。

 

关键词:多级子菜单设计、加密解密文件、加密解密中分算法

2—英文摘要:

2.1 -----Multi-level menu

This program used a graphical interface,and it has three modules: the menu at all levels to load the module parameters, basic mapping module, control and manage the menu at all levels modules. The module of control and manage the menu at all levels  is the core function of the menu, the module provides a menu activated, alternately, instruction execution, graphics management, and other complex operations. In addition,the two sub-menu of this program is scalable, free to change the number of two sub-menu, location, function. All the menu are the same array structure, so it’s easy to manage and expand.

2.2----- Text file encryption and decryption:

 

This program  make a document  divided into two parts, with the encryption algorithm of alternate with each character. It will disrupted the sequence of source characters add data,but it’ll provid an encryption algorithm that do not process individual characters. And this algorithm can be used together with process individual character,such as: or, or vary, xor.

It also can improve the grade of encryption.When decrypting the file which have been encryted, we will use a backstepping original encryption algorithm .Then we will get the source file.

 

Keywords: Multi-level sub-menu designFile encryption and decryptionEncryption and decryption algorithm of divide in middle.

二:程序分析

1—        多级菜单:

1.1模块分析:

基础作图模块有以下函数:

void initg();/*图形初始化*/

void drawsub1(int num);/*一级子菜单作图*/

void drawsub2(int m_num);/*二级子菜单作图*/

各级菜单参数加载模块有以下函数:

void getitemcount(char **s,int *count ,int *maxlen);/*得到标题字符串的个数*/

void loadmain();/*得到主菜单的各项参数,并画出主菜单*/

void loadsub1(char **sname,int num);/*得到一级子菜单的各项参数*/

void loadsub2(char **sname2,int num_m,int num_s,int num_o);/*得到二级子菜单的各项参数*/

各级菜单控制管理模块有以下函数:

void Pmain(int oid,int nid,int mod);/*处理主菜单中选择项的交替*/

void managemain();/*管理按键选择时的操作*/

void managesub1(int n);/*一级子菜单管理*/

void PSUB1(int os,int ns,int mn,int m);/*处理一级子菜单选择项的交替*/

void saveimage(int mo,int num);/*图像缓冲*/

void managesub2(int n);/*二级子菜单管理*/

void PSUB2(int so,int sn,int sm);/*处理二级子菜单选择项的交替*/

void cmdid(int,int,int);/*指令执行管理函数*/

 

2—加密解密文本文件:

2.1 文件中分为二交替排列的加密算法:

do

    {

             r=getc(in);

             flen++;

    }

while(!feof(in));

此循环得到文件里面字符的总数目

flen--;

         if(flen%2==0)

         {

                   j=flen/2;

                   i=j-1;                  

                   do

                   {

                            fseek(in,i,SEEK_SET);

                       r=getc(in)+N;

                       fputc(r,out);

                       fseek(in,j,SEEK_SET);

                       r=getc(in)+N;

                       fputc(r,out);

                       i--;

                       j++;

                   }

                   while(i>=0&&j<=flen-1);

         }

当文件字符个数为偶数时的算法。下面举例说明:

若文件有这样几个字符:ABCDEFGH,中分算法将在DE之间分开,把左侧一个字符写入加密文件,接着把右侧一个字符写入加密文件,如此交替进行,最后的加密结果为:DECFBGAH

         else

         {

                   k=(flen-1)/2;

                   i=k-1;

                   j=k+1;

                   do

                   {

                            fseek(in,i,SEEK_SET);

                            r=getc(in)+N;

                            fputc(r,out);

                            fseek(in,j,SEEK_SET);

                            r=getc(in)+N;

                            fputc(r,out);

                            i--;

                            j++;

                   }

                   while(i>=0&&j<flen);

         }

当文件字符个数为奇数时的算法。下面也举例说明:

若文件有这样几个字符:ABCDEFGHI,中分算法将以中间字符E为分隔线,先把此字符写入加密文件,然后把左侧一个字符写入加密文件,接着把右侧一个字符写入加密文件,如此交替进行,最后的加密结果为:EDFCGBHAI

2.2解密算法:

do

    {   s=getc(in);

             fleng++;

    }

while(!feof(in));

同加密算法一样,先得到文件字符总数。

    fleng--;

    if(fleng%2==0)

    {   o=fleng-2;

             p=1;

             do

             {

                       fseek(in,o,SEEK_SET);

                       s=getc(in)-N;

                       fputc(s,out);

                       o-=2;

             }

             while(o>=0);

             do

             {        fseek(in,p,SEEK_SET);

                       s=getc(in)-N;

                       fputc(s,out);

                       p+=2;

             }

             while(p<=fleng-1);      

}

字符个数为偶数时的算法。举例说明:

文件有如下字符:DECFBGAH,先将倒数第二个字符写入解密文件,再将倒数第四个字符写入解密文件,每次去字符的步长为2,当写入了第一个字符后,开始把第二个字符写入,步长也为2,直到写完最后一个字符,解密完成。解密结果为:ABCDEFGH

    else

    {   o=fleng-2;

             p=0;

             do

             {        fseek(in,o,SEEK_SET);

                       s=getc(in)-N;

                       fputc(s,out);

                       o-=2;

             }

             while(o>=1);

             do

             {        fseek(in,p,SEEK_SET);

                       s=getc(in)-N;

                       fputc(s,out);

                       p+=2;

             }

             while(p<=fleng-1);

    }

字符个数为奇数时的算法。此时和偶数时的解密算法类似,只不过在倒着取字符写入解密文件时要取到第二个字符,然后再正着从第一个字符开始取字符写入解密文件。

 

三:参考资料:

程序设计实训(C语言) 高等教育出版社  王达贤、陆虹等合编

C/C++语言程序设计      清华大学出版社  孟军、赵晶、王凡 编著

C语言实例解析精粹   人民邮电出版社   曹衍龙, 林瑞仲, 徐慧 编著

四:附录:

1—多级子菜单源程序:

#include "stdio.h"

#include "graphics.h"

#include "bios.h"

#define NUM 10

#define ESC 0x11b

#define TAB 0x0f09

#define ENTER 0x1c0d

#define RIGHT 0x4d00

#define LEFT 0x4b00

#define UP 0x4800

#define DOWN 0X5000

#define A 0X1e61

#define E 0X1265

#define F 0X2166

#define P 0X1970

#define V 0X2f76

 

typedef struct

{

         int xy_self[4];

         int xy_item[4*NUM];

         int xy_title[2*NUM];

         char **title;

         int commandid[NUM];

         int num_item;

         int maxl;

} my_menu;

my_menu Mainmenu,sub1[5],sub2[4];

 

char *Main[]={"File..[F]","Edit..[E]","Project..[P]","View..[V]","About..[A]",0};

char *Sub11[]={"Open..[O]","New..[N]","Load..[L]","Save..[S]..","More..[M]","Quit..[Q]",0};

char *Sub12[]={"Undo..[U]","Copy..[C]","Paste..[P]","Select All..[A]","Quit..[Q]",0};

char *Sub13[]={"Sub13..[0]","Sub13..[1]","Quit..[Q]",0};

char *Sub14[]={"Sub14..[0]","Sub14..[1]","Quit..[Q]",0};

char *Sub15[]={"Sub15..[0]","Sub15..[1]","Quit..[Q]",0};

char *Sub21[]={"Sub21..[0]","Sub21..[1]","Sub21..[2]","Quit..[Q]",0};

char *Sub22[]={"Sub22..[0]","Sub22..[1]","Sub22..[2]","Quit..[Q]",0};

char *Sub23[]={"Sub23..[0]","Sub23..[1]","Sub23..[2]","Quit..[Q]",0};

char *Sub24[]={"Sub24..[0]","Sub24..[1]","Sub24..[2]","Quit..[Q]",0};

int TW,TB=50,LR=20,MX=640,MY=480;

int Mcount,Mmaxlen;

int mflag=0,s1flag=0,s2flag=0;

/*各菜单激活标志:mflag=1主菜单激活,s1flag=1一级子菜单激活,s2flag=1二级子菜单激活*/

void *imagebuf[2];/*图像缓冲区*/

 

void initg();/*图形初始化*/

void getitemcount(char **s,int *count ,int *maxlen);/*得到标题字符串的个数*/

void loadmain();/*得到主菜单的各项参数,并画出主菜单*/

void Pmain(int oid,int nid,int mod);/*处理主菜单中选择项的交替*/

void managemain();/*管理按键选择时的操作*/

void loadsub1(char **sname,int num);/*得到一级子菜单的各项参数*/

void loadsub2(char **sname2,int num_m,int num_s,int num_o);/*得到二级子菜单的各项参数*/

void drawsub1(int num);/*一级子菜单作图*/

void drawsub2(int m_num);/*二级子菜单作图*/

void managesub1(int n);/*一级子菜单管理*/

void PSUB1(int os,int ns,int mn,int m);/*处理一级子菜单选择项的交替*/

void saveimage(int mo,int num);/*图像缓冲*/

void managesub2(int n);/*二级子菜单管理*/

void PSUB2(int so,int sn,int sm);/*处理二级子菜单选择项的交替*/

void cmdid(int,int,int);

main()

{

    initg();

    TW=textwidth("P");  

    loadmain(); /*载入主菜单*/

    loadsub1(Sub11,0);/*载入各个一级子菜单*/

    loadsub1(Sub12,1);

    loadsub1(Sub13,2);

    loadsub1(Sub14,3);

    loadsub1(Sub15,4);

    loadsub2(Sub21,0,0,0);/*二级子菜单各标题,对应主菜单位置,对应一级子菜单位置,在二级子菜单中的编号*/    

    loadsub2(Sub22,1,0,1);

    loadsub2(Sub23,4,0,2);

    loadsub2(Sub24,3,0,3);

    loadsub2(Sub24,2,1,3);

    managemain();   

    getch();

    closegraph();

}

 

void initg()/*图形模式初始化并画出主窗口*/

{

        

         int gd=9,gm=2;

         initgraph(&gd,&gm,"");

         setbkcolor(8);

         setfillstyle(1,1);

         bar(LR,TB,640-LR,480-TB);/*主窗口位置*/

        

}

 

void getitemcount(char **s,int *count ,int *maxlen)

{

         int i,j=0;

         for(i=0;s[i]!=NULL;i++)

         {

                   j=strlen(s[i]);            

                   if(j>(*maxlen))

                   (*maxlen)=j;/*菜单中标题最长的个数*/

         }

         (*count)=i;/*子菜单项的个数*/

}

void loadmain()

{       

         int i=0,j=0;

        

         getitemcount(Main,&Mcount,&Mmaxlen);

         /*主菜单区域坐标*/              

         Mainmenu.xy_self[0]=LR;

         Mainmenu.xy_self[1]=TB;

         Mainmenu.xy_self[2]=MX-LR;

         Mainmenu.xy_self[3]=TB+20;

         Mainmenu.title=Main;        


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 9

    评论
  • 71

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-6 04:49 , Processed in 0.024820 second(s), 16 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部