⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histo.cpp

📁 这是Accelerated C++的配套源码
💻 CPP
字号:
#include <algorithm>
#include <iostream>

#include "Core.h"
#include "Pic.h"
#include "Student_info.h"

using std::cin;
using std::cout;
using std::endl;
using std::sort;
using std::string;
using std::vector;

Picture histogram(const vector<Student_info>& students)
{
	Picture names;
	Picture grades;

	// for each student
	for (vector<Student_info>::const_iterator it = students.begin();
	     it != students.end(); ++it) {

		// create vertically concatenated pictures of the names and grades
		names = vcat(names, vector<string>(1, it->name()));
		grades = vcat(grades,
#ifdef __BORLANDC__
		    vector<string>(1, " " + string(static_cast<size_t>(it->grade() / 5), '=')));
#else
		    vector<string>(1, " " + string(it->grade() / 5, '=')));
#endif
	}

	// horizontally concatenate the name and grade pictures to combine them
	return hcat(names, grades);
}

int main()
{
	vector<Student_info> students;
	Student_info s;

	// read the names and grades
	while (s.read(cin))
		students.push_back(s);

	// put the students in alphabetical order
	sort(students.begin(), students.end(), Student_info::compare);

	// write the names and histograms
	cout << frame(histogram(students)) << endl;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -