• 打字软件(最终版本)


    /* 
    * type_combined.c 
    */
    
    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "getputch.h"
    
    #define    NO            3            /* 训练次数 */
    #define    KTYPE        16            /* 块数 */
    #define    POS_LEN        10            /* 用于位置训练的字符数量 */
    
    /*--- 练习菜单 ---*/
    typedef enum { Term, KeyPos, KeyPosComp, Clang, Conversation, InValid } Menu;
    
    /*--- 各个块的键 ---*/
        char *kstr[] = {"12345", "67890-=",
                        "!@#$%", "^&*()_+",
                        "qlert", "yuiop[]\",
                        "QWERT", "YUIOP{}|",
                        "asdfg", "hjkl;'",
                        "ASDFG", "HJKL:""
                        "zxcvb", "nm,./",
                        "ZXCVB", "NM<>?",
    };
    
    /*--- C语言的关键字和库函数 ---*/
    char *cstr[] = {
        "auto",        "break",    "case",        "char",        "const",    "continue",
        "default",    "do",        "double",    "else",        "enum",        "extern",
        "float",    "for",        "goto",        "if",        "int",        "long",
        "register",    "return",    "short",    "signed",    "sizeof",    "static",
        "struct",    "switch",    "typedef",    "union",    "unsigned",    "void",
        "volatile",    "while",
        "abort",    "abs",        "acos",        "asctime",    "asin",        "assert",
        "atan",        "atan2",    "atexit",    "atof",        "atoi",        "atol",
        "bsearch",    "calloc",    "ceil",        "clearerr",    "clock",    "cos",
        "cosh",        "ctime",    "difftime",    "div",        "exit",        "exp",
        "fabs",        "fclose",    "feof",        "ferror",    "fflush",    "fgetc",
        "fgetpos",    "fgets",    "floor",    "fmod",        "fopen",    "fprintf",
        "fputc",    "fputs",    "fread",    "free",        "freopen",    "frexp",
        "fscanf",    "fseek",    "fsetpos",    "ftell",    "fwrite",    "getc",
        "getchar",    "getenv",    "gets",        "gmtime",    "isalnum",    "isalpha",
        "iscntrl",    "isdigit",    "isgraph",    "islower",    "isprint",    "ispunct",
        "isspace",    "isupper",    "isxdigit",    "labs",        "ldexp",    "ldiv",
        "localeconv",            "localtime","log",        "log10",    "longjmp",
        "malloc",    "memchr",    "memcmp",    "memcpy",    "memmove",    "memset",
        "mktime",    "modf",        "perror",    "pow",        "printf",    "putc",
        "putchar",    "puts",        "qsort",    "raise",    "rand",        "realloc",
        "remove",    "rename",    "rewind",    "scanf",    "setbuf",    "setjmp",
        "setlocale","setvbuf",    "signal",    "sin",        "sinh",        "sprintf",
        "sqrt",        "srand",    "sscanf",    "strcat",    "strchr",    "strcmp",
        "strcoll",    "strcpy",    "strcspn",    "strerror",    "strftime",    "strlen",
        "strncat",    "strncmp",    "strncpy",    "strpbrk",    "strrchr",    "strspn",
        "strstr",    "strtod",    "strtok",    "strtol",    "strtoul",    "strxfrm",
        "system",    "tan",        "tanh",        "time",        "tmpfile",    "tmpnam",
        "tolower",    "toupper",    "ungetc",    "va_arg",    "va_end",    "va_start",
        "vfprintf", "vprintf",    "vsprintf"
    };
    
    /*--- 英语会话 ---*/
    char *vstr[] = {
        "Hello!",                            /* 你好。*/
        "How are you?",                        /* 你好吗?*/
        "Fine thanks.",                        /* 嗯,我很好。*/
        "I can't complain, thanks.",        /* 嗯,还行吧。*/
        "How do you do?",                    /* 初次见面。*/
        "Good bye!",                        /* 再见。*/
        "Good morning!",                    /* 早上好。*/
        "Good afternoon!",                    /* 下午好。*/
        "Good evening!",                    /* 晚上好。*/
        "See you later!",                    /* 再见(过会见)。*/
        "Go ahead, please.",                /* 您先请。*/
        "Thank you.",                        /* 谢谢。*/
        "No, thank you.",                    /* 不,谢谢。*/
        "May I have your name?",            /* 请问你叫什么名字?*/
        "I'm glad to meet you.",            /* 很高兴能见到你。*/
        "What time is it now?",                /* 请问现在是几点?*/
        "It's about seven.",                /* 大概7点。*/
        "I must go now.",                    /* 我不得不走了。*/
        "How much?",                        /* 多少钱?*/
        "Where is the restroom?",            /* 请问洗手间在哪里?*/
        "Excuse me.",                        /* 抱歉(一人)。*/
        "Excuse us.",                        /* 抱歉(两人以上)。*/
        "I'm sorry.",                        /* 对不起。*/
        "I don't know.",                    /* 我不知道。*/
        "I have no change with me.",        /* 我没带零钱。*/
        "I will be back.",                    /* 我还会回来的。*/
        "Are you going out?",                /* 你要出门吗?*/
        "I hope I'm not disturbing you.",    /* 希望不会打搅到你。*/
        "I'll offer no excuse.",            /* 我没打算为自己辩解。*/
        "Shall we dance?",                    /* 来跳舞吧。*/
        "Will you do me a favor?",            /* 你能帮我个忙吗?*/
        "It's very unseasonable.",            /* 这非常不合时节啊。*/
        "You are always welcome.",            /* 随时欢迎。*/
        "Hold still!",                        /* 别动!*/
        "Follow me.",                        /* 跟我来。*/
        "Just follow my lead.",                /* 跟着我做就好。*/
        "To be honest with you,",            /* 说真的……*/
    };
    
    Menu SelectMenu()
    {
        int ch;
        do
        {
            printf("
    Please select practice. 
    ");
            printf("(1)Only Single		(2)Combined Position
    ");
            printf("(3)C Language word	(4)English Dialogue
    ");
            scanf("%d", &ch);
        }while(ch < Term || ch >= InValid);
    
        return (Menu)ch;
    }
    
    int go(const char *str)
    {
        int i, len = strlen(str), mistakes = 0;
    
        for (i = 0; i < len; i++)
        {
            printf("%s 
    ", &str[i]);
            fflush(stdout);
            while(getch() != str[i])
            {
                mistakes++;
            }
        }
    
        return mistakes;
    }
    
    void pos_training(void)
    {
        int i, stage, temp, line, len, qno, pno , tno, mno;
        clock_t start, end;
    
        printf("
    Starting single position to practice. 
    ");
        printf("please select a block to practice. 
    ");
        printf("The First floor (1) left %-8s (2) right %-8s
    ", kstr[0], kstr[1]);
        printf("The First floor (3) left %-8s (4) right %-8s
    ", kstr[4], kstr[5]);
        printf("The First floor (5) left %-8s (6) right %-8s
    ", kstr[8], kstr[9]);
        printf("The First floor (7) left %-8s (8) right %-8s
    ", kstr[12], kstr[13]);
    
        do
        {
            printf("number (99 is stop) : ");
            scanf("%d", &temp);
            if (temp == 99)
            {
                return;
            }
        }while(temp < 1 || temp > 8);
    
        line = 4 * ((temp - 1) / 2) +  (temp - 1) % 2;
    
        printf("practice %s times %d topices. 
    ", kstr[line], NO);
    
        printf("Starting after entering space. 
    ");
        while(getch() != ' ')
            ;
    
        tno = mno = 0;
        len = strlen(kstr[line]);
    
        start = clock();
        for (stage = 0; stage < NO; stage++)
        {
            char str[POS_LEN + 1];
    
            for (i = 0; i < POS_LEN; i++)
            {
                str[i] = kstr[line][rand() % len];
            }
            str[i] = '';
    
            mno += go(str);
            tno += strlen(str);
        }
    
        end = clock();
    
        printf("Title: %d characters/Mistakes: %d times
    ", tno, mno);
        printf("Costing time : %.1f seconds. 
    ", (double)(end-start)/CLOCKS_PER_SEC);
            
    }
    
    void pos_training2()
    {
        int i, stage, temp, line, sno, select[KTYPE], len[KTYPE], tno, mno;
        clock_t start, end;
        char *format = "the %d floor (%2d) left %-8s (%2d)    right %-8s"
                        "(%2d)[left] %-8s (%2d)[right] %-8s
    ";
    
        printf("
    Go to on combined training. 
    ");
        printf("Please select the block you wanted to practice(More). 
    ");
    
        for (i = 0; i < 4; i++)
        {
            int k = i * 4;
            printf(format, i+1, k+1, kstr[k], k+2, kstr[k+1],
                    k+3, kstr[k+2], k+4, kstr[k+3]);
        }
    
        sno = 0;
        while(1)
        {
            printf("number (end select--50/stop practice--99): ");
            do
            {
                scanf("%d", &temp);
                if (temp == 99) return ;
            }while((temp < 1 || temp > KTYPE) && temp != 50);
    
            if (temp == 50)
            {
                break;
            }
    
            for (i = 0; i < sno; i++)
            {
                if (temp == select[i])
                {
                    printf("aThat floor is already selected. 
    ");
                    break;
                }
            }
    
            if ( i == sno)
            {
                select[sno++] = temp;
            }
        }
    
        if (0 == sno)
        {
            return;
        }
    
        printf("Make the following block practicing %d times.
    ", NO);
    
        for (i = 0; i < sno; i++)
        {
            printf("%s ", kstr[select[i] - 1]);
        }
    
        printf("
    Entering the space to start. 
    ");
        while(getch() != ' ')
            ;
    
        tno = mno = 0;
        for (i = 0; i < sno; i++)
        {
            len[i] = strlen(kstr[select[i] - 1]);
        }
    
        start = clock();
    
        for (stage = 0; stage < NO; stage++)
        {
            char str[POS_LEN + 1];
    
            for (i = 0; i < POS_LEN; i++)
            {
                int q = rand() % sno;
                str[i] = kstr[select[q] - 1][rand() % len[q]];
            }
            str[i] = '';
    
            mno += go(str);
            tno += strlen(str);
        }
        end = clock();
    
        printf("Title: %d characters/Mistakes: %d
    ", tno, mno);
        printf("Costint time %.1f seconds. 
    ",(double)(end-start)/CLOCKS_PER_SEC);
    }
    
    void word_training(char *mes, char *str[], int n)
    {
        int stage, qno, pno, tno, mno;
        clock_t start, end;
    
        printf("
    pracetice %d numbers %s 
    ", NO, mes);    
        printf("Entering space to start. 
    ");
    
        while(getch() != ' ')
            ;
    
        tno = mno = 0;
        pno = n;
    
        start = clock();
        for (stage = 0; stage < NO; stage++)
        {
            do
            {
                qno = rand() % n;
            }while(qno == pno);
    
            mno += go(str[qno]);
            tno += strlen(str[qno]);
            pno = qno;
        }
        end = clock();
    
        printf("Title: %d characters/Mistakes: %d times 
    ", tno, mno);
        printf("Costint time %.1f seconds. 
    ",(double)(end-start)/CLOCKS_PER_SEC);
        
    }
    
    int main()
    {
        Menu menu;
        int cn = sizeof(cstr) / sizeof(cstr[0]);
        int vn = sizeof(vstr) / sizeof(vstr[0]);
    
        init_getputch();
    
        srand(time(NULL));
    
        do
        {
            switch(menu = SelectMenu())
            {
                case KeyPos:
                    pos_training();
                    break;
    
                case KeyPosComp:
                    pos_training2();
                    break;
                    
                case Clang:
                    word_training("C Language word", cstr, cn);
                    break;
                    
                case Conversation :
                    word_training("English conversation file", vstr, vn);
                    break;
            }
        }while(menu != Term);
    
        term_getputch();
        return 0;
    
    }
  • 相关阅读:
    URL 中使用 Base64 编码
    一个简单实用的C#日志类(第二版)
    C# 对象XML序列化
    VS2010安装项目的系统必备中添加.NET 2.0
    .NET Framework 4 安装程序
    使用ExeConfigurationFileMap读写配置文件
    C# 生成 XML
    Bug管理工具和测试管理工具介绍
    Android学习系列(19)App离线下载
    Android拓展系列(5)CyanogenMod源码下载和编译(Android ROM定制基础篇)
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/12015402.html
Copyright © 2020-2023  润新知