⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lengths.cpp

📁 一本语言类编程书籍
💻 CPP
字号:
// Exercise 16.2 Lengths.cpp
// Length classes implementations

#include "Lengths.h"

// Static data members of BaseLength
double BaseLength::mmPerInch = 25.4;
double BaseLength::inchesPerYard = 36.0;
double BaseLength::mmPerMeter = 1000.0;
double BaseLength::yardsPerPerch = 5.5;

// Virtual base function to return the length
double BaseLength::length() {
  return static_cast<double>(mm);
}

// Virtual function to return the length
double Inches::length() {
  return mm/mmPerInch; 
}

// Virtual function to return the length
double Yards::length() {
  return mm/(inchesPerYard*mmPerInch); 
}

// Virtual function to return the length
double Meters::length() {
  return mm/mmPerMeter; 
}

// Virtual function to return the length
double Perches::length() {
  return mm/(yardsPerPerch*inchesPerYard*mmPerInch); 
}

⌨️ 快捷键说明

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