
作业社区
探索学习新天地,共享知识资源!
大禹123 的学生作业:
#include #include /* 当成员函数运算符和非成员函数的运算符同时存在的时候,调用成员函数的 */ using namespace std; class String { public: String(const char *str = NULL); String(const String &obj); ~String(); char& operator[](const int index); int size() { return strlen(str); } private: char *str; }; String::String(const char *str) { cout str, str); } else { this->str = NULL; } } String::String(const String &obj) { cout str, obj.str); } else { this->str = NULL; } } String::~String() { cout





大禹123 的学生作业:
#include #include using namespace std; class Singleton { private: Singleton(); Singleton(const Singleton &obj); public: static Singleton &getInstance(); static int num; void addNum(); }; Singleton::Singleton() { } Singleton::Singleton(const Singleton &obj) {} //此处得返回引用,不然对象又被深拷贝了 Singleton &Singleton::getInstance() { static Singleton instance; return instance; } void Singleton::addNum() { num++; cout





大禹123 的学生作业:
#include #include using namespace std; class Test { public: Test(int size = 0) { cout 0) { this->data = new int[size]; } else { this->data = NULL; } } Test(const Test &obj) { // Test temp = obj; // cout size = obj.size; } else { this->data = NULL; this->size = 0; } } ~Test(void) { cout





大禹123 的学生作业:
#include using namespace std; class Test{ public: Test(int size = 0){ if(size > 0) { this->data = new int[size]; //堆区开辟内存,最后要释放 }else{ this->data = NULL; } this->index = 0; this->len = size; } ~Test(){ if(this->data){ delete this->data; } this->data = NULL; } void insert(int data){ //判满 if(index >= this->len-1) { cout index ++] = data; } } void show(void){ int *ptr = this->data; for(int i = 0;i < this->index; i ++){ cout show(); cout





大禹123 的学生作业:
#include #include using namespace std; class String{ public: String(const char *str = NULL); void show(void);//输出字符串中的每个字符和对应的ASCII码 private: char *str; }; String::String(const char *str) { if(NULL!=str) { this->str = new char[strlen(str)+1]; // strcpy(this->str, str); //都可以 memcpy(this->str, str, strlen(str)+1); }else{ this->str = NULL; } } void String::show(void) { //this->str 是字符串的首地址,这个一定不能动 if(NULL == this->str) return; char *ptr = this->str; while(*(ptr)!='\0') { cout




