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;
}


Comments

comments powered by Disqus