可能重複:
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編輯您的上一篇文章,將代碼放入,而不是詢問新問題。在網上搜索「C++獲取日期」。 –