急急急急 大家赶快 来帮帮啊 本人不是计算机专业的
如何实现下面要求啊 急求。。。。
5555555
要求: 编写一个Student学生类和Student类的友元类FriendStudent。其中Student类包含4个数据成员,有两个非静态成员name和total_score分别用来表示学生的总人数和总成绩;FriendStudent类包含两个成员函数Disp()和Total()分别用来输出学生的姓名,成绩和总的学生人数及学生的总成绩.
在线等。。。。。 。。
要源程序
[解决办法]
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class student{
public:
friend class friendstudent;
student()
{
total_num=0;
}
private:
vector <string> name;
vector <int> score1;
vector <int> score2;
vector <int> total_score;
int total_num;
};
class friendstudent{
public:
bool add_new(string _name,int _score1,int _score2)
{
temp.name.push_back(_name);
temp.score1.push_back(_score1);
temp.score2.push_back(_score2);
temp.total_score.push_back(_score1+_score2);
temp.total_num++;
return 0;
}
void disp()
{
cout < < "姓名 " < < '\t ' < < "成绩1 " < < '\t ' < < "成绩2 " < <endl;
for(int i=0;i <temp.name.size();i++)
cout < <temp.name[i] < < '\t ' < <temp.score1[i] < < '\t ' < <temp.score2[i] < <endl;
}
void total()
{
cout < < "姓名 " < < '\t ' < < "总成绩 " < <endl;
for(int i=0;i <temp.name.size();i++)
cout < <temp.name[i] < < '\t ' < <temp.total_score[i] < <endl;
cout < < "总人数: " < <temp.total_num < <endl;
}
private:
student temp;
};
//测试用main函数
int main()
{
friendstudent stu;
stu.add_new( "张三 ",90,80);
stu.add_new( "李四 ",70,60);
stu.disp();
stu.total();
system( "pause ");
return 0;
}
LZ问题描述得不明确,name怎么可能指向学生的总人数?成绩的类型个数也没指明
上面实现了两种程序的统计计数,学生总成绩视为两项分数之和
WinXP+sp2 Dev-C++ 4.9.9.2中调试通过