帮看看这个简单的程序为什么结果有乱码,如何修改
程序代码为:#include<iostream>
using namespace std;
class Date {
public:
Date() {
strcpy(year, "1900");
strcpy(mon, "01");
strcpy(year, "01");
} Date(char *y, char *m, char *d) {
strcpy(year, y);
strcpy(mon, m);
strcpy(date, d);
}
void print();
private:
char year[5];
char mon[3];
char date[3];
};
void Date::print()
{
cout << year << "-" << mon << "-" << date << " ";
}
class Time {
public:
Time() {
strcpy(houor, "00");
strcpy(mini, "00");
strcpy(second, "00");
} Time(char *h, char *m, char *s) {
strcpy(houor, h);
strcpy(mini, m);
strcpy(second, s);
}
void print() {
cout << houor << "-" << mini << "-" << second << " ";
}
private:
char houor[3];
char mini[3];
char second[3];
};
class DateTime:public Date, public Time {
public:
DateTime():a(2), Date(), Time() {
} DateTime(char *yyyy, char *mm, char *dd, char *HH, char *MM, char *SS,
int k):a(k), Date(yyyy, mm, dd), Time(HH, MM, SS) {
}
void print() {
Date::print();
Time::print();
cout << endl;
cout << a << endl;
}
private:
int a;
};
int main()
{
DateTime b;
b.print();
DateTime a("2011", "07", "05", "20", "05", "03", 3);
a.print();
}
执行结果为:
01-01-樚?0 00-00-00
2
2011-07-05 20-05-03
3