日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

复习了C++前几章,做一个ASCII码转换的小程序

發布時間:2023/12/20 c/c++ 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 复习了C++前几章,做一个ASCII码转换的小程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

復習了一下輸入輸出、for和switch,做了一個ASCII碼轉換的小東西。

#include <iostream> #include <string>using namespace std;void numtoalfa(void); void alfatonum(void); void showthem(void);const int STARTOFASCII = 33; const int ENDOFASCII = 126; int main() {int k;cout << "ASCII碼轉換:" << endl;cout << "1:字符找碼" << endl;cout << "2:碼找字符" << endl;cout << "3:顯示全部" << endl;cout << "0:退出程序" << endl;cout << "輸入數字選擇對應功能:" << endl;cin >> k;while (k != 0){switch (k){case 1:alfatonum(); break;case 2:numtoalfa(); break;case 3:showthem(); break;default:cout << "輸入有誤!" << endl<<endl;}cout << "ASCII碼轉換:" << endl;cout << "1:字符找碼" << endl;cout << "2:碼找字符" << endl;cout << "3:顯示全部" << endl;cout << "0:退出程序" << endl;cout << "輸入數字選擇對應功能:" << endl;cin >> k;}cin.get(); }void alfatonum() {cout << "輸入需要轉換的字符(可連續輸入;輸入“quit”返回上一層):" << endl;string ch;cin >> ch;while (ch != "quit"){int count = 0;int i;int q = ch.size();for (count = 0; count < q; count++){i = ch[count];cout << endl;cout << "\t“"<<ch[count]<<"” " << "的ASCII碼為:" << i << endl << endl;}cout << "輸入需要轉換的字符(可連續輸入;輸入“quit”返回上一層):" << endl;cin >> ch;} }void numtoalfa() {cout << "輸入需要查找的ASCII碼(33-126為有效范圍)(輸入“0”返回上一層):" << endl;int n;cin >> n;while (n != 0){if (n >= 33 && n<=126){char ch;ch = n;cout << endl;cout << "\tASCII碼" << n << ",對應的字符為:" << ch << endl << endl;cout << "輸入需要查找的ASCII碼(輸入“0”返回上一層):" << endl;}elsecout << "\t輸入數字不在范圍內!" << endl << endl;cin>>n;} }void showthem() {cout << "選擇需要輸出的范圍:(輸入“0”返回上一層)" << endl;cout << "1:輸出數字(0-9)對應的ASCII碼" << endl;cout << "2:輸出大寫字母(A-Z)對應的ASCII碼" << endl;cout << "3:輸出小寫字母(a-z)對應的ASCII碼" << endl;cout << "4:輸出全部" << endl;int n;cin >> n;while (n != 0){cout << endl;switch (n){case 1:{int count;int count3 = 0;int shownumber;char ch = '0';for (count = 0; count < 10; count++, ch++){shownumber = ch;cout <<" “" <<ch<<"” " << "對應的ASCII碼為: " << shownumber << "\t";count3++;if (count3 == 3){count3 = 0;cout << endl;}}}; break;case 2:{int count;int count3 = 0;int shownumber;char ch = 'A';for (count = 1; count < 27; count++, ch++){shownumber = ch;cout << " “"<<ch <<"” " << "對應的ASCII碼為: " << shownumber << "\t";count3++;if (count3 == 3){count3 = 0;cout << endl;}}}; break;case 3:{int count;int shownumber;int count3 = 0;char ch = 'a';for (count = 1; count < 27; count++, ch++){shownumber = ch;cout <<" “"<< ch<<"” " << "對應的ASCII碼為: " << shownumber << "\t";count3++;if (count3 == 3){count3 = 0;cout << endl;}}}; break;case 4:{int shownumber;char ch;int count3 = 0;for (shownumber = STARTOFASCII; shownumber < ENDOFASCII + 1; shownumber++){ch = shownumber;cout <<" “"<< ch<<"” " << "對應的ASCII碼為: " << shownumber << "\t";count3++;if (count3 == 3){count3 = 0;cout << endl;}}}; break;default: cout << "輸入有誤!" << endl;}cout << endl<<endl;cout << "選擇需要輸出的范圍:(輸入“0”返回上一層)" << endl;cout << "1:輸出數字(1-9)" << endl;cout << "2:輸出大寫字母(A-Z)" << endl;cout << "3:輸出小寫字母(a-z)" << endl;cout << "4:輸出全部" << endl;cin >> n;} }

現在還稍微有一點點缺陷,就是在選擇數字找碼的時候,如果輸入字符,就死循環了,暫時還沒有啥好的解決辦法。

小程序地址:

ASCII碼轉換小程序-其它文檔類資源-CSDN下載

總結

以上是生活随笔為你收集整理的复习了C++前几章,做一个ASCII码转换的小程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。