是将三个数字(int x, int y, double z)和一个字符串(string)当成一个structure,然后将structure存进vector中。
structure定义如下:
struct exam_struct
{
std:: string name;
int X;
int Y;
double Z;
};
vector也给出:
vector
老师给出head file所以只需要写出function即可。
第一个是比较成绩X*Y+Z的大小
bool exam_cmp(const exam_struct &a, const exam_struct &b)
比较完之后用降序排列出strucrture,需要使用vector
第二个是如果一个structure中的name=john,Z<=10,输出ture,同样需要使用vector中的元素
bool exam_pred(const exam_struct &a)
第三个是将文件的内容存入vector,我写了如下:
vector
{
vector
ifstream myfile;
myfile.open(filename.c_str());
while(myfile)
{
int i;
i = 0;
myfile >> read_exam[i].X >>read_exam[i].Y >> read_exam[i].Z;
myfile >> read_exam[i].name;
myfile >> ws;
i++;
read_exam.push_back();
}
return read_exam;
}
因为不确定文件有几个这样的东西,所以需要while loop。但不知我做的是否正确。对于第一和第二个方程我不太会写,希望大家能帮忙!
只需要按要求写出即可,不需要运行!