2 luoqiwell luoqiwell 于 2014.06.10 21:57 提问

C++编程问题(学生查找系统)class student class CClass

void Print(CStudent& student)
{
cout << "ID: " << student.GetID() << " ";
cout << "NAME: " << student.GetName() << " ";
cout << "GENDER: " << student.GetGender() << " ";
cout << "AGE: " << student.GetAge() << " ";
cout << "CLASS: " << student.GetClass().GetName() << endl;
}

int main (int argc, char * argv[])
{
CClass c("200404100701", "信息管理2004-1");

CStudent s1("20040410070101", "李杨", 0, 18);
CStudent s2("20040410070102", "文涛", 1, 17);
CStudent s3("20040410070103", "罗菲", 0, 19, c);
CStudent s4("20040410070104", "陈诚", 1, 17, c);

c.AddStudent(s1);
c.AddStudent(s2);

// 打印班级中所有学生的信息。
for(int i = 0; i < c.GetStudentCount(); i++)
{
    Print(c.GetStudent(i));
}

// 输入一个学号。
string id;
cout << "Please input some student's id: ";
cin >> id;

// 调用 FindStudent 函数,查找指定学号的学生。
CStudent* ps = c.FindStudent(id);

// 如果找到学生,输出学生信息,否则提示找不到学生。
if(ps != 0){
    Print(*ps);
}
else{
    cout << "No Student!" <<endl;
}

return 0;

}
输出结果:

请有兴趣的朋友帮我解答一下,感谢万分,可能你的几句言语将影响我的一生。

1个回答

JerryLeeFighting
JerryLeeFighting   2014.06.10 22:05

输出结果你已经自己加了注释,但是好像代码有点问题。

Csdn user default icon
上传中...
上传图片
插入图片