
作业社区
探索学习新天地,共享知识资源!
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





幕布斯3194744 的学生作业:
#include using namespace std; class Stu{ private: static Stu *stu; //静态成员变量 Stu(); //构造函数私有化 public: static Stu *create_obj(void); //静态成员函数 }; Stu *Stu::stu = NULL; //静态成员变量初始化 Stu::Stu(){ } Stu* Stu::create_obj(void) { if(NULL == stu){ stu = new Stu(); } return stu; } int main(int argc, const char *argv[]) { Stu *stu1 = Stu::create_obj(); cout




