#include<iostream>
#include<string>
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 <<C1.getCourseName()<<endl;
for(int i=0;i<C1.getNumberOfStudents();i++)
cout <<C1.getStudents()[i]<<endl;
C1.dropStudent(str);
cout <<C1.getNumberOfStudents()<<endl;
return 0;
}
版权声明:本文为u012495573原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。