每年自动更改年龄

时间:2012-11-18 21:30:53

标签: c++

  

可能重复:
  How to change the age automatically every year

我写了这个程序,但我有一个变量“年龄”。我如何做到这一点,以便我不必每年改变狗的年龄?换句话说它应该自动改变?

#include <iostream>
#include <conio.h>
#include <string>
#include <stdlib.h>

using namespace std;

class Dog//instance class
{
string Fam;
string & Name;
//string  Name;
string Otch;
static string mField;
unsigned int    Nagradi;
unsigned int    Age;
public:

Dog(string fam="", string otch="", string nam="", 
unsigned nagradi=0, unsigned age=0):Fam("")
    ,Name(Fam)
{
    cout << "Dog::Dog(" << nam << ")" << endl;
    Name = nam;
    Otch = otch;
    Fam  = fam;
    Nagradi = nagradi;
    Age = age;
}

Dog(Dog const & st): Name(Fam)//constructor
{
    cout << "Dog::Dog(copy:" << st.Name << ")" << endl;
    Name = st.Fam;
    Otch = st.Name;
    Fam  = st.Otch;
    Nagradi = st.Nagradi;
    Age = st.Age;
}

~Dog()//Destructor
{
    cout << "Dog::~Dog(" << Name << ")" << endl;
     system ("pause");
      }

void Show()
{
    cout<< Name << ' ' << Fam << ' ' << Otch <<
           " #" << Nagradi << " age:" << Age << endl;
}
};

1 个答案:

答案 0 :(得分:5)

存储出生日期而不是年龄,然后根据需要计算年龄。

就像有人说上次你问这个问题一样。请不要两次问同一个问题。