回复 10楼 TonyDeng
不吝赐教。。。。大一c++都是自学的,现在学C也是自己瞎鼓捣的,都怪以前上课老睡觉了。

#############################################
##########################################
因为不懂、才要学习、只有学习、才有进步。
程序代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <conio.h>
struct Birthday
{
int _Month;
int _Day;
int _Year;
Birthday(int year, int month, int day)
{
_Year = year;
_Month = month;
_Day = day;
}
void Show(void)
{
printf_s("%04d-%02d-%02d", _Year, _Month, _Day);
}
};
struct Student
{
char _Name[21];
char _Sex;
Birthday* _Birthday;
double _Score;
Student(const char* name, char sex, Birthday* birthday, double score = 0.0)
{
strcpy_s(this->_Name, name);
this->_Sex = sex;
this->_Birthday = birthday;
this->_Score = score;
}
void Show(void) const
{
printf_s("%-20s %2s ", _Name, (_Sex == 0 ? "女" : "男"));
_Birthday->Show();
printf_s("%6.2f", _Score);
}
};
void Pause(void)
{
printf_s("\nPress any key to continue...");
_getch();
}
int main(void)
{
Student* students[] = {
new Student("Zhang", 1, new Birthday(1983, 2, 3), 82),
new Student("Li", 0, new Birthday(1983, 10, 12)),
new Student("Huang", 1, new Birthday(1984, 1, 21), 78)
};
for (const Student* stu : students)
{
stu->Show();
putchar('\n');
}
Pause();
return EXIT_SUCCESS;
}
[此贴子已经被作者于2015-11-27 21:47编辑过]
