Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

c++問題~高手請救命~急

定義一個MyTime類別, 相關說明如下:

• 資料成員(定義為private)

– Hour:時, 資料型態為整數

– Minute:分, 資料型態為整數

– Second:秒, 資料型態為整數

• 成員函式(定義為public)

– 建構子: 設定Hour, Minute, 與Second的值分別為0, 不用給預設值

– void SetTime(int h, int m, int s) : 設定Hour, Minute, 與Second的值

– void Print(void) const : 列印Hour, Minute, 與Second的值

• 主程式

– 宣稱一個MyTime1物件t1

– 列印t1的內容(呼叫t1的Print成員函式)

– 要求使用者輸入及設定t1的時、分、秒(呼叫t1的SetTime成員函式)

– 列印t1的內容(呼叫t1的Print成員函式)

1 Answer

Rating
  • MrAYD
    Lv 5
    1 decade ago
    Favorite Answer

    #include "stdafx.h"

    #include <iostream>

    using namespace std;

    class MyTime

    {

    private:

    int Hour;

    int Minute;

    int Second;

    public:

    MyTime(){

    this->Hour=0;

    this->Minute=0;

    this->Second=0;

    }

    void SetTime(int h,int m,int s){

    this->Hour=h;

    this->Minute=m;

    this->Second=s;

    }

    void Print(void) const{

    cout<<this->Hour<<':'<<this->Minute<<':'<<this->Second<<endl;

    }

    };

    int _tmain(int argc, _TCHAR* argv[])

    {

    MyTime t1;

    t1.Print();

    t1.SetTime(02,30,10);

    t1.Print();

    cin.ignore();

    return 0;

    }

    Source(s): Me
Still have questions? Get your answers by asking now.