datalog.cpp

来自「Thinking in C++ 2nd edition source code 」· C++ 代码 · 共 63 行

CPP
63
字号
//: C19:Datalog.cpp {O}
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Datapoint member functions
#include "DataLogger.h"
#include <iomanip>
#include <cstring>
using namespace std;

tm DataPoint::Time() { return Tm; }

void DataPoint::Time(tm t) { Tm = t; }

const char* DataPoint::latitude() {
  return Latitude;
}

void DataPoint::latitude(const char* l) {
  Latitude[bsz - 1] = 0;
  strncpy(Latitude, l, bsz - 1);
}

const char* DataPoint::longitude() {
  return Longitude;
}

void DataPoint::longitude(const char* l) {
  Longitude[bsz - 1] = 0;
  strncpy(Longitude, l, bsz - 1);
}

double DataPoint::depth() { return Depth; }

void DataPoint::depth(double d) { Depth = d; }

double DataPoint::temperature() {
  return Temperature;
}

void DataPoint::temperature(double t) {
  Temperature = t;
}

void DataPoint::print(ostream& os) {
  os.setf(ios::fixed, ios::floatfield);
  os.precision(4);
  os.fill('0'); // Pad on left with '0'
  os << setw(2) << Time().tm_mon << '\\'
     << setw(2) << Time().tm_mday << '\\'
     << setw(2) << Time().tm_year << ' '
     << setw(2) << Time().tm_hour << ':'
     << setw(2) << Time().tm_min << ':'
     << setw(2) << Time().tm_sec;
  os.fill(' '); // Pad on left with ' '
  os << " Lat:" << setw(9) << latitude()
     << ", Long:" << setw(9) << longitude()
     << ", depth:" << setw(9) << depth()
     << ", temp:" << setw(9) << temperature()
     << endl;
} ///:~

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?