iT邦幫忙

2022 iThome 鐵人賽

DAY 23
0
Software Development

C++超級菜鳥也可以懂的物件導向攻略系列 第 23

Day23 C++虛擬貨幣Crypto Bot menu與功能雜談

  • 分享至 

  • xImage
  •  

請搭直通車
Day11 - C++好簡單之來做一個ATM系統吧! switch和do..while

這個Crypto小程式會依照上面ATM的概念作延伸。

來列舉一下想要添加的功能:

  • Current Price 價錢
  • Crypto Info
  • Market Capital
  • Help
  • Exit
    以上就是我們的目錄了。

因為是簡單介紹就不多做其他功能例如bid price spread等等的運算。
先簡單做出一個目錄:

    cout << "*****MENU*******" <<endl;
    cout << "1.Show Current Price" << endl;
    cout << "2.Find Crypto info" <<  endl;
    cout << "3.Find Market Cap" <<  endl;
    cout << "4.Help" <<  endl;
    cout << "5.Exit" <<  endl;
    cout << "****************" <<  endl;

第一個選項會在另一篇專門說明,因為會用到File handling佔的篇幅比較多。

接下來輸入我們的選擇,用cin >>

    int option;
    cout << "Type the service you'd like to do: " << endl;
    cin >> option;

    

    int option;
    cout << "Type the service you'd like to do: " << endl;
    cin >> option;
    do{
        switch(option){
            case 1:
            {
                cout << "Enter the Crypto (1.BTC, 2.ETH, 3.USDT 4. Exit):"<<endl;
                int cname;
                cin >> cname;
                cout << "You entered: " << cname << endl;
                break;
            }
            case 2:
            {
                cout <<"Enter the name of the crypto you'd like to see info with:" << endl;
                cout << "1.BTC, 2.ETH, 3.USDT 4. Exit" << endl;
                int x;
                cin >> x;
                cout << "you entered: " << x<< endl;
                break;}
            case 3:
            {   cout <<"Enter the crypto you'd like to see Market Cap with:" << endl;
                cout << "1.BTC, 2.ETH, 3.USDT 4. Exit" << endl;
                int y;
                cin >> y;
                cout << "Market cap is: $" << marketcap(y) << endl;
                break;}
            case 4:
                cout <<"Need Help? Don't worry! We're here for you" << endl;
                break;
        }
    }while (option != 5);

Show Current Price

預期功能:輸入編號會顯示出該虛擬幣的資訊,包含現有流通樹木與第一個區塊創建時間(上市時間)。
1.BTC, 2.ETH, 3.USDT 4. Exit

if(c == 1){
        cout << "Total Bitcoin: 19,166,487 BTC" << endl;
         cout << "First Block(Bitcoin creation date): 2009-01-09" << endl;
    }else if(c == 2){
        cout << "Total ETH: 122,690,161 ETH" << endl;
         cout << "First Block(ETH creation date): July 30, 2015
" << endl;
    }else cout << "Total USDT: 68,212,574,446 USDT" << endl;
         cout << "Tether was created as an attempt to solve two major issues with existing cryptocurrencies: high volatility and convertibility between fiat currencies and cryptocurrencies. To address these perceived issues Tether created a cryptocurrency that is fully backed 1:1 by deposits of U.S. dollars held at banks." << endl; 

Market Capital

預期功能:輸入編號會顯示出該虛擬幣的資本市值。
這邊想用輸出數字,long int當輸出值。稍後把它做到function裡面。
1.BTC, 2.ETH, 3.USDT 4. Exit

if(c == 1){
        long int mbtc = 367982010627;
        return mbtc;
    }else if(c == 2){
        long int meth =  163879592332;
        return meth;
    }else if(c == 3){
        long int musdt =  68269066618;
        return musdt;
    }else

        return 0;
}

Help

預期功能:顯示聯絡方式與常見問題。

cout <<"Telephone: 120-332-593. Email: crypto-servie@cryptobot.com Open:Mon-Fri AM9:00~PM4:30"<< endl;

Reference: w3school, geeksforgeeks, CodeBeauty(YouTube)


上一篇
Day 22 C++ 繼承Inheritance 刷題練習、如何顯示現在時間與Crypto雜談
下一篇
Day24 - C++ 虛擬貨幣程式Crypto bot - 顯示虛擬貨幣資料 File I/O, filesystem和資料儲存 Filestoring
系列文
C++超級菜鳥也可以懂的物件導向攻略30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言