定义一个Course类,并编写几个成员函数

#include
#include
using namespace std;

class Course
{	
private:	
	string courseName;
	string *students;
	int numberOfStudent;
	int capacity;
public:	
	Course(string name,int capacity,int num=0)	
	{	
		courseName=name;	
		this->capacity=capacity;
		numberOfStudent=num;
		students=new string[capacity];
	}
	~Course()	
	{
		delete []students;	
	}
	string getCourseName()const	
	{	
		return courseName;	
	}
	void addStudent(const string& name)	
	{
		students[numberOfStudent++]=name;	
	}
	
	void dropStudent( string name)	
	{	
		name=students[--numberOfStudent];	
	}
	
	string *getStudents()	
	{	
		return students;	
	}
	
	int getNumberOfStudents()	
	{	
		return numberOfStudent;	
	}
};

int main()
{	
	Course C1("math",100);
	string str;
	C1.addStudent("zhangsan");
	C1.addStudent("lisi");
	C1.addStudent("wangwu");
	cout <


你可能感兴趣的:(c++)