close
class的基礎小練習
 
 
 
#include <iostream>
 
/* 咖啡店點飲料 */

 

using namespace::std;

 

class Cafeshop
{
    public:
    void menu(string drink)
    {
        makedrink=drink;
    }
 
    string tellservice()
    {
        return makedrink;
    }
 
    void printreceipt()
    {
    cout<<"Welcome to the Niki cafe shop!You drinks:"<<tellservice()<<endl;
    }
 
    private:
    string makedrink;
};
 
int main() 
{
    string youlike;
    Cafeshop myorder;  //建一個Cafeshop名為myorder
 
    cout<<"Which kind drink you want?"<<endl;
 
    getline(cin,youlike);  //輸入字串
    myorder.menu(youlike);
 
    myorder.printreceipt();
 
    system("PAUSE");
    return 0;
}

 

顯示結果:

Which kind drink you want?

apple juice

Welcome to the Niki cafe shop!You drinks:apple juice

arrow
arrow
    文章標籤
    c++
    全站熱搜
    創作者介紹
    創作者 布拉怡 的頭像
    布拉怡

    nini的部落格

    布拉怡 發表在 痞客邦 留言(0) 人氣()