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

📄 course.h

📁 为SSD5课程《数据结构与算法》中的练习
💻 H
字号:
#include <iostream>
#include <cstdlib>

#ifndef COURSE_H
#define COURSE_H

using namespace std;

int const MAX_LINES = 10;

class course {

  public:
    string name;
    string title;
    string description[MAX_LINES];
     
    course() : name(""), title("") {}
    course(string name, string title) : 
        name(name), title(title) {}

    friend ostream& operator<<(ostream&, const course&);        
    friend istream& operator>>(istream&, course&);
};

ostream& operator<<(ostream& out, const course& c) {

    out << c.name << ": " << c.title << "\n";

    int index = 0;
    while (c.description[index] != "") {
        out << c.description[index++] << "\n";    
    }

    return out;
}

istream& operator>>(istream& in, course& c) {

    getline(in, c.name);
    getline(in, c.title);

    string line;
    getline(in, line);
    int number = 0;
    while (line != "") {
        c.description[number++] = line;
        getline(in, line);
    }
    
    return in;
}

#endif

⌨️ 快捷键说明

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