C編寫程式,讀取英語短語,並將其編製成莫爾斯碼

時間 2021-10-30 05:26:15

1樓:匿名使用者

input a sentence: abc abc.

the morse code is:

press any key to continue#include

#include

#include

using namespace std;

char *morsecode(char ch) ;

return morse_code[toupper(ch) - 'a'];

}int main()

else if(s[i] == ' ') cout << " ";

else cout << s[i];

}cout << endl;

return 0;}

2樓:匿名使用者

樓上說的不錯 用陣列簡單些

完整程式:

#include

#include

using namespace std;

const char* morsetable = ;

const char* morsecode(char ch)

int find(const char* code, const char** table,int count)

char morse2char(const char* code)

void translate(char* dstbuf, const char* morsecode)

;char* p = buff;

while(*morsecode)

}else

*p++ = *morsecode;

morsecode++;

}*p = 0;

p = buff;

*dstbuf++ = morse2char(buff);

*dstbuf = 0;

}int main()

, text[2048] = ;

char *p = s;

begin:

cout << "1. encode to morse." << endl << "2.

 decode morse." << endl << "3. exit.

" << endl;

cin >> s;

t = s[1] == 0 ? *s : 0;

switch(t)

cout << endl << "-------------------------------" << endl;

cin.clear();

goto begin;

end:

return 0;

}執行結果:

3樓:冰羽清風

這很簡單啊,對於每個字元,讀後判斷,相對應輸出就行啊

char* mosidianma (char c)}

4樓:

感覺是你寫複雜了。這種題用switch...case解決寫下來太多,用陣列簡單。另題中沒有說標點符號處理,所以下面的**不能處理標點符號。

輸入morse電碼時,即便是最後一位,也不能忘記其後的空格『 』,因為它是morse編碼的一部分。

//#include "stdafx.h"//vc++6.0加上這一行.

#include

using namespace std;

void mrstoeng(const char (*pm)[6],const char *p)

for(j=0;j<36;j++)

if(strcmp(pm[j],a)==0)

i=0;

}else

}void main(void),phr[1000],*pt,k;

cout << "type a short english article...\n";

gets(phr);

for(k=0,pt=phr;*pt;pt++)

cout << "\ntype a string of morse code...\n";

gets(phr);

mrstoeng(m,phr);

cout << "\n";}

莫爾斯碼的c語言怎麼編寫啊

5樓:匿名使用者

定義兩個陣列,一個是char *型,放a-z,0-9的莫爾斯碼,一個是char型,放'a'-'z','0'-'9'.

原文轉電碼時,對每個字元查詢其在第二個陣列中的位置i,那麼第一個陣列中下標為i的就是對應的莫爾斯碼.

電碼轉原文時,在第一個陣列中用strcmp查詢莫爾斯碼,然後第二個陣列中對應字元.

比如,放莫爾斯碼的陣列是char *morse[36],放原文的是char str[36],那麼字元c轉莫爾斯碼就可以這樣:

char *char2morse(char c)

莫爾斯碼轉原文就是

char morse2char(char *m)

用C語言編寫程式,用C語言編寫一個程式

樓上沒有找出相差最小的數而是找出的和平均數比較結果中最小的數 include include void main int v,b 10 int i v a 0 a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 10 for i 0 i 10 i for i 0 i 9 i if...

C語言中如何讀取檔案中的漢字並將其存入陣列中

為了方便文字檔案的操作,標準函式程式設計庫提供了,行讀寫函式,char gets char s char fgets char s,int n,file stream 精通unix下c語言程式設計與專案實踐p66 行輸出函式族 int puts const char s int fputs cons...

c語言請編寫程式來幫,c語言 請編寫一個程式來幫

right prompt wrong prompt 求幫忙編一個c語言程式 本來想著給你答一下。結果發現太遲了,只是編寫了一些 你看一下。如果能用就用。還沒編譯過。一定有很多問題吧。一般 只是參考一下。或可這麼做。include define maxsize 1024 int store maxsi...