独習C++ 改訂版日記 P.52 練習問題2.2 2.〜2.(こんなコードで良いのか?)

#include 
#include 

using namespace std;

class t_and_d {
  time_t now_time;
public:
  t_and_d(time_t _now_time);
  void disp();
};

t_and_d::t_and_d(time_t _now_time)
{
  now_time = _now_time;
}

void t_and_d::disp()
{
  struct tm *tm = localtime(&now_time);
  char *time_str = asctime(tm);

  printf("%s\n", time_str);
}

int main()
{
  time_t n = time(NULL);
  t_and_d td(n);

  td.disp();

  return 0;
}

3.(こんなコードで良いのか?)

#include 

using namespace std;

class box {
  double height;
  double width;
  double breadth;

public:
  box(double _height,
      double _width,
      double _breadth);
  void vol();
};

box::box(double _height, double _width, double _breadth)
{
  height = _height;
  width = _width;
  breadth = _breadth;
}

void box::vol()
{
  printf("vol:%f\n", height * width * breadth);
}

int main()
{
  box b(10.0, 20.0, 30.0);

  b.vol();

  return 0;
}


関連記事:

Facebook Comments

 Leave a Reply


上の画像の文字を入力して下さい(入力必須)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">