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

📄 person.cpp

📁 一本语言类编程书籍
💻 CPP
字号:
// Program 11.5 Working with a person.     File: person.cpp
#include <iostream>
#include "person.h"
  // Display the name
  void Name::show() {
    std::cout << firstname << " " << surname << std::endl;
  }

  // Display the date
  void Date::show() {
    std::cout << month << "/" << day << "/" << year << std::endl;
  }

  // Display a phone number
  void Phone::show() {
    std::cout << areacode << " " << number << std::endl;
  }

  // Display a person
  void Person::show() {
    std::cout << std::endl;
    name.show();
    std::cout << "Born: ";
    birthdate.show();
    std::cout << "Telephone: ";
    number.show(); 
  }

  // Calculate the age up to a given date
  int Person::age(Date& date) {
    if(date.year <= birthdate.year)
      return 0;

    int years = date.year - birthdate.year;
    if((date.month>birthdate.month) || 
                  (date.month == birthdate.month && date.day>= birthdate.day))
    return years;
      else
    return --years;
  }

⌨️ 快捷键说明

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