單詞本管理系統c語言,個人通訊錄管理系統c語言

本文目錄一覽:

用c語言編寫背單詞系統要求背單詞和測驗,瀏覽單詞

#include stdio.h

#include stdlib.h

#include string.h

#include time.h

struct word

{

    char english[30];

    char chinese[100];

    int  count;         /* 記錄背單詞的正確次數 */

}dic[4000];

char getChoice()

{

    char str[10];

    gets(str);

    while (strlen(str)==0)

    {

        printf(“輸入為空,請重新輸入:”);

        gets(str);

    }

    return str[0];

}

int main()

{

    FILE *fp;

    char ch,line[100];

    int kong,i,count=0,j=0,end=0,k=0;

    int last_process = 0;

    if((fp=fopen(“cet4.txt”,”r”))==NULL)

    {

        printf(“cannot open the txt!!!\n”);

        exit(0);

    }

    /* 讀取所有單詞 */

    while(fgets(line,sizeof(line),fp)!=0)

    {

        /* 每一行記錄的格式【單詞 中文 正確數】*/

        /* 讀取單詞 */

        j=0;

        for(i=0;iline[i]!=’ ‘;i++)

        {

            dic[count].english[j]=line[i];

            j++;

        }

        dic[count].english[i]=’\0′;

        /* 特殊處理,如果這個字段是自定義的上次進度標記,則記下進度,假如進度標記是#last_process# */

        if(strcmp(dic[count].english,”#last_process#”) == 0)

        {

            last_process = atoi(line+i+1);

            continue;

        }

        /* 讀取中文 */

        j=0;

        for(i=kong+1;iline[i]!=’ ‘;i++)

        {

            dic[count].chinese[j]=line[i];

            j++;

        }

        dic[count].chinese[j]=’\0′;

        /* 正確數 */

        dic[count].count = atoi(line+i+1);

        count++;

    }

    fclose(fp);

    /* 打印下讀取的信息 */

    printf(“單詞數:%d\n上次背到第%d個單詞\n”, count, last_process);

    /*while*/ 

    /* 這裡背單詞策略,可以根據count來判斷單詞熟悉度,該值越大表示越熟悉 */

    /* 負數表示記錯了的次數,錯的越多,負的越大 */

    i = last_process;

    while(ch!=0)

    {

        // 可根據需要排序單詞,排序依據是count字段大小

        puts(“\n1.隨機20個單詞測試\n”);

        puts(“\n2.強化記憶\n”);

        puts(“\n前一個(P)後一個(N)收藏(C)結束瀏覽(M)”);

        while(ch!=0)

        {

            ch=getChoice();

            if(ch==’P’||ch==’p’)

            {

                i = (last_process+count-1)%count;

                printf(“%s\n\n”,dic[i].english);

                printf(“%s\n\n”,dic[i].chinese);

            }

            if(ch==’N’||ch==’n’)

            {

                i = (last_process+1)%count;

                printf(“%s\n\n”,dic[i].english);

                printf(“%s\n\n”,dic[i].chinese);

            }

            else if(ch==’C’||ch==’c’)

            {

                printf(“已經加入單詞本”);

            }

            if(ch==’M’||’m’)

            {

                break;

            }

        }

    }

    /* 程序退出 */

    last_process = i;

    if((fp=fopen(“cet4.txt”,”w”))==NULL)

    {

        printf(“cannot open the txt!!!\n”);

        exit(0);

    }

    /* 把單詞進入重新寫入單詞文件 */

    for (i=0; icount; i++)

    {

        fprintf(fp, “%s %s %d\n”, dic[i].english, dic[i].chinese, dic[i].count);

    }

    fprintf(fp,”#last_process# %d”, last_process);

    fclose(fp);

    

    return 0;

}

大致這樣子,懶得寫了~~~有需要可討論

用C語言編寫“背單詞 程序”

#includestdio.h

#includestdlib.h

#includestring.h

struct word //定義一個word的結構體,裡面的兩個成員分別放英語單詞和相應的漢語翻譯

{

char chinese[20];

char english[20];

};

int point=0; //統計分數的

int count1=0; //測試的次數

void tianjia(struct word str[100],int count); //函數聲明,往詞庫中添加詞組

void shuchu(struct word str[100],int count); //函數聲明,輸出詞庫中所有的詞組

void fanyi1(struct word str[100],int count); //函數聲明,輸入漢語,對英語翻譯的考察

void fanyi2(struct word str[100],int count);

void chaxun(int point,int count1); //函數聲明,輸出成績!

void main()

{

int count=0;

struct word str[100]; //定義一個結構體數組str

int n;

char ch,chioch;

while(1)

{

printf(“*************背單詞系統*********************\n”);

printf(“*************1,添加詞庫*********************\n”);

printf(“*************2,漢譯英***********************\n”);

printf(“*************3,英譯漢***********************\n”);

printf(“*************4,輸出所有詞庫*****************\n”);

printf(“*************5,成績查詢*********************\n”);

printf(“*************0,退出*************************\n”);

printf(“********************************************\n”);

printf(“請輸入你要經行的操作:\n”);

scanf(“%d”,n);

switch(n)

{

case 1:tianjia(str,count);break; //函數調用

case 2:fanyi1(str,count);break; //函數調用

case 3:fanyi2(str,count);break; //函數調用

case 4:shuchu(str,count);break;

case 5:chaxun(point,count1);break; //函數調用

case 0:{printf(“你確認要退出嗎?y/n!!\n”);

scanf(“%c%c”,ch,chioch);

if(ch==’y’||ch==’Y’) exit(0);

}

default :printf(“你輸入了錯誤的操作,無法執行!!!”);

exit(0);

}

}

}

void tianjia(struct word str[100],int count) //往詞庫中添加詞組

{

char ch;

do{

printf(“錄入詞庫!!!\n”);

printf(“請輸入詞庫中的英語單詞:\n”);

scanf(“%s”,str[count].english);

printf(“\n請輸入相應的中文意思:\n”);

scanf(“%s”,str[count].chinese);

count++;

printf(“是否繼續錄入?y/n!!!\n”);

scanf(“%s”,ch);

}while(ch==’y’);

printf(“%d\n\n”,count);

}

void shuchu(struct word str[100],int count) // 輸出詞庫中所有的詞組

{

int i=0;

printf(“輸出詞庫中所有的單詞!!!\n”);

if(count=0) {printf(“沒有任何單詞,無法輸出!!!\n”);return;}

else {

for(i=0;icount;i++){

printf(“英文單詞是:%s”,str[i].english);

printf(“\n相應的中文意思是:%s”,str[i].chinese);

printf(“\n\n”);

}

printf(“詞庫所有單詞輸入完畢!!!!\n”);

}

}

void fanyi1(struct word str[100],int count) //輸入漢語,對英語翻譯的考察

{

int i;

char ch[20];

char bh[20];

printf(“請輸入英語單詞:\n”);

scanf(“%s”,ch);

printf(“請輸入翻譯後的中文:\n”);

scanf(“%s”,bh);

for(i=0;icount;i++)

{

if(strcmp(ch,str[i].english)==0)

{

if(strcmp(bh,str[i].chinese)==0)

{

point++;

count1++;

printf(“恭喜你!!答對了!!!\n”);

}

else

{

count1++;

printf(“很遺憾,答錯了!!!正確的翻譯是:%s\n”,str[i].chinese);

}

}

}

}

void fanyi2(struct word str[100],int count) //輸入英語,對漢語翻譯的考察

{

int i;

char ch[20];

char bh[20];

printf(“請輸入中文:\n”);

scanf(“%s”,ch);

printf(“請輸入翻譯後的英文:\n”);

scanf(“%s”,bh);

for(i=0;icount;i++)

{

if(strcmp(ch,str[i].chinese)==0)

{

if(strcmp(bh,str[i].english)==0){

point++;

count1++;

printf(“恭喜你!!答對了!!!\n”);

}

else

{

count1++;

printf(“很遺憾,答錯了!!!正確的翻譯是:%s\n”,str[i].english);

}

}

}

}

void chaxun(int point,int count1)

{

printf(“本次測試的成績是:\n”);

printf(“總共:%d個\n”,count1);

printf(“正確:%d個\n”,point);

// printf(“正確率為:%d\%\n”,point*100/count1);

}

C語言 單詞檢索程序

=====================================

問題補充:二樓的是死循環運行不了啊

=====================================

實在抱歉,之前疏忽了,現在已經改好了,再試一下吧:)

=====================================

問題補充:二樓的幸苦了,仔細看了一下你的,好像有點出入,不是自己輸入文章,是打開已有文章。還得麻煩你稍稍修改下。謝謝哈

=====================================

根據你的要求,又改了一版,現在已經改好了,再試一下吧:)

給:

#includestdio.h

#includestring.h

#define MAX_size 1000

int flag=1,degree=0;

void Index(char str[],char word[],int position[])

{

int i,len_str,len_word,pos_str,pos_word,k=0,word_number=0;//word_number代表短文中單詞的個數

len_word=strlen(word);

len_str=strlen(str);

for(i=0;ilen_str;i++)

{

while(str[i]==’ ‘||str[i]==’,’||str[i]==’.’)

i++;

word_number++; //單詞個數加一

for(pos_str=i,pos_word=0;pos_strlen_str pos_wordlen_word;pos_str++,pos_word++)

{

if(str[pos_str]!=word[pos_word])

break;

}

if(pos_word==len_word (str[pos_str]==’\0’|| str[pos_str]==’ ‘||str[pos_str]==’,’||str[pos_str]==’.’)) //表明找到相等的單詞

{

position[k++]=word_number;

degree++; //相等的次數加1

flag=0;

}

else

{

while(str[pos_str]!=’ ‘str[pos_str]==’,’str[pos_str]==’.’ pos_strlen_str)

pos_str++;

}

i=pos_str;

}

}

void main()

{

char str[MAX_size],word[20],ch;

int position[100],i;

int k=0;

FILE *fp;

if((fp=fopen(“a.txt”,”r”))!=NULL)

{

while(1)

{

ch=fgetc(fp);

if(ch==EOF) break;

str[k]=ch;

k++;

}

}

printf(“請輸入要檢索的單詞: \n”);

gets(word);

Index(str,word,position);

if(flag)

printf(“您輸入的單詞不在短文中。\n”);

else

{

printf(“您輸入的單詞在短文中,它共出現 %-d 次\n”,degree);

printf(“出現的位置為: \n”);

for(i=0;idegree;i++)

printf(“第%-2d個單詞\n”,position[i]);

}

fclose(fp);

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/297675.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-28 12:16
下一篇 2024-12-28 12:16

相關推薦

  • 銀行資金管理系統總結

    銀行資金管理系統是銀行日常業務運營的核心支撐系統,主要負責處理銀行的資金流動、結算、清算等業務。本文將從功能特點、技術架構、安全性以及未來發展趨勢等多個方面對銀行資金管理系統進行詳…

    編程 2025-04-29
  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • 北化教務管理系統介紹及開發代碼示例

    本文將從多個方面對北化教務管理系統進行介紹及開發代碼示例,幫助開發者更好地理解和應用該系統。 一、項目介紹 北化教務管理系統是一款針對高校學生和教職工的綜合信息管理系統。系統實現的…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28

發表回復

登錄後才能評論