void CStudent::Inputdata(int i)
{
cout << "\nPlease Input student " << i+1 << " name: ";
cin.get(stu[i].name, 15);
ClearBuffer(); //clear cin buffer
cout << "Please Input student " << i+1 << " grade: ";
cin >> stu[i].grade;
//对非法数字和字符进行限制,当然可以不是0.00或100.00
while (stu[i].grade < 0.00 || stu[i].grade > 100.00)
{
cout << "Invalid data!\n";
cin >> stu[i].grade;
ClearBuffer();
}
cout << "Please Input student " << i+1 << " year: ";
cin >> stu[i].biryear;
//对非法数字和字符进行限制
while (stu[i].biryear < 1900 || stu[i].biryear > 2006)
{
cout << "Invalid data!\n";
cin >> stu[i].biryear;
ClearBuffer();
}
cout << "Please Input student " << i+1 << " month(1-12): ";
cin >> stu[i].birmonth;
//对非法数字和字符进行限制
while (stu[i].birmonth < 1 || stu[i].birmonth > 12)
{
cout << "Invalid data!\n";
cin >> stu[i].birmonth;
ClearBuffer();
}
cout << "Please Input student " << i+1 << " day: ";
cin >> stu[i].birday;
//对非法数字和字符进行限制
switch (stu[i].birmonth)
{
case 2://二月
while (stu[i].birday < 1 || stu[i].birday > 28)
{
cout << "Invalid data!\n";
cin >> stu[i].birday;
ClearBuffer();
}
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: //大月31天
while (stu[i].birday < 1 || stu[i].birday > 31)
{
cout << "Invalid data!\n";
cin >> stu[i].birday;
ClearBuffer();
}
break;
case 4:
case 6:
case 9:
case 11: //小月30天
while (stu[i].birday < 1 || stu[i].birday > 30)
{
cout << "Invalid data!\n";
cin >> stu[i].birday;
ClearBuffer();
}
break;
default:
break;
}
ClearBuffer();
}
谷底深深行 ,峰顶漫漫步......@_@