person.cpp

来自「一本语言类编程书籍」· C++ 代码 · 共 41 行

CPP
41
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?