
作業社區
探索學習新天地,共享知識資源!
MyStudy_HYB 的學生作業:
#include #include #include #include using namespace std; class Student { private: char* name; int age; static Student* instance; Student(const char* name, int age) { this->age = age; char* p = (char*)name; while (*p++); int len = p - name; this->name = (char*)malloc(len * sizeof(char)); strcpy(this->name, name); } public: static Student* static_func(const char* name, int age) { if (Student::instance == NULL) { Student::instance = new Student(name, age); } return Student::instance; } void show(void) const; ~Student(); }; Student* Student::instance = NULL; void Student::show(void) const { { cout





幕布斯3194744 的學生作業:
#include #include using namespace std; class String { public: String(const char* str = NULL) { if(NULL != str){ int len = strlen(str) + 1; this->str = new char[len]; strcpy(this->str,str); this->strLenth = len - 1; }else{ this->str = NULL; this->strLenth = 0; } } ~String(){ if(str){ delete[] str; } } char& operator[](int index){ return str[index]; } int size(){ return strLenth; } private: char *str; //字符串指針 int strLenth; //字符串長度 }; int main(int argc, const char *argv[]) { String str("hello"); str[0] = 'w'; str[1] = 'x'; for(int i = 0;i < str.size();i ++){ cout




