小编use*_*099的帖子

C++类的问题

我是一所独立寄宿学校的老师,我正在尝试用C++编写一个程序,该程序会随机将学生安排在餐厅的餐桌旁,这样他们每周都会与不同的学生和不同的工作人员坐在一起.理想情况下,在一定时期内,他们不会两次坐在同一张桌子上,并且尽可能多的不同学生.我用Python创建了这个程序,它运行得很好(非常好).出于各种原因,我试图将其移植到C++(我根本不熟悉),所以我可以把它交给寄宿人员.学生和教职员工(以及表格容量)都是从文本文件中读取的.我创建了两个自定义类,一个用于学生,一个用于表,用于处理数据.以下是两个类头文件:

Table.h

#pragma once
#include <iostream>
#include "Student.h"
#include <vector>

using namespace std;

class Table
{
    // Private class variables
    string staff;
    int numSeats;
    vector<Student> seating;
public:
    Table(); // Default constructor
    Table(string s, int n);
    Table(const Table& that) : staff(that.staff), numSeats(that.numSeats)
    {
    }
    // Copy Constructor
    Table& operator=(const Table& that)
    {
        staff = that.staff;
        numSeats = that.numSeats;
        return *this;
    }
    int getNumSeats();
    string getStaffName();
    void addStudent(Student student);
    void removeStudent(Student student);
    void clearStudents();
    vector<Student> getTableSeating();
    int getRemainingSeats();
    ~Table(void);
};
Run Code Online (Sandbox Code Playgroud)

这是学生班级文件:

#pragma …
Run Code Online (Sandbox Code Playgroud)

c++ vector

3
推荐指数
1
解决办法
199
查看次数

标签 统计

c++ ×1

vector ×1