zoukankan      html  css  js  c++  java
  • 第一个C++例子

     1 #include <iostream>
     2 using namespace std;
     3 
     4 class Time
     5 {
     6 private:
     7     int hour;
     8     int minute;
     9     int second;
    10 public:
    11     //Time() //无参够创函数
    12     //{
    13     //    hour = 0; minute = 0; second = 0;
    14     //}
    15     //Time(int h, int m, int s) //带参构造函数
    16     //{
    17     //    hour = h; minute = m; second = s;
    18     //}
    19     Time(int h = 0, int m = 0, int s = 0) : hour(h), minute(m), second(s){} //带参数初始化表的构造函数
    20     void Set(int h, int m, int s);
    21     void Show();
    22 };
    23 
    24 void Time::Set(int h, int m, int s)
    25 {
    26     hour = h; minute = m; second = s;
    27 }
    28 void Time::Show()
    29 {
    30     cout << hour << ":" << minute << ":" << second << endl;
    31 }
    32 
    33 int main()
    34 {
    35     Time t1;
    36     t1.Show();
    37     t1.Set(6, 18, 16);
    38     t1.Show();
    39 
    40     Time t2(12, 11, 10);
    41     t2.Show();
    42 
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    8.18学习日志
    8.17学习日志
    8.15学习日志
    8.14学习日志
    8.13学习日志
    8.12学习日志
    8.11学习日志
    kindle
    xcode 4 安装cocos2d-x 2.1.4
    GUI之CCControlExtension
  • 原文地址:https://www.cnblogs.com/mrethan/p/4155573.html
Copyright © 2011-2022 走看看