C++ STL 第九次实验
来源:互联网 发布:js更新json值 编辑:程序博客网 时间:2024/06/15 12:36
【题目】
处理score.txt中的学生成绩信息
并且指出及格率,
得分87~100之间的学生比例
【要求】
使用multiset存储对象数据
使用2分查找函数处理检索要求:
如:lower_bound, up_bound和equal_range
【代码】
#include <iostream>#include <set>#include <fstream>#include <sstream>using namespace std;class Score{public: int s_no; int s_score;};int main(){ ifstream in; in.open("score.txt"); char buf[100]; int no; int score; multiset<int> ms; int i = 0; //学生总人数 int j = 0; //及格人数 float k = 0; //及格率 int l = 0; //87~100人数 float m = 0; //优秀率 while(in.getline(buf,100)){ istringstream data(buf); data >> no; data >> score; ms.insert(score); } for(multiset<int>::iterator it = ms.begin();it!=ms.end();it++) { i++; } cout << "总共有" << i << "个学生" << endl; multiset<int>::iterator ite = ms.lower_bound(60); while(ite!=ms.end()) { j++; ite++; } k = (float)j/i; cout << "总共有" << j << "个学生及格" << endl; cout << "及格率为:" << k << endl; multiset<int>::iterator iter = ms.lower_bound(87); while(iter!=ms.end()) { l++; iter++; } m = (float)l/i; cout << "87~100之间的人数为" << l << endl; cout << "优秀率为" << m; return 0;}
【结果】
阅读全文
2 0
- C++ STL 第九次实验
- C++STL 第八次实验
- C程序设计课程第九次实验任务
- 第九次C程序设计实验报告
- 第九次c语言上机实验报告
- 第九次实验任务
- 第九次实验任务
- 第九次上机实验
- 第九次实验任务
- 第九次实验任务
- 第九次实验任务
- 第九次上机实验
- 第九次上机实验
- 第九次上机实验
- 第九次上机实验
- 第九次实验
- 第九次实验
- 第九次上机实验
- openvswitch vlan port 模式解析
- linux命令返回值-错误码对照表
- matlab的fopen
- CFileDialog使用总结
- 创投日报:12月4日收录投融资项目12起
- C++ STL 第九次实验
- 苹果补缴130亿欧元税款;博通正式启动敌意收购;乐视大厦债权复杂难寻买家丨价值早报
- 基於Rx.js與generator的排序算法可視化
- 数据库索引原理及优化
- Caffe 安装 指定protoc版本
- Google QUIC
- jssdk获取微信用户网络状态,公众号用户网络状态demo实例
- springboot报错:Request method 'GET' not supported
- C++面试出现频率最高的30道题目