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

📄 d_grad.h

📁 这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言描述-应用模板库STL>陈君 译 英文名称是Data Structures with C++ Using STL.
💻 H
字号:
#ifndef GRADUATE_CLASS
#define GRADUATE_CLASS

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class graduate
{
	public:
		// default constructor; objects are initialized with input >>
		graduate()
		{}

		// return the degree obtained by the graduate
		string getDegree() const
		{ return degree; }

		// two objects are equal if they have the same name
		friend bool operator== (const graduate& lhs, const graduate& rhs)
		{
			return lhs.name == rhs.name;
		}

		// two objects are equal if the names are alpabetically ordered
		friend bool operator< (const graduate& lhs, const graduate& rhs)
		{
			return lhs.name < rhs.name;
		}

		// input name and degree from a file. each line contains
		// the name, ssn and degree separated by a tab character
		friend istream& operator>> (istream& istr, graduate& grad)
		{
			getline(istr, grad.name,'\t');		
			getline(istr, grad.degree,'\n');

			return istr;
		}

		// output the name and degree for the graduate
		friend ostream& operator<< (ostream& ostr, const graduate& grad)
		{
			// left justify output
			ostr.setf(ios::left, ios::adjustfield);

			ostr << setw(20) << grad.name << grad.degree;

			// restore right justification
			ostr.setf(ios::right, ios::adjustfield);

			return ostr;
		}

	private:
		string name;
		string degree;
};

#endif	// GRADUATE_CLASS

⌨️ 快捷键说明

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