UCLA A7


  • 作业标题:Homework 7 – due March 13th
  • 课程名称:University of California, Los Angeles (Winter 2022)
  • 完成周期:1天

Overview

  1. Suppose that we are writing a Person class and that we want to store each Person’s best friend.
    The Person class is not allowed to have a member variable of type Person because that’d result in the class having \infinite depth”. On the other hand, the Person class is allowed to have a member variable of type Person*. In this question, you’ll make a class called Person. Rather than storing each Person’s best friend, we’ll store an unordered set of all their friends.

  2. HW7.hpp contains the class interface and a function declaration:

    class Person {
    public:
    std::string name;
    Person(const std::string& _name) : name(_name), friends() {}
    void addFriend(const Person& p);
    void delFriend(const Person& p);
    void printFriends() const;
    bool hasFriends() const;
    bool isFriendsWith(const Person& other) const;
    private:
    std::unordered_set<const Person*> friends;
    };

void deleteOneSidedFriendship(Person& p1, Person& p2);

  1. HW7.cpp contains nonsense definitions of the member functions and the non-member function.

  2. main.cpp contains code that uses the class and the function.

  3. The goal is to edit HW7.cpp to contain sensible definitions so that running the code produces something like the following.

。。。


文章作者: IT神助攻
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 IT神助攻 !
  目录